Jump to content

Calling One GUI from Another


Recommended Posts

I'm currently working on my first "Big-Boy" script. It has a GUI, user choices, and a certain amount of inbuilt logic. All the different components work separately, but fail when together. Rather than bore you with my embarrassingly bad script, I've put together a proof of concept script that demonstrates the problem I'm having. I'm sure its a simple newbie mistake, but its bugging the heck out of me.

Ostensibly, what I'm doing is creating a GUI with GUICreate, and setting the function of a button on that GUI to destroy the GUI, and create another. The first GUI works fine, and clicking the button destroys and creates the second GUI. However, none of the buttons on the second GUI (including close) do anything. In the example below, clicking the Exit button should exit the script, but nothing happens.

Here is the code of my test script;

#include <GUIConstants.au3>

opt("GUIOnEventMode", 1)

;;;;;;;;;;;;;
; First GUI ;
;;;;;;;;;;;;;

$form_first = GUICreate("First", 127, 80, 381, 325)
GUISetOnEvent($GUI_EVENT_CLOSE, "form_firstClose")
GUISetOnEvent($GUI_EVENT_MINIMIZE, "form_firstMinimize")
GUISetOnEvent($GUI_EVENT_MAXIMIZE, "form_firstMaximize")
GUISetOnEvent($GUI_EVENT_RESTORE, "form_firstRestore")
$button_continue = GUICtrlCreateButton("Continue", 8, 8, 105, 57, 0)
GUICtrlSetOnEvent(-1, "button_continueClick")
GUISetState(@SW_SHOW)

While 1
    Sleep(100)
WEnd

Func button_continueClick()
    
    GUIDelete()
    _secondform ()
    Exit
    
EndFunc   ;==>button_continueClick


Func form_firstClose()
    
    Exit
    
EndFunc   ;==>form_firstClose


Func form_firstMaximize()
    
EndFunc   ;==>form_firstMaximize


Func form_firstMinimize()
    
EndFunc   ;==>form_firstMinimize


Func form_firstRestore()
    
EndFunc   ;==>form_firstRestore

;;;;;;;;;;;;;;
; Second GUI ;
;;;;;;;;;;;;;;

Func _secondform()

$form_second = GUICreate("Second", 127, 80, 381, 325)
GUISetOnEvent($GUI_EVENT_CLOSE, "form_secondClose")
GUISetOnEvent($GUI_EVENT_MINIMIZE, "form_secondMinimize")
GUISetOnEvent($GUI_EVENT_MAXIMIZE, "form_secondMaximize")
GUISetOnEvent($GUI_EVENT_RESTORE, "form_secondRestore")
$button_exit = GUICtrlCreateButton("Exit", 8, 8, 105, 57, 0)
GUICtrlSetOnEvent(-1, "button_exitClick")
GUISetState(@SW_SHOW)

While 1
    Sleep(100)
WEnd

EndFunc

Func button_exitClick()
    
    Exit
    
EndFunc   ;==>button_exitClick


Func form_secondClose()
    
    Exit
    
EndFunc   ;==>form_secondClose


Func form_secondMaximize()
    
EndFunc   ;==>form_secondMaximize


Func form_secondMinimize()
    
EndFunc   ;==>form_secondMinimize


Func form_secondRestore()
    
EndFunc   ;==>form_secondRestore
Link to comment
Share on other sites

Your second

While 1

Sleep(100)

WEnd

Is confusing me... you already got one at the top.. try removing the second see whats happening

It's working for me with out the second loop. Edited by sheckandar
Live and Learn, 'cause Knowledge is Super Power.
Link to comment
Share on other sites

It's working for me with out the second loop.

Which is weird, because if I take out the second loop;

While 1
    Sleep(100)
WEnd

When I click on the continue button on the first GUI, I see the second GUI flash up for a split second, then goes away and the script ends. That is what I would have expected because the loop, by my understanding, is what keeps the GUI active and ready to accept input.

Thanks for all your help!

Link to comment
Share on other sites

Have you looked at doing it in Messsage Loop mode rather than OnEvent mode? It is far easier juggling multiple GUI's with Message Loop mode.

Using the GuiSwitch command makes your life much simpler. ;)

Genius, thank you Lord Maim! You hit the nail on the head. Using Koda FormDesigner, and the Help File entry for GUISwitch as my basis, I came up with this script to handle my example situation. Before I convert my real script to this form, does it appear to be the best way to do it, or should I change anything?

#include <GUIConstants.au3>

$form_first = GUICreate("First", 225, 171, 193, 115)
$button_firstcontinue = GUICtrlCreateButton("Continue", 64, 32, 97, 73, 0)
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $button_firstcontinue ()
            
            GUIDelete()
            $form_second = GUICreate("Second", 245, 160, 373, 414)
            $button_secondexit = GUICtrlCreateButton("Exit", 48, 32, 137, 81, 0)
            GUISetState(@SW_SHOW)
            
            While 1
                $nMsg = GUIGetMsg()
                Switch $nMsg
                    Case $GUI_EVENT_CLOSE
                        Exit
                        
                    Case $button_secondexit ()
                        Exit
                        
                EndSwitch
            WEnd
            
    EndSwitch
WEnd
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...