#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GUIImageList.au3>
#include <GUIButton.au3>
Global $hImageList = _GUIImageList_Create(16, 16, 5, 1)
Global $sOld_Opt_GRM = Opt("GUIResizeMode", $GUI_DOCKALL)
Global $iGUI_Height = 200
Global $iExpndIndx = 14
Global $iCllpsIndx = 16
If StringRegExp(@OSVersion, "^WIN_(VISTA|7)$") Then
$iExpndIndx += 1
$iCllpsIndx += 1
EndIf
$hGUI = GUICreate("Expand GUI Example", 300, $iGUI_Height, -1, -1, -1, $WS_EX_TOOLWINDOW)
$nExpand_Button = GUICtrlCreateButton("Expand", 20, 80, 80, 22) ;, $BS_ICON)
_GUICtrlButton_SetImageEx($nExpand_Button, @SystemDir & "\rasdlg.dll", $iExpndIndx)
#Region Expanded controls
GUICtrlCreateButton("Some Button", 20, 240, 80)
GUICtrlCreateButton("Other Button", 120, 240, 80)
GUICtrlCreateInput("Some Input", 20, 200, 200, 20)
#EndRegion Expanded controls
Opt("GUIResizeMode", $sOld_Opt_GRM)
GUISetState()
While 1
$Msg = GUIGetMsg()
Switch $Msg
Case $GUI_EVENT_CLOSE
_GUIImageList_Destroy($hImageList)
Exit
Case $nExpand_Button
_Toggle_ExpandControls_Proc($hGUI, $iGUI_Height, $iGUI_Height + 80, $nExpand_Button)
EndSwitch
WEnd
Func _Toggle_ExpandControls_Proc($hWnd, $iInitWndHeight, $iExpndHeight, $iExpndCtrlID, $sExpndText = "Expand", $sCntrctText = "Collapse")
Local $iHeight, $sButtonText, $aSysCaptMetrics, $aSysBordMetrics
Local $aWinSize = WinGetPos($hWnd)
Local $aWinClientSize = WinGetClientSize($hWnd)
Local $iBorderWidth = $aWinSize[2] - $aWinClientSize[0]
Local $iCaptionHeight = $aWinSize[3] - $aWinClientSize[1] - $iBorderWidth
If $aWinSize[3] > $iExpndHeight + $iCaptionHeight Then
_GUICtrlButton_SetImageEx($nExpand_Button, @SystemDir & "\rasdlg.dll", $iExpndIndx)
$iHeight = $iInitWndHeight + $iCaptionHeight + $iBorderWidth
$sButtonText = $sExpndText
Else
_GUICtrlButton_SetImageEx($nExpand_Button, @SystemDir & "\rasdlg.dll", $iCllpsIndx)
$iHeight = $iExpndHeight + $iCaptionHeight + $iBorderWidth
$sButtonText = $sCntrctText
EndIf
GUICtrlSetData($iExpndCtrlID, $sButtonText)
WinMove($hWnd, "", $aWinSize[0], $aWinSize[1], $aWinSize[2], $iHeight)
EndFunc
Func _GUICtrlButton_SetImageEx($nCtrlID, $sIconFile, $nIconID = 0, $nAlign = -1)
_GUIImageList_Remove($hImageList, -1)
_GUIImageList_AddIcon($hImageList, $sIconFile, $nIconID)
_GUICtrlButton_SetImageList($nCtrlID, $hImageList)
EndFunc