#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
Opt("GUIEventOptions", 1)
Global $aLast_Child_Pos
$hMain_GUI = GUICreate("Move The parent - MDI Demo", 400, 300, -1, -1, BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPCHILDREN))
$nDummy = GUICtrlCreateLabel("", -100, -100)
GUICtrlSetState($nDummy, $GUI_HIDE)
GUISetState(@SW_SHOW, $hMain_GUI)
$aChild_GUI = _MDI_GUICreate("Child window", 200, 100, 5, 5, BitOr($GUI_SS_DEFAULT_GUI, $WS_MAXIMIZEBOX), $WS_EX_TOPMOST, $hMain_GUI)
While 1
$aMsg = GUIGetMsg(1)
Select
Case $aMsg[0] = $GUI_EVENT_CLOSE
Switch $aMsg[1]
Case $hMain_GUI
Exit
Case Else
GUIDelete($aMsg[1])
EndSwitch
Case $aMsg[0] = $GUI_EVENT_MINIMIZE
If $aMsg[1] = $hMain_GUI Then
GUISetState(@SW_MINIMIZE, $aMsg[1])
ContinueLoop
EndIf
$aLast_Child_Pos = WinGetPos($aMsg[1])
GUISetState(@SW_MINIMIZE, $aMsg[1])
Case $aMsg[0] = $GUI_EVENT_RESTORE
GUISetState(@SW_RESTORE, $aMsg[1])
Case $aMsg[0] = $GUI_EVENT_MAXIMIZE
If $aMsg[1] = $hMain_GUI Then
GUISetState(@SW_MAXIMIZE, $aMsg[1])
ContinueLoop
EndIf
$aLast_Child_Pos = WinGetPos($aMsg[1])
GUISetState(@SW_MAXIMIZE, $aMsg[1])
GUISetStyle($WS_POPUPWINDOW, -1, $aMsg[1])
GUICtrlSetState($aChild_GUI[1], $GUI_SHOW)
Case $aMsg[0] = $aChild_GUI[1]
If $aMsg[1] = $hMain_GUI Then
ContinueLoop
EndIf
Local $tPoint = DllStructCreate("int X;int Y")
DllStructSetData($tPoint, "X", $aLast_Child_Pos[0])
DllStructSetData($tPoint, "Y", $aLast_Child_Pos[1])
_WinAPI_ScreenToClient($hMain_GUI, $tPoint)
$aLast_Child_Pos[0] = DllStructGetData($tPoint, "X")
$aLast_Child_Pos[1] = DllStructGetData($tPoint, "Y")
GUISetState(@SW_RESTORE, $aMsg[1])
GUISetStyle(BitOr($GUI_SS_DEFAULT_GUI, $WS_MAXIMIZEBOX), -1,$aMsg[1] )
WinMove($aMsg[1], "", $aLast_Child_Pos[0], $aLast_Child_Pos[1], $aLast_Child_Pos[2], $aLast_Child_Pos[3])
GUICtrlSetState($aChild_GUI[1], $GUI_HIDE)
EndSelect
WEnd
Func _MDI_GUICreate($sTitle, $iWidth, $iHeight, $iLeft, $iTop, $nStyle, $nExStyle, $hWnd)
Local $hChild_GUI = GUICreate($sTitle, $iWidth, $iHeight, $iLeft, $iTop, $nStyle, $nExStyle, $hWnd)
Local $nRestore_Btn = GUICtrlCreateButton("p", $iWidth - 20, 3, 18, 18)
GUICtrlSetFont($nRestore_Btn, 10, 400, 0, "Wingdings")
GUICtrlSetState($nRestore_Btn, $GUI_HIDE)
_WinAPI_SetParent($hChild_GUI, $hWnd)
GUISetState(@SW_SHOW, $hChild_GUI)
Local $aRet[2] = [$hChild_GUI, $nRestore_Btn]
Return $aRet
EndFunc