Jump to content

GUI Window Problem


Recommended Posts

So I'm working on a simple menu chooser with three buttons. Two of the buttons (XP and Vista7) hide the window and continue on. A third button is supposed to hide the window, and load a new window with two buttons (Go back and Exit). I want Go back to re-open the original window with three buttons, and I want exit to close the program.

My problem is that the two buttons (Go back and Exit) do not work correctly.

$FormChooseOS = GUICreate("Choose the Operating System", 500, 350, 334, 140, $DS_MODALFRAME)
$Label1 = GUICtrlCreateLabel("Choose the Operating System", 35, 24, 430, 40)
GUICtrlSetFont($Label1, 24, 400, 0, "MS Sans Serif")
$XP = GUICtrlCreateButton("Windows XP/XPe/Embedded Standard", 150, 88, 200, 65, 0)
GUICtrlSetOnEvent($XP, "XPClick")
$Vista7 = GUICtrlCreateButton("Windows Vista/7/Embedded 7", 150, 160, 200, 65, 0)
GUICtrlSetOnEvent($Vista7, "Vista7Click")
$Other = GUICtrlCreateButton("Other", 150, 232, 200, 65, 0)
GUICtrlSetOnEvent($Other, "OtherClick")
GUISetState(@SW_SHOW)
While 1
    Sleep(100)
WEnd
Func OtherClick()
    Opt("GUIOnEventMode", 1)
    GUISetState(@SW_HIDE,"Choose the Operating System")
    $FormUnsupported = GUICreate("Unsupported", 283, 130, 192, 124, $DS_MODALFRAME)
    $TextBox = GUICtrlCreateLabel("Sorry, we do not support any other operating systems.", 16, 16, 256, 17)
    $GoBack = GUICtrlCreateButton("Go Back", 16, 48, 105, 65, 0)
    GUICtrlSetOnEvent($GoBack, "GoBackClick")
    $Exit = GUICtrlCreateButton("Exit", 160, 48, 105, 65, 0)
    GUICtrlSetOnEvent($Exit, "ExitClick")
    GUISetState(@SW_SHOW)
    While 1
        Sleep(100)
    WEnd
EndFunc
Func ExitClick()
    MsgBox(0,"","")
    Exit
EndFunc
Func GoBackClick()
    GUISetState(@SW_HIDE, "Unsupported")
    GUISetState(@SW_SHOW, "Choose the Operating System")
    MsgBox(0,"","")
EndFunc
Func Vista7Click()
$OSVersion = "XP"
GUISetState(@SW_HIDE)
Continue()
EndFunc
Func XPClick()
$OSVersion = "XP"
GUISetState(@SW_HIDE)
Analyze()
EndFunc

I originally had the functions 'ExitClick()' and 'GoBackClick()' inside the 'OtherClick() function, but I was getting errors and it wouldn't load.

Anyone have any advice on how I could get this to work?

Edited by cvocvo
Link to comment
Share on other sites

  • Moderators

cvocvo,

Just the one problems with the code which stopped it working as you wished:

You had an unnecessary loop in function OtherClick(). This infinite loop blocked the whole script as there was no way to get out of it! Remember you only need ONE loop in an OnEvent mode script. :P

A couple of other points:

- 1. You need to delare the handle of the "Unsupported" window as a Global variable. You had it declared within function OtherClick() and so it was Local in scope. This means that function GoBackClick() would not be able to access it unless we declare it as Global initially.

- 2. You need to delete the "Unsupported" GUI when you go back - if you press the "Other" button you would create another GUI and waste resources. :party:

Here is a modified version of your script:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Opt("GUIOnEventMode", 1)

$FormUnsupported = 9999

$FormChooseOS = GUICreate("Choose the Operating System", 500, 350, 334, 140, $DS_MODALFRAME)
$Label1 = GUICtrlCreateLabel($FormChooseOS, 35, 24, 430, 40)
GUICtrlSetFont($Label1, 24, 400, 0, "MS Sans Serif")
$XP = GUICtrlCreateButton("Windows XP/XPe/Embedded Standard", 150, 88, 200, 65, 0)
GUICtrlSetOnEvent($XP, "XPClick")
$Vista7 = GUICtrlCreateButton("Windows Vista/7/Embedded 7", 150, 160, 200, 65, 0)
GUICtrlSetOnEvent($Vista7, "Vista7Click")
$Other = GUICtrlCreateButton("Other", 150, 232, 200, 65, 0)
GUICtrlSetOnEvent($Other, "OtherClick")
GUISetState(@SW_SHOW)

While 1
    Sleep(10) ; 10 is enough
WEnd

Func OtherClick()
    GUISetState(@SW_HIDE, $FormChooseOS)
    $FormUnsupported = GUICreate("Unsupported", 283, 130, 192, 124, $DS_MODALFRAME)
    $TextBox = GUICtrlCreateLabel("Sorry, we do not support any other operating systems.", 16, 16, 256, 17)
    $GoBack = GUICtrlCreateButton("Go Back", 16, 48, 105, 65, 0)
    GUICtrlSetOnEvent($GoBack, "GoBackClick")
    $Exit = GUICtrlCreateButton("Exit", 160, 48, 105, 65, 0)
    GUICtrlSetOnEvent($Exit, "ExitClick")
    GUISetState(@SW_SHOW)
EndFunc   ;==>OtherClick

Func ExitClick()
    MsgBox(0, "", "Exiting")
    Exit
EndFunc   ;==>ExitClick

Func GoBackClick()
    GUIDelete($FormUnsupported)
    GUISetState(@SW_SHOW, $FormChooseOS)
    MsgBox(0, "", "Gone Back")
EndFunc   ;==>GoBackClick

Func Vista7Click()
    $OSVersion = "XP"
    GUISetState(@SW_HIDE)
    ;Continue()
EndFunc   ;==>Vista7Click

Func XPClick()
    $OSVersion = "XP"
    GUISetState(@SW_HIDE)
    ;Analyze()
EndFunc   ;==>XPClick

I hope that is all clear. :mellow:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

cvocvo,

My pleasure - that is what we are here for! :mellow:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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