Opt("GUIOnEventMode",1)
Opt("WinSearchChildren",1)
$guiname = "MAIN"
$gui = GUICreate($guiname,IniRead(@ScriptDir & "\test.ini","main","size_x","1200"),IniRead(@ScriptDir & "\test.ini","main","size_y","800"),IniRead(@ScriptDir & "\test.ini","main","pos_x","200"),IniRead(@ScriptDir & "\test.ini","main","pos_y","200"),BitOR(0x00010000,0x00020000,0x00040000))
GUISetOnEvent(-3,"_Exit_",$gui)
GUICtrlCreateLabel("",-100,-100,0,0)
GUISetState()
$guiname_tool = "TOOL"
$gui_tool = GUICreate($guiname_tool,IniRead(@ScriptDir & "\test.ini","tool","size_x","200"),IniRead(@ScriptDir & "\test.ini","tool","size_y","100"),IniRead(@ScriptDir & "\test.ini","tool","pos_x","20"),IniRead(@ScriptDir & "\test.ini","tool","pos_y","20"),0x00C00000,-1,$gui)
DllCall("user32.dll","int","SetParent","hwnd",$gui_tool,"hwnd",$gui)
GUICtrlCreateLabel("",-100,-100,0,0)
GUISetState(@SW_SHOW,$gui_tool)
While 1
Sleep(100)
WEnd
Func _Exit_()
$pos_main = WinGetPos($guiname)
IniWrite(@ScriptDir & "\test.ini","main","pos_x",$pos_main[0])
IniWrite(@ScriptDir & "\test.ini","main","pos_y",$pos_main[1])
IniWrite(@ScriptDir & "\test.ini","main","size_x",$pos_main[2])
IniWrite(@ScriptDir & "\test.ini","main","size_y",$pos_main[3])
$pos_tool = _Win_GetChildPos($guiname,$guiname_tool)
IniWrite(@ScriptDir & "\test.ini","tool","pos_x",$pos_tool[0] - $pos_main[0])
IniWrite(@ScriptDir & "\test.ini","tool","pos_y",$pos_tool[1] - $pos_main[1])
IniWrite(@ScriptDir & "\test.ini","tool","size_x",$pos_tool[2])
IniWrite(@ScriptDir & "\test.ini","tool","size_y",$pos_tool[3])
Exit
EndFunc
Func _Win_GetChildPos($h_parent, $h_child)
Local $h_wnd = ControlGetHandle($h_parent, "", $h_child)
Return WinGetPos($h_wnd)
EndFunc