JonnyThunder Posted July 25, 2008 Share Posted July 25, 2008 (edited) Hello, Created this basic script which allows the user to open up multiple windows from a system tray menu. Problem is, how can I close them. If you run this script and create two windows, then try to close the first window - it closes the second. expandcollapse popup#include <EditConstants.au3> #include <GUIConstantsEx.au3> #Include <Constants.au3> #include <WindowsConstants.au3> #Include <Misc.au3> #Include <Array.au3> ; Set tray options TraySetState() Opt("TrayMenuMode",1) ; Draw tray options $tr_newnote = TrayCreateItem("New Window") TrayItemSetState($tr_newnote, $TRAY_DEFAULT) $tr_div1 = TrayCreateItem("") $tr_exit = TrayCreateItem("Exit") ; Set up array for windows Dim $winhandle[1] Dim $currentwin = 0 ; Main loop While 1 ; Tray messages $tMsg = TrayGetMsg() if $tMsg = $tr_newnote Then $currentwin += 1 _ArrayAdd($winhandle, "") $winhandle[$currentwin] = GUICreate("Test Window " & $currentwin, 261, 161, 433, 274, BitOR($WS_SIZEBOX,$WS_THICKFRAME,$WS_CAPTION,$WS_POPUP,$WS_BORDER,$WS_CLIPSIBLINGS), BitOR($WS_EX_TOOLWINDOW,$WS_EX_WINDOWEDGE)) GUICtrlSetData(-1, "") GUICtrlSetBkColor(-1, 0xFFFF00) GUISetState(@SW_SHOW) EndIf if $tMsg = $tr_exit Then Exit EndIf ; GUI messages $nMsg = GUIGetMsg() if $nMsg = $GUI_EVENT_CLOSE Then GuiDelete() EndIf WEnd Edited July 25, 2008 by JonnyThunder Link to comment Share on other sites More sharing options...
TerarinKerowyn Posted July 25, 2008 Share Posted July 25, 2008 Because the first windows script has Parent described while each of the new windows is deemed a Child of the Parent hence closing the Parent closes everything. The thing you should try is Hide the Parent and start off with one as a Child and switching notes between each other so no child is higher up then one another Contact via MSN: [email=terarink_msn@hotmail.com]terarink_msn@hotmail.com[/email], yahoo: terarink_yah Link to comment Share on other sites More sharing options...
JonnyThunder Posted July 25, 2008 Author Share Posted July 25, 2008 I'm not sure I get what you mean. Is there no way of determining the handle of the window im closing? Then I can call GuiDelete for the right window - but no idea how you get the handle for the window im trying to close. Link to comment Share on other sites More sharing options...
TerarinKerowyn Posted July 25, 2008 Share Posted July 25, 2008 Disregard the last message I missed the part where you said you created two windows then close them Contact via MSN: [email=terarink_msn@hotmail.com]terarink_msn@hotmail.com[/email], yahoo: terarink_yah Link to comment Share on other sites More sharing options...
PsaltyDS Posted July 25, 2008 Share Posted July 25, 2008 (edited) Merry Christmas: expandcollapse popup#include <GUIConstantsEx.au3> #include <Constants.au3> #include <Array.au3> ; Set tray options TraySetState() Opt("TrayMenuMode", 1) ; Draw tray options $tr_newnote = TrayCreateItem("New Window") TrayItemSetState($tr_newnote, $TRAY_DEFAULT) $tr_div1 = TrayCreateItem("") $tr_exit = TrayCreateItem("Exit") ; Set up array for windows Dim $winhandle[1] = [0] ; Main loop While 1 ; Tray messages Switch TrayGetMsg() Case $tr_newnote $hWND = GUICreate("Test Window " & $winhandle[0] + 1, 300, 200, 200 + ($winhandle[0] * 100), 200 + ($winhandle[0] * 100)) GUICtrlSetData(-1, "") GUICtrlSetBkColor(-1, 0xFFFF00) GUISetState(@SW_SHOW) _ArrayAdd($winhandle, $hWND) $winhandle[0] = UBound($winhandle) - 1 Case $tr_exit For $n = 1 To $winhandle[0] GUIDelete($winhandle[$n]) Sleep(1000) Next Exit EndSwitch WEnd Edit: Removed #include's not required for this demo. Edited July 25, 2008 by PsaltyDS Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
TerarinKerowyn Posted July 25, 2008 Share Posted July 25, 2008 That doesn't take into account closing any window though only the main windows which closes each of the childs windows Contact via MSN: [email=terarink_msn@hotmail.com]terarink_msn@hotmail.com[/email], yahoo: terarink_yah Link to comment Share on other sites More sharing options...
TerarinKerowyn Posted July 25, 2008 Share Posted July 25, 2008 Here you go you can use GUIGetMsg() as a advance member to check over which window your doing. expandcollapse popup#include <EditConstants.au3> #include <GUIConstantsEx.au3> #Include <Constants.au3> #include <WindowsConstants.au3> #Include <Misc.au3> #include <array.au3> ; Set tray options TraySetState() Opt("TrayMenuMode",1) ; Draw tray options $tr_newnote = TrayCreateItem("New Window") TrayItemSetState($tr_newnote, $TRAY_DEFAULT) $tr_div1 = TrayCreateItem("") $tr_exit = TrayCreateItem("Exit") ; Set up array for windows Dim $winhandle[1] = [0] ; Main loop While 1 ; Tray messages $tMsg = TrayGetMsg() If $tMsg = $tr_newnote Then $hWND = GUICreate("Test Window " & $winhandle[0] + 1, 300, 200, 200 + ($winhandle[0] * 100), 200 + ($winhandle[0] * 100)) GUICtrlSetData(-1, "") GUICtrlSetBkColor(-1, 0xFFFF00) GUISetState(@SW_SHOW) _ArrayAdd($winhandle, $hWND) $winhandle[0] = UBound($winhandle) - 1 EndIf If $tMsg = $tr_exit Then Exit EndIf ; GUI messages $nMsg = GUIGetMsg(1) If $nMsg[0] = $GUI_EVENT_CLOSE Then GuiDelete($nMsg[1]) EndIf WEnd Yes I did use PsaltyDS code and your code to fully implement it. Contact via MSN: [email=terarink_msn@hotmail.com]terarink_msn@hotmail.com[/email], yahoo: terarink_yah Link to comment Share on other sites More sharing options...
NiVZ Posted July 25, 2008 Share Posted July 25, 2008 (edited) Just beat me to it Also beware when testing that if you run from SCI editor it sometimes looks like two windows have closed at once, when they are really sent behind the editing window (in other words it's best to minimise the editor once you've pressed F5) NiVZ Here you go you can use GUIGetMsg() as a advance member to check over which window your doing. expandcollapse popup#include <EditConstants.au3> #include <GUIConstantsEx.au3> #Include <Constants.au3> #include <WindowsConstants.au3> #Include <Misc.au3> #include <array.au3> ; Set tray options TraySetState() Opt("TrayMenuMode",1) ; Draw tray options $tr_newnote = TrayCreateItem("New Window") TrayItemSetState($tr_newnote, $TRAY_DEFAULT) $tr_div1 = TrayCreateItem("") $tr_exit = TrayCreateItem("Exit") ; Set up array for windows Dim $winhandle[1] = [0] ; Main loop While 1 ; Tray messages $tMsg = TrayGetMsg() If $tMsg = $tr_newnote Then $hWND = GUICreate("Test Window " & $winhandle[0] + 1, 300, 200, 200 + ($winhandle[0] * 100), 200 + ($winhandle[0] * 100)) GUICtrlSetData(-1, "") GUICtrlSetBkColor(-1, 0xFFFF00) GUISetState(@SW_SHOW) _ArrayAdd($winhandle, $hWND) $winhandle[0] = UBound($winhandle) - 1 EndIf If $tMsg = $tr_exit Then Exit EndIf ; GUI messages $nMsg = GUIGetMsg(1) If $nMsg[0] = $GUI_EVENT_CLOSE Then GuiDelete($nMsg[1]) EndIf WEnd Yes I did use PsaltyDS code and your code to fully implement it. Edited July 25, 2008 by NiVZ Link to comment Share on other sites More sharing options...
JonnyThunder Posted July 25, 2008 Author Share Posted July 25, 2008 Wicked, thanks very much. I'll get back to work on the app then! 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