Jump to content

How to resize a child GUI?


ReFran
 Share

Recommended Posts

Hi,

I want to make a GUI with a Child GUI resizable.

GUICtrlSetResizing seems not to work for the Child GUI.

Is there a special command to resize the child GUI according to the main GUI?

Best regards, Reinhard

#include <GUIConstants.au3>

$main_GUI       = GUICreate("GUI",260,250,-1,-1)
GUISetStyle(BitOR($WS_MINIMIZEBOX, $WS_MAXIMIZEBOX, $WS_CAPTION, $WS_SIZEBOX, $WS_POPUP, $WS_SYSMENU))
GUISetBkColor(0x5686A9)
$ok_button      = GUICtrlCreateButton("OK",40,220,70,20)
$cancel_button  = GUICtrlCreateButton("Cancel",150,220,70,20)

GUISetState ()

$child1 = GUICreate("",230,170,15,35,BitOr($WS_CHILD,$WS_TABSTOP),-1,$main_GUI)
GUICtrlSetResizing($child1, $GUI_DOCKAUTO)
GUISetBkColor(0x56861A)


GUISetState (@SW_SHOW)

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE, $cancel_button
            ExitLoop
            
        
    EndSwitch
WEnd
Link to comment
Share on other sites

Catch WM_SIZE message from main GUI and set size of child window accordingly.

Here is example for catch WM_SIZE message:

#include <GuiConstants.au3>
#Include <GuiStatusBar.au3>

Const $WM_SIZE = 0x05
Const $WM_SIZING = 0x0214

Global $is_sizing = 0
Global $is_size = 0
Global $is_resized = 0

$gui = GUICreate("Test", 330, 270, -1, -1, BitOr($GUI_SS_DEFAULT_GUI,$WS_SYSMENU,$WS_SIZEBOX,$WS_MAXIMIZEBOX))
$ctrl_Edit = GUICtrlCreateEdit("", 40, 16, 250, 120, -1, $WS_EX_CLIENTEDGE)
$ctrl_Edit = GUICtrlSetData($ctrl_Edit, _
    "try to resize/maximize window" & @CRLF & _
    "with combinations of workarounds" & @CRLF & _
    "and watch positioning of statusbar" & @CRLF & @CRLF & _
    "winner from workarounds is: WM_SIZE :-)")
GUICtrlCreateGroup(' Workarounds ',40, 150, 250, 80)
$cbx_sizing = GUICtrlCreateCheckbox('WM_SIZING',50,170,100,20)
$cbx_size = GUICtrlCreateCheckbox('WM_SIZE',50,200,100,20)
$cbx_resized = GUICtrlCreateCheckbox('GUI_EVENT_RESIZED',150,170,135,20)
$cbx_ctrlresize = GUICtrlCreateCheckbox('GUICtrlSetResizing',150,200,135,20)
GUICtrlCreateGroup ("",-99,-99,1,1)
GUICtrlSetState($cbx_size, $GUI_FOCUS)
$StatusBar1 = _GuiCtrlStatusBarCreate ($gui, -1, "")
_GuiCtrlStatusBarSetText ($StatusBar1, 'status text', 0)
;~ GUICtrlSetResizing($StatusBar1,$GUI_DOCKSTATEBAR) ; don't work

GUIRegisterMsg($WM_SIZING, "MY_WM_SIZING") ; hande resize
GUIRegisterMsg($WM_SIZE, "MY_WM_SIZE") ; button maximize

GUISetState(@SW_SHOW)
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $GUI_EVENT_RESIZED
            MY_GUI_EVENT_RESIZED()
        Case $msg = $cbx_sizing
            $is_sizing = BitAnd(GUICtrlRead($cbx_sizing),$GUI_CHECKED) = $GUI_CHECKED
        Case $msg = $cbx_size
            $is_size = BitAnd(GUICtrlRead($cbx_size),$GUI_CHECKED) = $GUI_CHECKED
        Case $msg = $cbx_resized
            $is_resized = BitAnd(GUICtrlRead($cbx_resized),$GUI_CHECKED) = $GUI_CHECKED
        Case $msg = $cbx_ctrlresize
            If BitAnd(GUICtrlRead($cbx_ctrlresize),$GUI_CHECKED) = $GUI_CHECKED Then
                GUICtrlSetResizing($StatusBar1,$GUI_DOCKSTATEBAR) ; don't work
            Else
                GUICtrlSetResizing($StatusBar1,$GUI_DOCKAUTO) ; don't work
            EndIf
    EndSelect
WEnd
GUIDelete()

Func MY_WM_SIZING()
    If $is_sizing Then _GuiCtrlStatusBarResize($StatusBar1)
    Return $GUI_RUNDEFMSG
EndFunc

Func MY_WM_SIZE()
    If $is_size Then _GuiCtrlStatusBarResize($StatusBar1)
    Return $GUI_RUNDEFMSG
EndFunc

Func MY_GUI_EVENT_RESIZED()
    If $is_resized Then _GuiCtrlStatusBarResize($StatusBar1)
EndFunc
Link to comment
Share on other sites

Catch WM_SIZE message from main GUI and set size of child window accordingly.

Mmmh,

thought it would be simpler, something like $GUI_DOCKAUTO.

"Catch WM_SIZE" for a child GUI sounds like I have to do extendend calculation with getting Clientsize and WinMove(?).

However, thanks for the example and quick answer.

Greetings to Praha, Reinhard

Edited by ReFran
Link to comment
Share on other sites

After some bigger calculation and investigation ...

... attached the simple working solution.

Only the differences in width and height of childGui to mainGui are needed.

Best regards, Reinhard

#include <GUIConstants.au3>

$mainGUI        = GUICreate("GUI",260,250,20,10,$WS_OVERLAPPEDWINDOW + $WS_VISIBLE +$WS_CLIPCHILDREN + $WS_CLIPSIBLINGS)
    GUISetStyle(BitOR($WS_MINIMIZEBOX, $WS_MAXIMIZEBOX, $WS_CAPTION, $WS_SIZEBOX, $WS_POPUP, $WS_SYSMENU))
    GUISetBkColor(0x5686A9)
    $ok_button      = GUICtrlCreateButton("OK",40,220,70,20)
    $cancel_button  = GUICtrlCreateButton("Cancel",150,220,70,20)
GUISetState ()

$child1 = GUICreate("",230,170,15,35,BitOr($WS_CHILD,$WS_TABSTOP,$WS_Border),-1,$mainGUI)
    GUISetBkColor(0x56861A)

GUISetState (@SW_SHOW)
GUIRegisterMsg($WM_SIZE, 'WM_SIZE')

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE, $cancel_button
            ExitLoop
    EndSwitch
WEnd

Func WM_SIZE($hWnd, $iMsg, $iWParam, $iLParam)
    $aMGPos = WinGetClientSize ($mainGUI) 
    Winmove($child1,"",15,35,+$aMGPos[0]-30,+$aMGPos[1]-80)
endfunc
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...