Jump to content

Child closes program,


Recommended Posts

Hello,

I have written a small gui to test some stuff, but now i have made a child window,

and when i close the child the whole program is closed.

does anybody know how i could prevent the program to close when i close a child window

i have te code from several tutorials found on the internet

While 1
    $msg = GUIGetMsg()
    
    Select
        Case $msg = $MenuExit
            ExitLoop
        Case $msg = $MenuHelp
            $child = GUICreate( "Help", 500, 500, 20, 20, -1, -1, $wnd)
            $Text = GUICtrlCreateEdit( "", 0, 0 , 500, 500, BitOR($ES_MULTILINE, $ES_READONLY) )
            
            GUICtrlSetData($Text, "test, " & @CRLF & @CRLF & "test", 1)
            
            GUISetState( @SW_SHOW )
            
        Case $msg = $startButton
            
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
    EndSelect
    
WEnd

i just started a few days ago so please comment anything you see that could also be done better

Edited by grimreaper
Link to comment
Share on other sites

I had a problem like this once too. How I got passed it was like this.

If $msg = $GUI_EVENT_CLOSE Then
    If WinActive("This GUI Title") Then 
        GUISwitch($tGui)  ;Other gui
        GUIDelete()
    Else
        Exit
    EndIf
EndIf

100th Post - Woot!

Edited by spudw2k
Link to comment
Share on other sites

That worked

Thanks

if there is a better solution for later purposes i like to hear it

but in the mean while thanks

Try this:

#include <GuiConstants.au3>

$hMainGUI = GUICreate("Main GUI", 300, 200)

$SwitchButton = GUICtrlCreateButton("Switch", 100, 50, 60, 25)

$hChildGUI = GUICreate("Child GUI", 200, 100, -1, -1, -1, -1, $hMainGUI)

GUISetState(@SW_SHOW, $hMainGUI)

While 1
    $msg = GUIGetMsg(1)
    Select
        Case $msg[0] = $GUI_EVENT_CLOSE  And $msg[1] = $hMainGUI
            ExitLoop
        Case $msg[0] = $GUI_EVENT_CLOSE  And $msg[1] = $hChildGUI
            GUISetState(@SW_ENABLE, $hMainGUI)
            GUISetState(@SW_HIDE, $hChildGUI)
        Case $msg[0] = $SwitchButton
            GUISetState(@SW_DISABLE, $hMainGUI)
            GUISetState(@SW_SHOW, $hChildGUI)
    EndSelect
WEnd

:)

Link to comment
Share on other sites

While 1
    $msg = GUIGetMsg(1)
    Select
        Case $msg[0] = $GUI_EVENT_CLOSE  And $msg[1] = $hMainGUI
            ExitLoop
        Case $msg[0] = $GUI_EVENT_CLOSE  And $msg[1] = $hChildGUI
            GUISetState(@SW_ENABLE, $hMainGUI)
            GUISetState(@SW_HIDE, $hChildGUI)
        Case $msg[0] = $SwitchButton
            GUISetState(@SW_DISABLE, $hMainGUI)
            GUISetState(@SW_SHOW, $hChildGUI)
    EndSelect
WEnd
That seems like a better solution, Thanks

:)

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...