Jump to content

Working with 2 GUI's can't close second GUI


Recommended Posts

I'v been beating my head over this. I searched and search the forum and actualy found a recent thread with a similar issue 2 GUI's

I have a larger program but I have pulled out all no essental stuff and it still doesn't work. I can start the the main GUI and then open the second GUI (my settings GUI) but it won't let me close the GUI and return to the main GUI. From the code you see I've tried to put the GUI exit code in diffrent spots and it still fails. What am I doing wrong?? Thanks for the help.

#include <GuiComboBox.au3>
#include <GuiComboBoxEx.au3>
#include <GuiEdit.au3>
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <TabConstants.au3>
Opt("GUIOnEventMode", 1)
$formLink = GUICreate("Link", 801, 571, 192, 124)
$btnStart = GUICtrlCreateButton("Start", 10, 10, 80, 30)
Local $formGlobal, $msg2
GUICtrlSetOnEvent($btnStart, "btnStartClick")
GUISetState(@SW_SHOW)
;
; main loop
;
While 1
    Sleep(100)
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            Exit
    EndSelect
WEnd
Func btnStartClick()
    globalSettingsGUI()
EndFunc   ;==>btnStartClick
;
Func globalSettingsGUI()
    GUISetState(@SW_DISABLE, $formLink)
    $formGlobal = GUICreate("Global Settings", 506, 271, 228, 426)
    $btnGlobalSaveSettings = GUICtrlCreateButton("Save Settings", 372, 222, 125, 33)
    GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
    GUICtrlSetOnEvent(-1, "btnGlobalSaveSettingsClick")
    GUISetState(@SW_SHOW)
    GUISwitch($formGlobal)
    ;
    ; loop
    ;
    While 1
        Sleep(100)
        $msg2 = GUIGetMsg()
        Select
            Case $msg2 = $GUI_EVENT_CLOSE
                MsgBox(0, "test", "test")
                GUISetState(@SW_DISABLE, $formGlobal)
                GUISetState(@SW_ENABLE, $formLink)
                GUISwitch($formLink)
                GUIDelete($formGlobal)
                Return
        EndSelect
    WEnd
EndFunc   ;==>globalSettingsGUI
Func formGlobalClose()
    MsgBox(0, "test", "test")
    GUISetState(@SW_DISABLE, $formGlobal)
    GUISetState(@SW_ENABLE, $formLink)
    GUISwitch($formLink)
    GUIDelete($formGlobal)
EndFunc   ;==>formGlobalClose
Func formGlobalMaximize()

EndFunc   ;==>formGlobalMaximize
Func formGlobalMinimize()

EndFunc   ;==>formGlobalMinimize
Func formGlobalRestore()

EndFunc   ;==>formGlobalRestore
Func btnGlobalSaveSettingsClick()
    MsgBox(0, "test", "test")
    GUISetState(@SW_DISABLE, $formGlobal)
    GUISetState(@SW_ENABLE, $formLink)
    GUISwitch($formLink)
    GUIDelete($formGlobal)
EndFunc   ;==>btnGlobalSaveSettingsClick
Edited by FrozenTeeth
Link to comment
Share on other sites

Several things...

You're mixing up onevent and getmsg methods. Stick to onevent, add a sleep to the main loop and set the exit event with guisetonevent.

Your second gui is created in a function. From within a function called by onevent you can not call another event function. Either create the second gui also (hidden) in the main part and just unhide it in the function, or switch to guimsg method in the function and back to onevent before returning to the main loop.

Link to comment
Share on other sites

Dont mix oneventmode and message loop modes

#include <GuiComboBox.au3>
#include <GuiComboBoxEx.au3>
#include <GuiEdit.au3>
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <TabConstants.au3>

HotKeySet("{ESC}","_Exit")

Func _Exit()
    Exit
EndFunc


Opt("GUIOnEventMode", 1)
$formLink = GUICreate("Link", 801, 571, 192, 124)
$btnStart = GUICtrlCreateButton("Start", 10, 10, 80, 30)
Local $formGlobal, $msg2
GUICtrlSetOnEvent($btnStart, "btnStartClick")
GUISetState(@SW_SHOW)

GUISetOnEvent($GUI_EVENT_CLOSE,"_closeMainWindow",$formLink)
Func _closeMainWindow()
    GUIDelete($formLink)
    Exit
EndFunc

;
; main loop
;
While 1
    Sleep(100)
;~     $msg = GUIGetMsg()
;~     Select
;~         Case $msg = $GUI_EVENT_CLOSE
;~             Exit
;~     EndSelect
WEnd
Func btnStartClick()
    globalSettingsGUI()
EndFunc   ;==>btnStartClick
;
Func globalSettingsGUI()
    GUISetState(@SW_DISABLE, $formLink)
    $formGlobal = GUICreate("Global Settings", 506, 271, 228, 426)
    $btnGlobalSaveSettings = GUICtrlCreateButton("Save Settings", 372, 222, 125, 33)
    GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
    GUICtrlSetOnEvent(-1, "btnGlobalSaveSettingsClick")
    GUISetState(@SW_SHOW)
;~     GUISwitch($formGlobal)
    ;
    ; loop
    ;
;~     While 1
;~         Sleep(100)
;~         $msg2 = GUIGetMsg()
;~         Select
;~             Case $msg2 = $GUI_EVENT_CLOSE
;~                 MsgBox(0, "test", "test")
;~                 GUISetState(@SW_DISABLE, $formGlobal)
;~                 GUISetState(@SW_ENABLE, $formLink)
;~                 GUISwitch($formLink)
;~                 GUIDelete($formGlobal)
;~                 Return
;~         EndSelect
;~     WEnd
EndFunc   ;==>globalSettingsGUI
Func formGlobalClose()
    MsgBox(0, "test", "test")
    GUISetState(@SW_DISABLE, $formGlobal)
    GUISetState(@SW_ENABLE, $formLink)
    GUISwitch($formLink)
    GUIDelete($formGlobal)
EndFunc   ;==>formGlobalClose
Func formGlobalMaximize()

EndFunc   ;==>formGlobalMaximize
Func formGlobalMinimize()

EndFunc   ;==>formGlobalMinimize
Func formGlobalRestore()

EndFunc   ;==>formGlobalRestore
Func btnGlobalSaveSettingsClick()
    MsgBox(0, "test", "test")
    GUISetState(@SW_DISABLE, $formGlobal)
    GUISetState(@SW_ENABLE, $formLink)
    GUISwitch($formLink)
    GUIDelete($formGlobal)
EndFunc   ;==>btnGlobalSaveSettingsClick
GDIPlusDispose - A modified version of GDIPlus that auto disposes of its own objects before shutdown of the Dll using the same function Syntax as the original.EzMySql UDF - Use MySql Databases with autoit with syntax similar to SQLite UDF.
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...