Jump to content

Multiple GUI window problems


Recommended Posts

I am trying to write a program that upon the initial window, will wait 10 seconds for the user to press a button, and auto-start if nothing is pressed.

(the intent is to give the user a chance to click SETUP)

I can get each GUI working fine individually, but try and get them working in the same script (same .au3 or includes) and the 2nd window doesn't seem to respond to any sort of "GUICtrlSetOnEvent" calls.

I've chopped the program way down to give you a simple example that while the first window opens/closes fine, the setup window is basically not going to close.

(also none of the buttons in the setup window respond if they are set to "GUICtrlSetOnEvent" as well. (radios work, but not a button, like SAVE which calls an external function)

Any help would be greatly appreciated!

Thanks,

Van Renier

Opt ( "GUICloseOnESC", 1)
Opt ( "GUICoordMode", 1)
Opt ( "GUIOnEventMode", 1)
Opt ( "GUIResizeMode", 0)
#include <GUIConstants.au3>
GLOBAL $SetupProgram
GLOBAL $RunOrSetupGUI
_RunOrSetupGUI()

Func _RunOrSetupGUI()
        $RunOrSetupGUI = GUICreate ( "Main Window", 300, 100 )
        $GUIButtonSetupProgram = GUICtrlCreateButton ( "Setup", 260, 85, 40, 15 )  
        GUICtrlSetOnEvent(-1, "_SetupProgramButton")
        $GUIEventClose = GUISetOnEvent ($GUI_EVENT_CLOSE, "_GUI_Closed_RunOrSetupGUI")
        GUISetState(@SW_SHOW)
      ; ---------------------------------------
        For $i = 10 to 1 step -1
                Sleep ( 1000 )
           Next
      ; ---------------------------------------
        GUIDelete ()
    EndFunc

Func _GUI_Closed_RunOrSetupGUI()
        GUIDelete ()
        Exit
    EndFunc
Func _SetupProgramButton()
        GUISetState(@SW_HIDE)
        GUIDelete ()
        _SetupProgram()
    EndFunc
;###################################################
;###################################################
Func _SetupProgram()
        $SetupProgram = GUICreate ( "SETUP window", 640, 480 )
        GUISetOnEvent($GUI_EVENT_CLOSE, "_GUIClosedSetupProgram")
        GUISetState(@SW_SHOW)
        While 1
                Sleep(20)
            Wend
    EndFunc
Func _GUIClosedSetupProgram()
        GUIDelete ()
        Exit
    EndFunc
Edited by van_renier
Link to comment
Share on other sites

Store the return values from GUICreate() and use that return value explicitly in all calls to GUISetState() or GUIDelete(). I won't go into my opinion on the problem, but suffice to say, AutoIt is attempting to keep track of which GUI it thinks you want the next command to operate on and in this case, its wrong. If you store the HWND (returned by GUICreate()) and use it explicitly, you shouldn't have any problems.

Link to comment
Share on other sites

Thanks for the suggestion, Valik, but I'd already tried that.

ie.

GUISetState( $RunOrSetupGUI )

GUIDelete($RunOrSetupGUI )

Since it did not work, I reverted back to the 'default' way, and choose to display it here in the forums.

Also, The documentation states that the GUISetState() and GUIDelete() functions apply to the last defined GUI. Considering I destory/delete the first before starting the second, there should be no problems.

(Remember, I have chopped this program down quite a bit to fit and be reasonably readable. I have controls and buttons on the second window, just they mostly don't do anything (if they have the GUISetOnEvent options in place. Just the fact that they are being created AND manipulated (other tests that had worked) indicate they are going to the correct windows. And since I've destroyed/deleted the '1st' GUI prior to creating the 2nd, the 1st should not be getting referenced anymore.)

I may be wrong, but I suspect this is more a problem with the GUISetOnEvent() functions.

Store the return values from GUICreate() and use that return value explicitly in all calls to GUISetState() or GUIDelete().  I won't go into my opinion on the problem, but suffice to say, AutoIt is attempting to keep track of which GUI it thinks you want the next command to operate on and in this case, its wrong.  If you store the HWND (returned by GUICreate()) and use it explicitly, you shouldn't have any problems.

<{POST_SNAPBACK}>

Link to comment
Share on other sites

I modified the program to include Valik's suggestions, and it still does not work.

Any help would be greatly appreciated!

Thanks,

Van Renier

Opt ( "GUICloseOnESC", 1)
Opt ( "GUICoordMode", 1)
Opt ( "GUIOnEventMode", 1)
Opt ( "GUIResizeMode", 0)
#include <GUIConstants.au3>
GLOBAL $SetupProgram
GLOBAL $RunOrSetupGUI
_RunOrSetupGUI()

Func _RunOrSetupGUI()
        $RunOrSetupGUI = GUICreate ( "Main window", 300, 100 )
        $GUIButtonSetupProgram = GUICtrlCreateButton ( "Setup", 260, 85, 40, 15 )  
        GUICtrlSetOnEvent(-1, "_SetupProgramButton")
        $GUIEventClose = GUISetOnEvent ($GUI_EVENT_CLOSE, "_GUI_Closed_RunOrSetupGUI")
        GUISetState(@SW_SHOW, $RunOrSetupGUI )
      ; ---------------------------------------
        For $i = 10 to 1 step -1
                Sleep ( 1000 )
           Next
      ; ---------------------------------------
        GUIDelete ()
    EndFunc

Func _GUI_Closed_RunOrSetupGUI()
        GUIDelete ($RunOrSetupGUI )
        Exit
    EndFunc
Func _SetupProgramButton()
        GUIDelete ($RunOrSetupGUI )
        _SetupProgram()
    EndFunc
;###################################################
;###################################################
Func _SetupProgram()
        $SetupProgram = GUICreate ( "SETUP window", 640, 480 )
        GUISetOnEvent($GUI_EVENT_CLOSE, "_GUIClosedSetupProgram")
        GUISetState(@SW_SHOW, $SetupProgram )
        While 1
                Sleep(20)
            Wend
    EndFunc
Func _GUIClosedSetupProgram()
        GUIDelete ($SetupProgram)
        Exit
    EndFunc

<{POST_SNAPBACK}>

Link to comment
Share on other sites

Thanks for the suggestion, Valik, but I'd already tried that.

ie.

    GUISetState( $RunOrSetupGUI )

    GUIDelete($RunOrSetupGUI )

Since it did not work, I reverted back to the 'default' way, and choose to display it here in the forums.

Also, The documentation states that the GUISetState() and GUIDelete() functions apply to the last defined GUI. Considering I destory/delete the first before starting the second, there should be no problems.

(Remember, I have chopped this program down quite a bit to fit and be reasonably readable. I have controls and buttons on the second window, just they mostly don't do anything (if they have the GUISetOnEvent options in place. Just the fact that they are being created AND manipulated (other tests  that had worked) indicate they are going to the correct windows. And since I've destroyed/deleted the '1st' GUI prior to creating the 2nd, the 1st should not be getting referenced anymore.)

I may be wrong, but I suspect this is more a problem with the GUISetOnEvent() functions.

<{POST_SNAPBACK}>

I think you get a problem because to have 2 while loops.

Autoit is not multi threaded as such.

I modified line with ;;;

and the code is working NO problem in GUISetOnEvent, at least with what you intend to do :)

