Jump to content
Sign in to follow this  
neuronyx

GUIOnEventMode Fails on Second Window

Recommended Posts

Hi All- I am trying my hand at a basic GUI program however when I try and run the program I can't click any buttons on my second window which calls the function (SMARTTEST). I am hoping to keep my functions in separate AU3 files since they will get pretty lengthy. Could someone point out where I am going wrong? Thanks!

Main GUI:

#include <GUIConstants.au3>
#include <SMARTIPTools.au3>
#include <SMARTTEST.au3>
#RequireAdmin

; GUI Visual Options
;Opt("GUIOnEventMode", 1) ; Polls GUI for button press events
;Opt("GUICoordMode", 2) ; Defines GUI Alignment 2= relative to current cell positioning

MainGUI()

Func MainGUI()
    Select
    Case @OSVersion = "WIN_7" Or @OSVersion = "WIN_XP" Or @OSVersion = "WIN_8"
        Opt("GUIOnEventMode", 1) ; Polls GUI for button press events
        Opt("GUICoordMode", 2) ; Defines GUI Alignment 2= relative to current cell positioning

        GUICreate("SMART", 580, 720, 600)
        $sFont = "Arial"
        GUISetFont(20, 400, 0, $sFont)
        GUICtrlCreateLabel("Welcome to SMART", 200, 10)
        GUISetBkColor(0xB29B7F)
        GUISetFont(12, 400, 0, $sFont)

        GUICtrlCreateButton ("Network and IP Tools", -250, 5, 250)
        GUICtrlSetOnEvent(-1, "SMARTIP")

        GUICtrlCreateButton ("TEST-TEST", -250, 5, 250)
        GUICtrlSetOnEvent(-1, "SMARTTEST")

        GUICtrlCreateButton ("EXIT", -250, 5, 250)
        GUICtrlSetOnEvent(-1, "ExitPressed")

        GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents")
        GUISetState(@SW_SHOW)

    Case Else
        MsgBox(48, "OS Check Failed", "This program works with Windows XP, 7 and 8. Please consult your Administrator for assistance.")
        Exit
    EndSelect
EndFunc

; Idle and wait for choice
While 1
    Sleep(1000)
Wend

Func IPBackPressed()
    GUIDelete($GUIIPTools)
EndFunc

Func ExitPressed()
    Exit
EndFunc


Func SpecialEvents()
    Select
    Case @GUI_CTRLID = $GUI_EVENT_CLOSE
    Exit

    Case @GUI_CTRLID = $GUI_EVENT_MINIMIZE
    MsgBox(0, "Window Minimized", "ID=" & @GUI_CTRLID & " WinHandle=" & @GUI_WINHANDLE)

    Case @GUI_CTRLID = $GUI_EVENT_RESTORE
    MsgBox(0, "Window Restored", "ID=" & @GUI_CTRLID & " WinHandle=" & @GUI_WINHANDLE)

    EndSelect
EndFunc

Child GUI:

Func SMARTTEST()
        Opt("GUIOnEventMode", 1) ; Polls GUI for button press events
        Opt("GUICoordMode", 2) ; Defines GUI Alignment 2= relative to current cell positioning

        GUICreate("SMART", 580, 720, 600)
        $sFont = "Arial"
        GUISetFont(20, 400, 0, $sFont)
        GUICtrlCreateLabel("Welcome to SMART TEST PAGE", 200, 10)
        GUISetBkColor(0xB29B7F)
        GUISetFont(12, 400, 0, $sFont)

        GUICtrlCreateButton ("EXIT", -250, 5, 250)
        GUICtrlSetOnEvent(-1, "ExitPressed")

        GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents")
        GUISetState(@SW_SHOW)

    ; Idle and wait for choice
    While 1
        Sleep(1000)
    Wend

EndFunc

Share this post


Link to post
Share on other sites

Hi, neuronyx, have you read through the Wiki article on managing multiple GUIs? It has good suggestions for what you are trying to do:

http://www.autoitscript.com/wiki/Managing_Multiple_GUIs


"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Share this post


Link to post
Share on other sites

Wow, my code was a mess. Thanks much, I restructured it using that How-To and got it working! My only issue now is that I have a problem with one of my buttons. This works great except for the fact that when I click my "Back to Main Menu" button my main GUI is still disabled, like the function that calls the child window is still running. Focusing on just the While sections:

Here is my main GUI:

While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
                GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents")
Case $hButton1
                GUISetState(@SW_DISABLE, $hGUI1) ; Disable the first GUI
SMARTIP()
GUISetState(@SW_ENABLE, $hGUI1) ; Re-enable the first GUI
Case $hButton2
                GUISetState(@SW_DISABLE, $hGUI1)
                GUISetState(@SW_ENABLE, $hGUI1)
Case $hButton3
ExitPressed()
EndSwitch
     WEnd

My Child GUI is named $iptGUI and contains the function SMARTIP() which you can see is called on Button 1 above. In the SMARTIP() function I have the following While statement:

Case $hButton6
GUISetState(@SW_DISABLE, $iptGUI)
                 IPBackPressed()
                 ;GUISetState(@SW_ENABLE, $iptGUI)
 
 
Finally the IPBackPressed() button calls this function:
Func IPBackPressed()
GUIDelete($iptGUI)
EndFunc

 

So $iptGUI is deleted but my main GUI is still dead and I can't click anything. Any ideas?

Edited by neuronyx

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...