Jump to content

GuiCtrlGetState()


Recommended Posts

I'm trying to create something similar to an installer, but with AutoIt. When the Next button is clicked, it should create one of two new guis (depending on which radio has been selected). When back is clicked from either of these two guis it should return to the original gui. I'm certain there is a minor mistake as I make them quite often, but any help would be much appreciated.

EDIT: Code fixed, below is a working example for anyone that might find it useful for something...

#include <GUIConstants.au3>

Global $First, $Second, $Label, $Next, $Back, $Exit

;Current window active
;1 = MainWindow
;2 = FirstWindow
;3 = SecondWindow
;================
$ActiveWindow = 1
;================

;Load the Main Window
;================
LoadWindow(1)
;================

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $Next
            Select
                Case $ActiveWindow = 1
                    If GUICtrlRead($First) = $GUI_CHECKED Then
                        LoadWindow(2)
                    ElseIf GUICtrlRead($Second) = $GUI_CHECKED Then
                        LoadWindow(3)
                    EndIf
            EndSelect
        Case $Back
            Select
                Case $ActiveWindow = 2
                    LoadWindow(1)
                Case $ActiveWindow = 3
                    LoadWindow(1)
            EndSelect
        Case $Exit
            Close()
        Case $GUI_EVENT_CLOSE
            Close()
    EndSwitch
WEnd

Func LoadWindow($WindowToLoad)
    Switch $WindowToLoad
        Case 1
            LoadMain()
        Case 2
            LoadFirst()
        Case 3
            LoadSecond()
    EndSwitch
EndFunc

Func LoadMain()
    GUIDelete()
    GUICreate("TESTING", 473, 248)
    $First = GUICtrlCreateRadio("First", 104, 120, 161, 17)
    GUICtrlSetState(-1, $GUI_CHECKED)
    $Second = GUICtrlCreateRadio("Second", 104, 152, 89, 17)
    $Next = GUICtrlCreateButton("Next >>", 352, 208, 97, 25, 0)
    $Exit = GUICtrlCreateButton("Exit", 24, 208, 97, 25, 0)
    $ActiveWindow = 1
    GUISetState()
EndFunc

Func LoadFirst()
    GUIDelete()
    GUICreate("TESTING", 473, 248)
    $Label = GUICtrlCreateLabel("THIS IS FIRST WINDOW!", 104, 80)
    $Back = GUICtrlCreateButton("<< Back", 232, 208, 97, 25, 0)
    $Exit = GUICtrlCreateButton("Exit", 24, 208, 97, 25, 0)
    $ActiveWindow = 2
    GUISetState()
EndFunc

Func LoadSecond()
    GUIDelete()
    GUICreate("TESTING", 473, 248)
    $Label = GUICtrlCreateLabel("THIS IS SECOND WINDOW!", 104, 80)
    $Back = GUICtrlCreateButton("<< Back", 232, 208, 97, 25, 0)
    $Exit = GUICtrlCreateButton("Exit", 24, 208, 97, 25, 0)
    $ActiveWindow = 3
    GUISetState()
EndFunc

Func Close()
    Exit
EndFunc
Edited by dandymcgee

- Dan [Website]

Link to comment
Share on other sites

Thanks Zenda!

This is what I was looking for:

Case $ActiveWindow = 1
    If GUICtrlRead($First) = $GUI_CHECKED Then
        LoadWindow(2)
    ElseIf GUICtrlRead($Second) = $GUI_CHECKED Then
        LoadWindow(3)
    EndIf

I was trying to use GuiCtrlGetState rather than GuiCtrlRead... Thanks for you help. I knew it was a dumb mistake :)

Edited by dandymcgee

- Dan [Website]

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...