Opt ( "GUICloseOnESC", 1)
Opt ( "GUICoordMode", 1)
Opt ( "GUIOnEventMode", 1)
Opt ( "GUIResizeMode", 0)
#include <GUIConstants.au3>
;GLOBAL $SetupProgram
;GLOBAL $RunOrSetupGUI
_RunOrSetupGUI()

        While 1             ;;;
                Sleep(20)   ;;;
           Wend             ;;;

Func _RunOrSetupGUI()
        $RunOrSetupGUI = GUICreate ( "Auto-Copy for DVD Shrink", 300, 100 )
        $GUIButtonSetupProgram = GUICtrlCreateButton ( "Setup", 260, 85, 40, 15 )  
        GUICtrlSetOnEvent(-1, "_SetupProgramButton")
        $GUIEventClose = GUISetOnEvent ($GUI_EVENT_CLOSE, "_GUI_Closed_RunOrSetupGUI")
                                                                GUISetState(@SW_SHOW)
      ; ---------------------------------------
        For $i = 10 to 1 step -1
                $AutoStartText = "Auto-Starting in " & $i & "...."
;;;             GUICtrlSetData ($GUILabelAutoStartText, $AutoStartText )
                Sleep ( 1000 )
           Next
      ; ---------------------------------------
;;;     GUIDelete ()
    EndFunc

Func _GUI_Closed_RunOrSetupGUI()
        GUIDelete ()
        Exit
    EndFunc
Func _SetupProgramButton()
        GUISetState(@SW_HIDE)
        GUIDelete ()
        _SetupProgram()
    EndFunc
;###################################################
;###################################################
Func _SetupProgram()
        $SetupProgram = GUICreate ( "SETUP window", 640, 480 )
        GUISetOnEvent($GUI_EVENT_CLOSE, "_GUIClosedSetupProgram")
        GUISetState(@SW_SHOW)
;;;     While 1
;;;             Sleep(20)
;;;        Wend
    EndFunc
Func _GUIClosedSetupProgram()
        GUIDelete ()
        Exit
    EndFunc
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...