momar33 Posted July 14, 2007 Share Posted July 14, 2007 See the code below. I can open and close multiple MDI windows fine, untill it comes to the last one. If the windows aren't closed in the opposite order they were opened, the last window closed causes the entire program to go into the background. So be sure to have another program or folder running when you test this out. Here is the code: expandcollapse popup#include <GUIConstants.au3> ;#include <database.au3> ;#include <variables.au3> Global $child[1000] Global $spellEdit Local $parentWidth = 800 Local $parentHeight = 500 Local $parentLeft = -1 Local $parentTop = -1 Local $toolBarWidth = $parentWidth Local $toolBarHeight = 30 Local $toolBarLeft = 0 Local $toolBarTop = 0 Local $mainWidth = $parentWidth Local $mainHeight = $parentHeight - 50 Local $mainLeft = 0 Local $mainTop = $toolBarHeight ;AutoItSetOption("MustDeclareVars", 1) Opt("GUIOnEventMode", 1) ; Change to OnEvent mode Global $parentGui = GUICreate("Spell Inventory", $parentWidth, $parentHeight, $parentLeft, $parentTop, $WS_OVERLAPPEDWINDOW) _CreateEvents() GUISetState() _CreateMenu() _CreateToolbar($toolBarWidth, $toolBarHeight, $toolBarLeft, $toolBarTop) Global $mainGui=GUICreate("mainGui", $mainWidth, $mainHeight, 0, 30, $WS_CHILD, Default, $parentGui) GUISetState () While 1 Sleep(10) Wend Func _Exit() ;MsgBox(0, "", "test2" & @GUI_WINHANDLE) ;MsgBox(0, "", WinGetHandle($child[$numChildGuis])) If @GUI_WINHANDLE = $parentGui Then ;GUISwitch($parentGui) GuiDelete() Exit ElseIf @GUI_WINHANDLE = WinGetHandle($child[$numChildGuis]) Then ;MsgBox(0,"","test") GUISwitch(WinGetHandle($child[$numChildGuis])) GuiDelete() GUISetState(@SW_SHOW,$parentGui) EndIf EndFunc Func _MakeNewChild() Global $numChildGuis if $numChildGuis < 1000 then ;~ $gui[$x] = GUICreate("",200,90,100+$numChildGuis*5,100+$numChildGuis*5, BitOR($WS_POPUPWINDOW, $WS_CHILD),$WS_EX_TOOLWINDOW) ;~ ;$child = GUICreate("View Spells", 400, 350, 100, 0, BitOR($WS_OVERLAPPEDWINDOW, $WS_CHILD), Default, $mainGui) ;~ DllCall("user32.dll", "int", "SetParent", "hwnd", WinGetHandle($Gui[$x]), "hwnd", WinGetHandle($Main_GUI)) $child[$numChildGuis] = GUICreate("View Spells", 400, 350, 100+$numChildGuis*5, 0+$numChildGuis*5, $WS_OVERLAPPEDWINDOW, Default, $mainGui) DllCall("user32.dll", "int", "SetParent", "hwnd", WinGetHandle($child[$numChildGuis]), "hwnd", WinGetHandle($mainGui)) GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit") GUISetState() $numChildGuis = $numChildGuis +1 EndIf EndFunc Func _CreateMenu() ;-----File Menu----- Global $fileMenu = GuiCtrlCreateMenu ("File") Global $importMI = GuiCtrlCreateMenuitem ("Import File",$filemenu) Global $separator = GuiCtrlCreateMenuitem ("",$filemenu) Global $ppOptionsMenu = GuiCtrlCreateMenu ("Print Preview Options",$filemenu) Global $separator = GuiCtrlCreateMenuitem ("",$filemenu) Global $exitMI = GuiCtrlCreateMenuitem ("Exit",$filemenu) ;-----Tools Menu----- Global $toolsMenu = GuiCtrlCreateMenu ("Tools") Global $manageSpellbooksMI = GuiCtrlCreateMenuitem ("Manage Spellbooks",$toolsMenu) Global $manageSchoolsMI = GuiCtrlCreateMenuitem ("Manage Schools",$toolsMenu) Global $manageSpellsMI = GuiCtrlCreateMenuitem ("Manage Spells",$toolsMenu) Global $separator = GuiCtrlCreateMenuitem ("",$toolsMenu) Global $manageScrollsMI = GuiCtrlCreateMenuitem ("Manage Scrolls",$toolsMenu) Global $separator = GuiCtrlCreateMenuitem ("",$toolsMenu) Global $searchMI = GuiCtrlCreateMenuitem ("Search",$toolsMenu) ;-----Window Menu----- Global $windowMenu = GuiCtrlCreateMenu ("Window") Global $tileMI = GuiCtrlCreateMenuitem ("Tile",$windowMenu) Global $separator = GuiCtrlCreateMenuitem ("",$windowMenu) Global $cascadeMI = GuiCtrlCreateMenuitem ("Cascade",$windowMenu) ;-----About Menu----- Global $aboutMenu = GuiCtrlCreateMenu ("About") Global $helpTopicsMI = GuiCtrlCreateMenuitem ("Help Topics",$aboutMenu) Global $separator = GuiCtrlCreateMenuitem ("",$aboutMenu) Global $aboutMI = GuiCtrlCreateMenuitem ("About SI",$aboutMenu) EndFunc Func _CreateToolbar($width, $height, $left, $top) Global $toolbar=GUICreate("toolbar", $width, $height, $left, $top, $WS_CHILD, Default, $parentGui) Global $viewSpell = GUICtrlCreateButton ("Spell", 0,0,50,20) GUICtrlSetOnEvent(-1, "_MakeNewChild") GUISetState () EndFunc Func _CreateEvents() GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit") GUISetOnEvent($GUI_EVENT_RESIZED, "_UpdateChildGui") GUISetOnEvent($GUI_EVENT_MAXIMIZE, "_UpdateChildGui") GUISetOnEvent($GUI_EVENT_RESTORE, "_UpdateChildGui") EndFunc Func _UpdateChildGui() Local $state = WinGetState($child[$numChildGuis]) Local $array = WinGetPos($parentGui) WinMove($mainGui, '', 0, 30, ($array[2]-8), ($array[3]-84)) If BitAnd($state, 32) Then ; x, y, width, heighth WinMove($child[$numChildGuis], '', -4, -4, $array[2], ($array[3]-76)) EndIf EndFunc Link to comment Share on other sites More sharing options...
martin Posted July 14, 2007 Share Posted July 14, 2007 See the code below. I can open and close multiple MDI windows fine, untill it comes to the last one. If the windows aren't closed in the opposite order they were opened, the last window closed causes the entire program to go into the background. I don't know why it happens but this will fix it. I suppose that when a window is deleted windows switches to the previously active window which is not listed as the Spell Inventory for some reason. (The fix for child windows in your other thread is useful btw.) Func _Exit() If @GUI_WINHANDLE = $parentGui Then ;GUISwitch($parentGui) GuiDelete() Exit ElseIf @GUI_WINHANDLE = WinGetHandle($child[$numChildGuis]) Then GUIDelete(WinGetHandle($child[$numChildGuis])) WinActivate("Spell Inventory") EndIf EndFunc Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
Zedna Posted July 14, 2007 Share Posted July 14, 2007 I had similar problem and I solved it by using: GUICtrlSetState($control_from_parent, $GUI_FOCUS)oÝ÷ Øò¢êÜjǺÚ"µÍ[ÈÑ^] BÓÙÐÞ ][ÝÉ][ÝË ][ÝÝÝ][ÝÈ [ÈÕRWÕÒSSJBÓÙÐÞ ][ÝÉ][ÝËÚ[Ù][J ÌÍØÚ[ÉÌÍÛ[PÚ[ÝZ×JJBYÕRWÕÒSSHH ÌÍÜ[ÝZH[ÑÕRTÝÚ]Ú ÌÍÜ[ÝZJBÝZQ[]J B^][ÙRYÕRWÕÒSSHHÚ[Ù][J ÌÍØÚ[ÉÌÍÛ[PÚ[ÝZ×JH[ÓÙÐÞ ][ÝÉ][ÝË ][ÝÝÝ ][ÝÊBÕRTÝÚ]Ú Ú[Ù][J ÌÍØÚ[ÉÌÍÛ[PÚ[ÝZ×JJBÝZQ[]J BÕRTÙ]Ý]JÕ×ÔÒÕË ÌÍÜ[ÝZJBÕRPÝÙ]Ý]J ÌÍØÛÛÛÙÛWÜ[ ÌÍÑÕRWÑÐÕTÊB[Y[[ You have parent GUI empty (without controls) so I wrote $control_from_parent which should be some control to be focused. Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
momar33 Posted July 14, 2007 Author Share Posted July 14, 2007 I don't know why it happens but this will fix it. I suppose that when a window is deleted windows switches to the previously active window which is not listed as the Spell Inventory for some reason. (The fix for child windows in your other thread is useful btw.) Func _Exit() If @GUI_WINHANDLE = $parentGui Then ;GUISwitch($parentGui) GuiDelete() Exit ElseIf @GUI_WINHANDLE = WinGetHandle($child[$numChildGuis]) Then GUIDelete(WinGetHandle($child[$numChildGuis])) WinActivate("Spell Inventory") EndIf EndFunc Thanks, this worked great. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now