dsm-sas Posted June 14, 2023 Share Posted June 14, 2023 Is there any way to show a pressed ENTER in GUICtrlRichEdit_Create(...) ? Because the people are writing and writing, the GUI makes automatic next line. But if you WANT a CR by pressing ENTER it has to be seen. Thx's for helping Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted June 14, 2023 Moderators Share Posted June 14, 2023 Moved to the appropriate AutoIt General Help and Support forum, as the Developer General Discussion forum very clearly states: Quote General development and scripting discussions. Do not create AutoIt-related topics here, use the AutoIt General Help and Support or AutoIt Technical Discussion forums. Moderation Team "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
20Ice18 Posted June 15, 2023 Share Posted June 15, 2023 (edited) By default, when you press Enter in a GUICtrlRichEdit control, it creates a new line but does not visually show the carriage return (CR) symbol. To display the pressed Enter as a visible carriage return in a GUICtrlRichEdit control, you can modify the control's style using the GUICtrlSetStyle function. By adding the ES_WANTRETURN style, you can achieve the desired behavior.https://www.autoitscript.com/autoit3/docs/libfunctions/_GUICtrlRichEdit_Create.htm You can try: #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GuiRichEdit.au3> Global $hRichEdit $hGUI = GUICreate("Rich Edit Control Example", 400, 300) $hRichEdit = _GUICtrlRichEdit_Create($hGUI, "Initial text", 10, 10, 380, 280, BitOR($ES_MULTILINE, $ES_AUTOVSCROLL)) _GUICtrlRichEdit_SetFont($hRichEdit, 10, "Courier New") ; Add the ES_WANTRETURN style to the rich edit control GUICtrlSetStyle($hRichEdit, BitOR(GUICtrlGetStyle($hRichEdit), $ES_WANTRETURN)) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd GUIDelete() please let me know if it worked Edited June 15, 2023 by 20Ice18 ❤️ Link to comment Share on other sites More sharing options...
dsm-sas Posted June 15, 2023 Author Share Posted June 15, 2023 $ES_WANTRETURN - Specifies that a carriage return be inserted when the user presses the ENTER key. (Default) This is just a default and will NOT SHOW it in the control... 20Ice18 1 Link to comment Share on other sites More sharing options...
20Ice18 Posted June 15, 2023 Share Posted June 15, 2023 You're right. In that case I think there is no built-in option to visually display the CR character when the Enter key is pressed. If you specifically need to visually show the CR character, you may need to create a custom control or modify an existing control to meet your requirements. This would involve custom drawing and handling the keypress events to manually insert and display the CR character in the control. Alternatively, you could consider using a different control or library that provides more customization options for text editing and display, such as a WebView control or a third-party library for rich text editing. ❤️ Link to comment Share on other sites More sharing options...
Andreik Posted June 15, 2023 Share Posted June 15, 2023 (edited) On 6/14/2023 at 11:05 AM, dsm-sas said: Is there any way to show a pressed ENTER in GUICtrlRichEdit_Create(...) ? Because the people are writing and writing, the GUI makes automatic next line. But if you WANT a CR by pressing ENTER it has to be seen. Thx's for helping Just seen or seen and processed? Something like this? #include <WinAPIConstants.au3> #include <WinAPISys.au3> #include <WindowsConstants.au3> #include <GuiRichEdit.au3> Global $hMain, $hRichEdit Global $hKeyboardProcedure = DllCallbackRegister('__keyboard', 'long', 'int;wparam;lparam') Global $hHook = _WinAPI_SetWindowsHookEx($WH_KEYBOARD_LL, DllCallbackGetPtr($hKeyboardProcedure), _WinAPI_GetModuleHandle(Null)) $hMain = GUICreate('Test', 800, 600) $hRichEdit = _GUICtrlRichEdit_Create($hMain, '', 10, 10, 780, 580) GUISetState(@SW_SHOW, $hMain) Do Sleep(10) Until GUIGetMsg() = -3 _GUICtrlRichEdit_Destroy($hRichEdit) _WinAPI_UnhookWindowsHookEx($hHook) DllCallbackFree($hKeyboardProcedure) Func __keyboard($nCode, $wParam, $lParam) If _WinAPI_GetFocus() = $hRichEdit Then Local $tKBDLLHOOKSTRUCT = DllStructCreate('dword vkCode;dword scanCode;dword flags;dword time;ulong_ptr dwExtraInfo', $lParam) If $nCode < 0 Then Return _WinAPI_CallNextHookEx($hHook, $nCode, $wParam, $lParam) If $wParam = $WM_KEYDOWN Then Local $sKey = DllStructGetData($tKBDLLHOOKSTRUCT, "vkCode") If $sKey = Asc(@CR) Then _GUICtrlRichEdit_AppendText($hRichEdit, ChrW(0xB6)) EndIf EndIf Return _WinAPI_CallNextHookEx($hHook, $nCode, $wParam, $lParam) EndFunc Edited June 15, 2023 by Andreik Code update When the words fail... music speaks. Link to comment Share on other sites More sharing options...
TheDcoder Posted June 15, 2023 Share Posted June 15, 2023 2 hours ago, dsm-sas said: This is just a default and will NOT SHOW it in the control... Did you try defining your own style without including this one? Perhaps that will do the trick. EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time) DcodingTheWeb Forum - Follow for updates and Join for discussion Link to comment Share on other sites More sharing options...
mikell Posted June 15, 2023 Share Posted June 15, 2023 (edited) An other way, without a hook expandcollapse popup#include <GUIConstantsEx.au3> #include <GuiRichEdit.au3> #include <WindowsConstants.au3> $hGui = GUICreate("Example", 320, 350, -1, -1) $hRichEdit = _GUICtrlRichEdit_Create($hGui, "This is a test.", 10, 10, 300, 220) GUISetState() _GUICtrlRichEdit_SetEventMask($hRichEdit, $ENM_KEYEVENTS) GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") While 1 $iMsg = GUIGetMsg() Select Case $iMsg = $GUI_EVENT_CLOSE _GUICtrlRichEdit_Destroy($hRichEdit) ; needed unless script crashes Exit EndSelect WEnd Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) #forceref $iMsg, $wParam Local $hWndFrom, $iCode, $tNMHDR, $tMsgFilter, $hMenu $tNMHDR = DllStructCreate($tagNMHDR, $lParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hRichEdit Select Case $iCode = $EN_MSGFILTER $tMsgFilter = DllStructCreate($tagMSGFILTER, $lParam) Switch DllStructGetData($tMsgFilter, "msg") Case $WM_KEYDOWN $key = DllStructGetData($tMsgFilter, "wparam") If $key = 13 Then _GUICtrlRichEdit_AppendText($hRichEdit, "<CR>") ; @CR EndSwitch EndSelect EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY Edit To display the <CR> without processing the newline just add "Return 1" If $key = 13 Then _GUICtrlRichEdit_AppendText($hRichEdit, "<CR>") ; @CR Return 1 EndIf Edited June 15, 2023 by mikell Andreik 1 Link to comment Share on other sites More sharing options...
dsm-sas Posted June 16, 2023 Author Share Posted June 16, 2023 Great doing. The problem now: I have "<CR>" as text. And this will be in the RTF-File. So. I have to replace it before writing. But: GREAT . Thx's 20Ice18 1 Link to comment Share on other sites More sharing options...
mikell Posted June 16, 2023 Share Posted June 16, 2023 1 hour ago, dsm-sas said: The problem now: I have "<CR>" as text. And this will be in the RTF-File. So. I have to replace it before writing. ? expandcollapse popup#include <GUIConstantsEx.au3> #include <GuiRichEdit.au3> #include <WindowsConstants.au3> $hGui = GUICreate("Example", 320, 350, -1, -1) $hRichEdit = _GUICtrlRichEdit_Create($hGui, "This is a test.", 10, 10, 300, 220) GUISetState() _GUICtrlRichEdit_SetEventMask($hRichEdit, $ENM_KEYEVENTS) GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") While 1 $iMsg = GUIGetMsg() Select Case $iMsg = $GUI_EVENT_CLOSE $txt = StringReplace(_GUICtrlRichEdit_StreamToVar($hRichEdit), "<CR>", "\line ") _GUICtrlRichEdit_StreamFromVar($hRichEdit, $txt) _GUICtrlRichEdit_StreamToFile($hRichEdit, @DesktopDir & "\test.rtf") _GUICtrlRichEdit_Destroy($hRichEdit ; needed unless script crashes Exit EndSelect WEnd Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) #forceref $iMsg, $wParam Local $hWndFrom, $iCode, $tNMHDR, $tMsgFilter, $hMenu $tNMHDR = DllStructCreate($tagNMHDR, $lParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hRichEdit Select Case $iCode = $EN_MSGFILTER $tMsgFilter = DllStructCreate($tagMSGFILTER, $lParam) Switch DllStructGetData($tMsgFilter, "msg") Case $WM_KEYDOWN $key = DllStructGetData($tMsgFilter, "wparam") If $key = 13 Then _GUICtrlRichEdit_AppendText($hRichEdit, "<CR>") ; @CR Return 1 ; don't process newline in richedit EndIf EndSwitch EndSelect EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY dsm-sas and pixelsearch 1 1 Link to comment Share on other sites More sharing options...
dsm-sas Posted June 16, 2023 Author Share Posted June 16, 2023 (edited) Just remove the "<CR>" in $txt, because "_GUICtrlRichEdit_Streamtovar" (or File) add automatically "\par" if @CR is in $txt. Edited June 16, 2023 by dsm-sas Link to comment Share on other sites More sharing options...
mikell Posted June 16, 2023 Share Posted June 16, 2023 3 hours ago, dsm-sas said: "_GUICtrlRichEdit_Streamtovar" (or File) add automatically "\par" if @CR is in $txt. Right. This is the case if <CR> is added and the newline processed anyway In my previous code I used "Return 1" (meaning add <CR> without processing the newline) . In this case "\par" is not present in the stream so to change the <CR> seen in the Richedit to a real newline visible in the rtf file it is necessary to add "\line" in the stream - BTW "\par" could be used instead of "\line" in the replacement dsm-sas 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now