mike1950r Posted June 27, 2023 Share Posted June 27, 2023 (edited) Hi, i have made my rich text editor resizable but if the text gets over the window size the scrollbars do not automaticly appear. If the window is not resized the scrollbars work normal. What do I have to do? Thanks for advice. cheers mike ; GUI $iWidth = $iGlo_Avail_Screen_Width - 6 $iHeight = $iGlo_Avail_Screen_Height - 25 $iLeft = 0 $iTop = 0 $hStyle = BitOR($WS_CAPTION, $WS_SYSMENU, $WS_SIZEBOX, $WS_MINIMIZEBOX, $WS_MAXIMIZEBOX) $hExStyle = $WS_EX_DLGMODALFRAME $hGlo_WE_GUI = GUICreate($sTitle, $iWidth , $iHeight, $iLeft, $iTop, $hStyle, $hExStyle, $hWnd) ; Richedit Control $hStyle = BitOR($ES_MULTILINE, $ES_WANTRETURN, $ES_NOHIDESEL, $WS_VSCROLL, $WS_HSCROLL) $hExStyle = $WS_EX_CLIENTEDGE $hGlo_WE_Control = _GUICtrlRichEdit_Create($hGlo_WE_GUI, "", 0, 0, $iWidth, $iHeight - $iGlo_Menu_Height, $hStyle, $hExStyle) Edited June 27, 2023 by mike1950r Link to comment Share on other sites More sharing options...
Solution pixelsearch Posted June 27, 2023 Solution Share Posted June 27, 2023 Mike, you should resize the RichEdit control when the GUI is resized, then you shouldn't have issues with the RichEdit scrollbars. Below are a couple of functions (from a personal long script) where you can pick what you want (e.g the resize part) to solve your richedit scrollbar issue :expandcollapse popup ;================================================================= Func _GuiPrev() If $g_hGuiPrev = 0 Then ; only once during whole script $g_hGuiPrev = GUICreate("Preview in RichEdit control (read-only)", $g_iGui_W, $g_iGui_H, -1, -1, _ BitOR($GUI_SS_DEFAULT_GUI, $WS_MAXIMIZEBOX, $WS_SIZEBOX)) ; $g_cLabel just to allow resizing of a richedit control ! ; Melba23 - https://www.autoitscript.com/forum/topic/204198-richedit-resize/?do=findComment&comment=1466930 $g_cLabel = GUICtrlCreateLabel("", 1, 1, $g_iGui_W - 2, $g_iGui_H - 2) GUICtrlSetResizing($g_cLabel, 1) GUICtrlSetState($g_cLabel, $GUI_DISABLE) ; Most important! (Melba23) $g_hRichEdit = _GUICtrlRichEdit_Create($g_hGuiPrev, "", 1, 1, $g_iGui_W - 2, $g_iGui_H - 2, _ BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL, $ES_WANTRETURN, $ES_NOHIDESEL, $ES_READONLY)) ; no hozizontal scrollbar ; BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL, $WS_HSCROLL, $ES_AUTOHSCROLL, $ES_WANTRETURN, $ES_NOHIDESEL, $ES_READONLY)) ; horizontal scrollbar ; To do (done) : switch $ES_READONLY off/on after richedit creation (keep the interesting Malkey's link below +++) ; https://www.autoitscript.com/forum/topic/141238-richedit-friendly-name-hyperlinks/?do=findComment&comment=993231 ; No need to use _GUICtrlRichEdit_SetBkColor as white background hurts my eyes. Keep the following line for its syntax ; _GUICtrlRichEdit_SetBkColor($g_hRichEdit, 0x00FFFFFF) ; white (note: my background is grey). White to match Forum background ; 2 following lines to allow clickable url's inside richedit controls, not forgetting $EN_LINK in Func WM_NOTIFY _GUICtrlRichEdit_SetEventMask($g_hRichEdit, $ENM_LINK) _GUICtrlRichEdit_AutoDetectURL($g_hRichEdit, True) ; True to detect URLs in text, False not to ; Nine's - https://www.autoitscript.com/forum/topic/206070-setup-permanent-font-for-richedit-control/?do=findComment&comment=1484072 Local $hFont = _WinAPI_CreateFont(14, 0, 0, 0, $FW_NORMAL, False, False, False, $DEFAULT_CHARSET, _ $OUT_DEFAULT_PRECIS, $CLIP_DEFAULT_PRECIS, $DEFAULT_QUALITY, 0, 'Lucida Console') ; trying to match $g_idEdit font _SendMessage($g_hRichEdit, $WM_SETFONT, $hFont, True) ; True = the control redraws itself _WinAPI_DeleteObject($hFont) _SetTabStops($g_hRichEdit, 14) ; 14 corresponds approx. to 4 characters width (as my Scite) in this RichEdit control with this font Else _GUICtrlRichEdit_SetText($g_hRichEdit, "") ; useful on 2nd(+) preview, to erase the text that was in the richedit control EndIf GUISetState(@SW_DISABLE, $g_hGui) GUISetState(@SW_SHOW, $g_hGuiPrev) _PreviewOrGenerate(1) ; 1 = Preview (in RichEdit control) GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") ; to take care of clickable url's in richedit control GUIRegisterMsg($WM_SIZE, "WM_SIZE") ; to resize richedit control when its Gui is resized While 4 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ; close $g_hGuiPrev (as $g_hGui is disabled at this stage) ExitLoop; While 4 Case $GUI_EVENT_MAXIMIZE, $GUI_EVENT_RESTORE ; goal is to resize correctly... the richedit control in $g_hGuiPrev _Resize() EndSwitch Wend GUIRegisterMsg($WM_SIZE, "") GUIRegisterMsg($WM_NOTIFY, "") GUISetState(@SW_HIDE, $g_hGuiPrev) GUISetState(@SW_ENABLE, $g_hGui) ControlFocus($g_hGui, "", $g_idEdit) EndFunc ;==>_GuiPrev ;================================================================= Func WM_SIZE($hWnd, $iMsg, $wParam, $lParam) If $hWnd = $g_hGuiPrev Then _Resize() ; Return 0 ; "If an application processes this message, it should return zero." (msdn) ... but bad display in this script ! EndIf Return $GUI_RUNDEFMSG EndFunc ;==>WM_SIZE ;================================================================= Func _Resize() ; Get the new position and size of the label... Local $aPos = ControlGetPos($g_hGuiPrev, "", $g_cLabel) ; ...and set the RichEdit to the same position and size WinMove($g_hRichEdit, "", $aPos[0], $aPos[1], $aPos[2], $aPos[3]) EndFunc ;==>_Resize I applied it to the code you presented in your post, it worked fine :expandcollapse popup #include <EditConstants.au3> #include <GuiRichEdit.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> ; GUI $iWidth = 800 $iHeight = 600 $iLeft = 0 $iTop = 0 $hStyle = BitOR($WS_CAPTION, $WS_SYSMENU, $WS_SIZEBOX, $WS_MINIMIZEBOX, $WS_MAXIMIZEBOX) $hExStyle = $WS_EX_DLGMODALFRAME $hGlo_WE_GUI = GUICreate("Gui title", $iWidth , $iHeight, $iLeft, $iTop, $hStyle, $hExStyle) ; $g_cLabel just to allow resizing of a richedit control ! ; Melba23 - https://www.autoitscript.com/forum/topic/204198-richedit-resize/?do=findComment&comment=1466930 $g_cLabel = GUICtrlCreateLabel("", 0, 0, $iWidth - 100, $iHeight - 100) GUICtrlSetResizing($g_cLabel, 1) GUICtrlSetState($g_cLabel, $GUI_DISABLE) ; Most important! (Melba23) ; Richedit Control $hStyle = BitOR($ES_MULTILINE, $ES_WANTRETURN, $ES_NOHIDESEL, $WS_VSCROLL, $WS_HSCROLL) $hExStyle = $WS_EX_CLIENTEDGE $hGlo_WE_Control = _GUICtrlRichEdit_Create($hGlo_WE_GUI, "", 0, 0, $iWidth - 100, $iHeight - 100, $hStyle, $hExStyle) GUISetState(@SW_SHOW) GUIRegisterMsg($WM_SIZE, "WM_SIZE") ; to resize richedit control when its Gui is resized While True Switch GUIGetMsg() Case $GUI_EVENT_CLOSE _GUICtrlRichEdit_Destroy($hGlo_WE_Control) Exit Case $GUI_EVENT_MAXIMIZE, $GUI_EVENT_RESTORE ; goal is to resize correctly... the richedit control in $hGlo_WE_GUI _Resize() EndSwitch WEnd ;================================================================= Func WM_SIZE($hWnd, $iMsg, $wParam, $lParam) If $hWnd = $hGlo_WE_GUI Then _Resize() ; Return 0 ; "If an application processes this message, it should return zero." (msdn) ... but bad display in this script ! EndIf Return $GUI_RUNDEFMSG EndFunc ;==>WM_SIZE ;================================================================= Func _Resize() ; Get the new position and size of the label... Local $aPos = ControlGetPos($hGlo_WE_GUI, "", $g_cLabel) ; ...and set the RichEdit to the same position and size WinMove($hGlo_WE_Control, "", $aPos[0], $aPos[1], $aPos[2], $aPos[3]) EndFunc ;==>_Resize In my script, I still have a minor issue with the resize part (solved with a workaround) but let's hope you won't face it. Good luck mike1950r 1 Link to comment Share on other sites More sharing options...
mike1950r Posted June 27, 2023 Author Share Posted June 27, 2023 thanks pixelsearch, i didn't know that i have to define this resize function by myself. cheers mike Link to comment Share on other sites More sharing options...
mike1950r Posted June 28, 2023 Author Share Posted June 28, 2023 Hi pixelsearch, I found another methode for resizing without disabled dummy-label: GUIRegisterMsg($WM_SIZE, "ON_WINDOW_EDIT_RESIZE") Func ON_WINDOW_EDIT_RESIZE($hWnd, $iMsg, $wParam, $lParam) Local $iHeight, $iWidth If $hWnd = $hGlo_WE_GUI Then $iWidth = _WinAPI_LoWord($lParam) $iHeight = _WinAPI_HiWord($lParam) _WinAPI_MoveWindow($hGlo_WE_Control, 0, 0, $iWidth, $iHeight) Return 0 EndIf Return $GUI_RUNDEFMSG EndFunc ;==>ON_WINDOW_EDIT_RESIZE This works excellent in my program. Cheers mike pixelsearch 1 Link to comment Share on other sites More sharing options...
pixelsearch Posted June 28, 2023 Share Posted June 28, 2023 Mike, well done, but it works in your program (without disabled dummy-label) only because your RichEdit control takes exactly all the place of the GUI client area. As your RichEdit control starts at 0,0 and its width & height are the size of the GUI client area, then you can get rid of the disabled dummy-label, because you retrieve the new width & height of the client area of the GUI (e.g. your RichEdit control dimensions) inside the resize function, by checking the low-order & high-order words of lParam But if your RichEdit Control got initially other coordinates (for example if the GUI contains other controls, or if you simply want your RichEdit control to have apparent borders visible inside the GUI) then you'll need the disabled dummy-label method... or add some maths while resizing Link to comment Share on other sites More sharing options...
mike1950r Posted June 28, 2023 Author Share Posted June 28, 2023 so I'm happy with this one. 🙂 Cheers mike 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