#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ButtonConstants.au3>
#include <WinAPI.au3>
Global $hChild_GUI, $G_hHook
Opt("GUIOnEventMode", 1)
Global $hGUI = GUICreate("Parent & Child Demo", 500, 250)
GUISetOnEvent(-3, "_Exit")
$nCreateChild_Button = GUICtrlCreateButton("Child", 20, 40, 80, 20)
GUICtrlSetOnEvent(-1, "_Start")
GUISetState(@SW_SHOW, $hGUI)
GUIRegisterMsg($WM_COMMAND, 'WM_COMMAND1')
While 1
Sleep(1000)
WEnd
Func _Start()
_Child_GUI($hGUI)
EndFunc
Func _Child_GUI($hParent)
GUISetState(@SW_DISABLE, $hParent)
OnAutoItExitRegister("_onExit")
$hChild_GUI = GUICreate("Child GUI", 300, 150, -1, -1, -1, -1, $hParent)
GUISetOnEvent(-3, "_Exit2")
GUICtrlCreateButton("Test", 10, 40, 100, 20)
GUISetState(@SW_SHOW, $hChild_GUI)
Local $hProc = DllCallbackRegister('_WinEvent', 'ptr', 'hwnd;uint;wparam;lparam')
$G_hHook = _WinAPI_SetWindowLong($hChild_GUI, -4, DllCallbackGetPtr($hProc))
EndFunc
Func _WinEvent($hWind, $soMsg, $sowParam, $solParam)
If $soMsg = $WM_NOTIFY Then
; WM_NOTIFY2($hWind, $soMsg, $sowParam, $solParam)
ElseIf $soMsg = $WM_COMMAND Then
WM_COMMAND2($hWind, $soMsg, $sowParam, $solParam)
EndIf
Return _WinAPI_CallWindowProc($G_hHook, $hWind, $soMsg, $sowParam, $solParam)
EndFunc
Func WM_COMMAND1($hWnd, $iMsg, $wParam, $lParam)
Switch _WinAPI_HiWord($wParam)
Case $BN_CLICKED
ConsoleWrite("==> GUI 1"& @CRLF)
EndSwitch
EndFunc
Func WM_COMMAND2($hWnd, $iMsg, $wParam, $lParam)
Switch _WinAPI_HiWord($wParam)
Case $BN_CLICKED
ConsoleWrite("==> GUI 2"& @CRLF)
_Exit2()
EndSwitch
EndFunc
Func _Exit()
Exit
EndFunc
Func _Exit2()
GUISetState(@SW_ENABLE, $hGUI)
GUIDelete($hChild_GUI)
EndFunc
Func _onExit()
_WinAPI_SetWindowLong($hChild_GUI, -4, $G_hHook)
EndFunc