qwert Posted February 16, 2016 Share Posted February 16, 2016 I have an unusual situation where a rich text field always contains 4 lines of text. I do not want the field to accept/process an Enter key, which would create a fifth line. $ES_WANTRETURN is the default style when the control is created. How can I remove it? And will that give me the behavior I want? Or is there a better way? I tried creating the control with only $ES_MULTILINE, but the Enter key was still accepted. Thanks in advance for any assistance. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 16, 2016 Moderators Share Posted February 16, 2016 qwert, I have been playing around and cannot find an easy solution - it seems that using $ES_MULTILINE forces $ES_WANTRETURN regardless of how you subsequently reset the styles (see the Setting Styles tutorial in the Wiki to see how you can do this). The only thing I can think of is having 4 single line controls - but that raises problem with all the required RTF formatting. Do you have an example file that I can use to experiment? M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
qwert Posted February 17, 2016 Author Share Posted February 17, 2016 Thanks for offering to take a look. Here is a minimum example of the situation: #include <GuiRichEdit.au3> #include <WindowsConstants.au3> #include <StaticConstants.au3> #include <GUIConstantsEx.au3> $Rich = "{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fnil\fcharset0 Arial;}}{\*\generator Msftedit 5.41.21.2510;}\viewkind4\uc1\pard\sl240\slmult1\lang9\fs28 These four lines\par of rich text\par were prepared\par using WordPad.\par}" $hGui = GUICreate("Rich Test", 300, 200, -1, -1, $WS_POPUP, BitOR($WS_EX_TOPMOST, $WS_EX_COMPOSITED)) $hRichEdit = _GUICtrlRichEdit_Create($hGui, "", 20, 20, 250, 160, $ES_MULTILINE, $WS_EX_TRANSPARENT) ; BitOR($ES_MULTILINE, $ES_AUTOVSCROLL) ; _GUICtrlRichEdit_SetFont($hRichEdit, 14, "Arial") GUISetState() _GUICtrlRichEdit_StreamFromVar($hRichEdit, $Rich) While True Switch GUIGetMsg() Case $GUI_EVENT_CLOSE _GUICtrlRichEdit_Destroy($hRichEdit) Exit EndSwitch WEnd Aside from the $ES_WANT RETURN issue, where is this default font size of 10 getting defined? How can I force 14pt for anything that might be entered? And how can I make the cursor go to the start of the text, not the end? Link to comment Share on other sites More sharing options...
InunoTaishou Posted February 17, 2016 Share Posted February 17, 2016 (edited) This kind of does what you want. You could also stream the richedit to a var, trim the new line and then set the richedit with the new info. expandcollapse popup#include <GuiRichEdit.au3> #include <WindowsConstants.au3> #include <StaticConstants.au3> #include <GUIConstantsEx.au3> #include <SendMessage.au3> Global $___pOld_WndProc = 0 Global $___hNew_WndProc = DllCallbackRegister("_New_WndProc", "int", "hwnd;uint;wparam;lparam") Global $___pNew_WndProc = DllCallbackGetPtr($___hNew_WndProc) $Rich = "{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fnil\fcharset0 Arial;}}{\*\generator Msftedit 5.41.21.2510;}\viewkind4\uc1\pard\sl240\slmult1\lang9\fs28 These four lines\par of rich text\par were prepared\par using WordPad.\par}" $hGui = GUICreate("Rich Test", 300, 200, -1, -1, $WS_POPUP, BitOR($WS_EX_TOPMOST, $WS_EX_COMPOSITED)) $hRichEdit = _GUICtrlRichEdit_Create($hGui, "", 20, 20, 250, 160, $ES_MULTILINE, $WS_EX_TRANSPARENT) ; BitOR($ES_MULTILINE, $ES_AUTOVSCROLL) ; _GUICtrlRichEdit_SetFont($hRichEdit, 14, "Arial") GUISetState() GUICtrlSetState($hRichEdit, $GUI_DISABLE) $___pOld_WndProc = _WinAPI_SetWindowLong($hRichEdit, -4, $___pNew_WndProc) If @error Then MsgBox("", "", "Failed to set info for richedit control") _GUICtrlRichEdit_StreamFromVar($hRichEdit, $Rich) _GUICtrlRichEdit_SetFont($hRichEdit, 14) While True Switch GUIGetMsg() Case $GUI_EVENT_CLOSE _GUICtrlRichEdit_Destroy($hRichEdit) DllCallbackFree($___hNew_WndProc) Exit EndSwitch WEnd Func _New_WndProc($hWndFrom, $iMsg, $wParam, $lParam) If ($hWndFrom <> $hRichEdit) Then Return _WinAPI_CallWindowProc($___pOld_WndProc, $hWndFrom, $iMsg, $wParam, $lParam) Switch $iMsg Case 0x0100 Switch $wParam Case 0x0D Send("{Backspace}") EndSwitch EndSwitch Return _WinAPI_CallWindowProc($___pOld_WndProc, $hWndFrom, $iMsg, $wParam, $lParam) EndFunc ;==>_New_WndProc As for the text formatting, you'll need update the font/size of the richedit yourself with _GUICtrlRichEdit_SetFont Found this topic, it might help. If you didn't want to completely block input to the window you could go through the .au3 file and figure out how to just block the enter key. Edited February 17, 2016 by InunoTaishou Link to comment Share on other sites More sharing options...
qwert Posted February 17, 2016 Author Share Posted February 17, 2016 Yes, it does neutralize the Enter key 0x0D ... and I can almost follow how it does it. Can you tell me what this statement is doing: $___pOld_WndProc = _WinAPI_SetWindowLong($hRichEdit, -4, $___pNew_WndProc) And can you think of any downside(s) of this "intercept" approach? On a first-look test, it looks pretty good. Thanks for your help. Link to comment Share on other sites More sharing options...
InunoTaishou Posted February 17, 2016 Share Posted February 17, 2016 (edited) The statement is setting the WndProc for the richedit handle. Create a new callback (Global $___hNew_WndProc = DllCallbackRegister("_New_WndProc", "int", "hwnd;uint;wparam;lparam")) Get a pointer to the callback (Since Windows uses pointers) (Global $___pNew_WndProc = DllCallbackGetPtr($___hNew_WndProc)) Set the window procedure for the richedit, storing the old pointer in $__pOld_WndProc ($___pOld_WndProc = _WinAPI_SetWindowLong($hRichEdit, -4, $___pNew_WndProc)) Check out these topics to learn more https://msdn.microsoft.com/en-us/library/system.windows.forms.control.wndproc%28v=vs.110%29.aspx https://msdn.microsoft.com/en-us/library/windows/desktop/ms633573%28v=vs.85%29.aspx As for downsides, it's not blocking the enter key, it's just recognizing that the enter key was pressed while the richedit is active, then sending backspace. There's probably a better way, I think the old hook.dll that used to be on the autoit forums could have done it without letting the enter command go to the rich edit, but this was a cleaner way than setting Enter to a hotkey whenever the $hGUI is active, and resetting the hotkey when the $hGUI is not active. Edited February 17, 2016 by InunoTaishou Link to comment Share on other sites More sharing options...
qwert Posted February 17, 2016 Author Share Posted February 17, 2016 OK, I think I follow that. It preserves the normal processing of the rich edit control, but inserts a function to detect an Enter key ... and when one occurs, inserts a backspace code to effectively take it away. Although it's not relevant to my use, it looks like the same method could be used to insert strings of text in response to defined key codes. Unless there's substantial processing overhead to this method, it looks like it will suit my needs. Thanks for taking the time to explain. 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