Champak Posted June 23, 2023 Posted June 23, 2023 I'm having an issue with bottom docking a child gui to a parent gui. The UDF in question is with The below example is what I'm trying to achieve. The regular button on the left is how I need the button (actually a gui) on the right to doc....to the bottom. I have found a couple of threads about docking guis, but they all doc the same way, from the top. I need to bottom doc these buttons and have no idea how to approach this. Why don't I just use the regular buttons? Because I want some of my buttons to have color and the regular buttons capture the ENTER key which messes things up. expandcollapse popup#include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> #include "GuiFlatButton.au3" Opt("GUIResizeMode", 4) Example() ;GUI with one button Func Example() Local $hGUI, $mybutton1 $hGUI = GUICreate("GuiFlatButton Ex0", 325, 120, -1, -1, BITOR($GUI_SS_DEFAULT_GUI, $WS_SIZEBOX)) GUISetBkColor(0x333333) Local $idLabel = GUICtrlCreateLabel("Click the button", 10, 100, 150, 30) GUICtrlSetColor(-1, 0xFFFFFF) ;create new button then set the background and foreground colors $mybutton1 = GuiFlatButton_Create("Button 1" & @CRLF & "Line 2", 180, 20, 120, 40, $BS_MULTILINE) ;GUICtrlSetResizing(-1, $GUI_DOCKSIZE+$GUI_DOCKBOTTOM+$GUI_DOCKLEFT) GuiFlatButton_SetBkColor(-1, 0x5555FF) GuiFlatButton_SetColor(-1, 0xFFFFFF) GUICtrlCreateButton("Button 2", 0, 20, 120, 40) GUICtrlSetResizing(-1, $GUI_DOCKSIZE+$GUI_DOCKBOTTOM+$GUI_DOCKLEFT) GUISetState(@SW_SHOW, $hGUI) Local $i = 0 Local $iMsg While 1 $iMsg = GUIGetMsg() Switch $iMsg Case $GUI_EVENT_CLOSE ExitLoop Case $mybutton1 $i += 1 GUICtrlSetData($idLabel, $i) ConsoleWrite($i & @CRLF) EndSwitch Sleep(10) WEnd GUIDelete() EndFunc ;==>Example
Solution Andreik Posted June 23, 2023 Solution Posted June 23, 2023 Register WM_SIZING and do the math to move the control by your own desire. expandcollapse popup#include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> #include "GuiFlatButton.au3" Opt("GUIResizeMode", 4) Global $hGUI, $mybutton1 $hGUI = GUICreate("GuiFlatButton Ex0", 325, 120, -1, -1, BITOR($GUI_SS_DEFAULT_GUI, $WS_SIZEBOX)) GUISetBkColor(0x333333) Local $idLabel = GUICtrlCreateLabel("Click the button", 10, 100, 150, 30) GUICtrlSetColor(-1, 0xFFFFFF) ;create new button then set the background and foreground colors $mybutton1 = GuiFlatButton_Create("Button 1" & @CRLF & "Line 2", 180, 20, 120, 40, $BS_MULTILINE) ;GUICtrlSetResizing(-1, $GUI_DOCKSIZE+$GUI_DOCKBOTTOM+$GUI_DOCKLEFT) GuiFlatButton_SetBkColor(-1, 0x5555FF) GuiFlatButton_SetColor(-1, 0xFFFFFF) GUICtrlCreateButton("Button 2", 0, 20, 120, 40) GUICtrlSetResizing(-1, $GUI_DOCKSIZE+$GUI_DOCKBOTTOM+$GUI_DOCKLEFT) GUISetState(@SW_SHOW, $hGUI) GUIRegisterMsg(0x0214, 'WM_SIZING') Local $i = 0 Local $iMsg While 1 $iMsg = GUIGetMsg() Switch $iMsg Case $GUI_EVENT_CLOSE ExitLoop Case $mybutton1 $i += 1 GUICtrlSetData($idLabel, $i) ConsoleWrite($i & @CRLF) EndSwitch Sleep(10) WEnd GUIDelete() Func WM_SIZING($hWnd, $iMsg, $wParam, $lParam) If $hWnd = $hGUI Then ; Title bar height Local $iTBHeight = _WinAPI_GetSystemMetrics(33) + _WinAPI_GetSystemMetrics(4) + _WinAPI_GetSystemMetrics(92) Local $tRECT = DllStructCreate('long Left;long Top;long Right;long Bottom;', $lParam) Local $aPos = GuiFlatButton_GetPos($mybutton1) ; Initial GUI Size = 120, button starts at 20 and has a height of 40, basically from buttom of the control to the bottom of the window are 60 pixels ; so we add just the height of the button and we end up with 100px Local $iBottom = DllStructGetData($tRECT, 'Bottom') - DllStructGetData($tRECT, 'Top') - $iTBHeight - 100 GuiFlatButton_SetPos($mybutton1, 180, $iBottom, $aPos[2], $aPos[3]) EndIf EndFunc I used 100px as a constant but it might be obtained with simple math. As you can see it's slightly different by how GUI docking resize and move the controls but this is expected since I don't know what formula is used by GUICtrlSetResizing().
Champak Posted June 23, 2023 Author Posted June 23, 2023 For some reason $tRECT = DllStructCreate('long Left;long Top;long Right;long Bottom;', $lParam) didn't work for my app, it was causing it to freeze up and shut down, but $tRECT = _WinAPI_GetClientRect($hWnd) works with no issue. Thanks for the help.
Andreik Posted June 23, 2023 Posted June 23, 2023 It's strange but it's good that you did it in a different way and get the job done.
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