I am currently working on a project to automate repetitive tasks at work. Data is entered into a form and the design requires that certain fields and other controls only display when certain controls are selected (primarily check boxes). Due to this I need a manageable way to re-size the form window on a check box event. I experimented with wrapping the GUI code in a function so the entire form is redrawn when the check box is checked or unchecked. This has turned out to not be very maintainable as I need to save all currently entered data and other control states when recreating the form with the new size (and adding new controls). Ideally I would simply be able to change the existing window size and move existing controls down as needed to make room for new ones (and vice versa). Searching the forums here I found mention of the WinMove() function which at first glance appeared to offer this functionality. When called like this: WinMove( "FormTitle", "", Default, Default, $newWidth, $newHeight ) A strange thing happens, however. When doubling the height of the form window (as determined by GetClientWindow()) it only gets marginally larger, and when halving it back to the original height it is smaller than when it started. Here is the original size: Here is the doubled size: And then halved, when it should return to the original: Here is the relevant code: #include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Opt( 'GUIOnEventMode', 1 )
Global Const $TITLE = "Expand"
; GUI Code
Global $Window = GUICreate($TITLE, 429, 36, 200, 124)
Global $Checkbox1 = GUICtrlCreateCheckbox("Expand 1", 8, 8, 97, 17)
GUISetState(@SW_SHOW)
; Global state variables associated with the GUI
Global $WindowSize = WinGetClientSize( $TITLE )
Global $WindowWidth = $WindowSize[0]
Global $WindowHeight = $WindowSize[1]
; Register callbacks
GUICtrlSetOnEvent( $Checkbox1, "Checkbox1" )
Func Checkbox1()
If GUICtrlRead( $Checkbox1 ) = $GUI_CHECKED Then
DebugWindow()
$WindowHeight *= 2
UpdateWindow()
DebugWindow()
Else
DebugWindow()
$WindowHeight /= 2
UpdateWindow()
DebugWindow()
EndIf
EndFunc
Func DebugWindow()
MsgBox( 0, "Debug", "Window Size: " & @CRLF & @CRLF & _
"Window width: " & $WindowWidth & @CRLF & _
"Window height: " & $WindowHeight )
EndFunc
Func UpdateWindow()
WinMove( $TITLE, "", Default, Default, $WindowWidth, $WindowHeight )
EndFunc
; Main idle loop
While 1
Sleep(1000)
WEnd I'm sure this is a case of my doing something wrong, and if anyone has any ideas I would greatly appreciate any input. Alternately, if anyone has used another, more viable method for handling window resizing I am also open to suggestions. Thanks in advance!