Jump to content
Sign in to follow this  
JonnyThunder

Closing multiple windows

Recommended Posts

JonnyThunder

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.

#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 by JonnyThunder

Share this post


Link to post
Share on other sites
TerarinKerowyn

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

Share this post


Link to post
Share on other sites
JonnyThunder

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.

Share this post


Link to post
Share on other sites
TerarinKerowyn

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

Share this post


Link to post
Share on other sites
PsaltyDS

Merry Christmas:

#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

:P

Edit: Removed #include's not required for this demo.

Edited 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

Share this post


Link to post
Share on other sites
TerarinKerowyn

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

Share this post


Link to post
Share on other sites
TerarinKerowyn

Here you go you can use GUIGetMsg() as a advance member to check over which window your doing.

#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

Share this post


Link to post
Share on other sites
NiVZ

Just beat me to it :P

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.

#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 by NiVZ

Share this post


Link to post
Share on other sites
JonnyThunder

Wicked, thanks very much. I'll get back to work on the app then! :P

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.