MacScript Posted June 26, 2014 Posted June 26, 2014 (edited) HI all - I need some help with resizing my GUI that has many controls on it including a richedit control. I was having it all resize automatically, but found out that rich edits do not work that way. So I searched the forums and found WM_Size so that fixed my richedit. but nothing else resizes any more. I have about 15 items that need to be resized. Below is a code snippet showing my issue. Any suggestions for forum searches would be appreciated or a function I should use. Thanks Again ahead of time. expandcollapse popup; Credit for soem of this script comes from :http://www.autoitscript.com/wiki/Tabs #include <GUIConstantsEx.au3> #include <GuiRichEdit.au3> #include <GUIImageList.au3> #include <WindowsConstants.au3> #include <GuiTab.au3> GUIRegisterMsg($WM_SIZE, "WM_SIZE") $hGUI = GUICreate("Tabs w/RichEdit To be resized", 500, 500, -1, -1,$WS_SIZEBOX) global $TabShtMain = GUICtrlCreateTab(10, 10, 480, 480) GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKTOP) global $testtab1 = GUICtrlCreateTabItem("Plain CreateEdit Field") Global $Input = GUICtrlCreateEdit("", 20, 40, 460, 400, $WS_VSCROLL) GUICtrlCreateTabItem("Richtext Field" ) $hRichEdit = _GUICtrlRichEdit_Create($hGui, "", 20,40,460,400, BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL)) ControlHide($hGUI, "", $hRichEdit) GUICtrlCreateTabItem("") GUISetState(@SW_SHOW, $hGUI) ; Makes GUI Visible $iLastTab = 0 While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $TabShtMain ; Check which Tab is active $iCurrTab = GUICtrlRead($TabShtMain) ; If the Tab has changed If $iCurrTab <> $iLastTab Then ; Show/Hide controls as required Switch $iCurrTab Case 0 ControlHide($hGUI, "", $hRichEdit) Case 1 ControlShow($hGUI, "", $hRichEdit) EndSwitch ; Store the value for future comparisons $iLastTab = $iCurrTab EndIf EndSwitch WEnd Func WM_SIZE($hWnd, $iMsg, $wParam, $lParam) Local $iWidth = _WinAPI_LoWord($lParam) Local $iHeight = _WinAPI_HiWord($lParam) _WinAPI_MoveWindow($hRichEdit, 20, 40, $iWidth - 40, $iHeight - 100) Return 0 EndFunc ;==>WM_SIZE Edited June 26, 2014 by MacScript
MacScript Posted June 27, 2014 Author Posted June 27, 2014 Found this and have added GUICtrlSetPos for each control that needs to be resized into the WM_Size function. 1) Is this the correct way to do this or is there a better way? 2) Seems like my gui is not as responsive as it was prior to adding in WM_size registration. Does WM_Size add more cpu cycles? Thanks for all responses, I appreciate the help I get from the Autoit Community.
Moderators Solution Melba23 Posted June 27, 2014 Moderators Solution Posted June 27, 2014 MacScript,You need to return $GUI_RUNDEFMSG from the original message handler - at present you are returning 0 which tells AutoIt to ignore the message and so it does not honour the size change for its own controls:expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GuiRichEdit.au3> Opt("GUIResizeMode",$GUI_DOCKAUTO) $hGUI = GUICreate("Tabs w/RichEdit to be resized", 500, 500, -1, -1, $WS_SIZEBOX) Global $TabShtMain = GUICtrlCreateTab(10, 10, 480, 460) GUICtrlCreateTabItem("Plain CreateEdit Field") Global $Input = GUICtrlCreateEdit("", 20, 40, 460, 420, $WS_VSCROLL) GUICtrlCreateTabItem("Richtext Field") GUICtrlCreateTabItem("") GUISetState(@SW_SHOW, $hGUI) ; Makes GUI Visible $hRichEdit = _GUICtrlRichEdit_Create($hGUI, "", 20, 40, 460, 420, BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL)) ControlHide($hGUI, "", $hRichEdit) GUIRegisterMsg($WM_SIZE, "WM_SIZE") While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $TabShtMain ConsoleWrite("Hit" & @CRLF) ; Check which Tab is active $iCurrTab = GUICtrlRead($TabShtMain) ; Show/Hide controls as required Switch $iCurrTab Case 0 ControlHide($hGUI, "", $hRichEdit) Case 1 ControlShow($hGUI, "", $hRichEdit) EndSwitch EndSwitch WEnd Func WM_SIZE($hWnd, $iMsg, $wParam, $lParam) If $hWnd = $hGUI Then Local $iWidth = _WinAPI_LoWord($lParam) Local $iHeight = _WinAPI_HiWord($lParam) _WinAPI_MoveWindow($hRichEdit, 20, 40, $iWidth - 40, $iHeight - 40) EndIf Return $GUI_RUNDEFMSG ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< EndFunc ;==>WM_SIZENote that you do not need to track the tab index - the tab control only fires an event when the tab is changed, so the index will always be different. I have never noticed any slow-down when registering Windows messages. Perhaps if you posted the whole script we might be able to offer some advice on why this might be happening. 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
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