Jump to content
Sign in to follow this  
RegularGuy

How do I create a wizard-like GUI

Recommended Posts

RegularGuy

I have been trying to figure out the best way (practice) of preforming this task. I am still new to this all (auto it as well as programming) and I need some help. I'm creating a wizard that prompts the user for several peices of information and then returns an answer.

I have included this sample code of the method that I've begun using but I would like some feedback as to what I could do differently, because I know there is a better way that what I have here.

Global $GuiHeight = 400
Global $GuiWidth = 350
Global $ButtonWidth1 = 100
GLobal $NavButton = 75
Global $Centered = $GuiWidth/2-$ButtonWidth1/2
Global $NavCentered = $GuiWidth/2-$NavButton/2
GLobal $Left = 10
Global $Bottom = $GuiHeight-25-$Left
Global $Right = $GuiWidth-$NavButton-$Left

_Inception()

Func _Inception()
    Local $GuiDescription = "You're getting sleepy"
    GUICreate("",$GuiWidth,$GuiHeight)
    GUICtrlCreateLabel($GuiDescription,$Left,10)
    Local $cancel = GUICtrlCreateButton("Cancel", $Left, $Bottom,$NavButton)
    local $next = GUICtrlCreateButton("Next", $Right, $Bottom, $NavButton)
    GUICtrlCreateLabel("Level 1",$GuiWidth/2,$GuiHeight/2)

    GUISetState()

While 1
  Local $msg = GUIGetMsg()
  Switch $msg

     Case -3
        Exit

     Case $cancel
        Exit

     Case $next
        GUIDelete()
        _Inception2()

    EndSwitch
WEnd

EndFunc

Func _Inception2()
Local $GuiDescription = "Follow the White Rabbit."
GUICreate("",$GuiWidth,$GuiHeight)
GUICtrlCreateLabel($GuiDescription,$Left,10)
Local $cancel = GUICtrlCreateButton("Cancel", $Left, $Bottom,$NavButton)
Local $back = GUICtrlCreateButton("Back", $NavCentered,$Bottom,$NavButton)
local $next = GUICtrlCreateButton("Next", $Right, $Bottom, $NavButton)
GUICtrlCreateLabel("Level 2",$GuiWidth/2,$GuiHeight/2)
local $Button1 = Guictrlcreatebutton("Test 1",$Left,40,100)
local $Button2 = Guictrlcreatebutton("Test 2",$Centered,40,100)
local $Button3 = Guictrlcreatebutton("Test 3",$Right-25,40,100)

GUISetState()

While 1
  Local $msg = GUIGetMsg()
  Switch $msg

     Case -3
        Exit

     Case $cancel
        Exit

     Case $back
        GUIDelete()
        _Inception()

     Case $next
        GUIDelete()
        _Inception3()

  EndSwitch
WEnd

EndFunc

Func _Inception3()
Local $GuiDescription = "You are Fast asleep"
GUICreate("",$GuiWidth,$GuiHeight)
GUICtrlCreateLabel($GuiDescription,$Left,10)
Local $cancel = GUICtrlCreateButton("Cancel", $Left, $Bottom,$NavButton)
Local $back = GUICtrlCreateButton("Back", $NavCentered,$Bottom,$NavButton)
GUICtrlCreateLabel("Level 3",$GuiWidth/2,$GuiHeight/2)
local $Button1 = Guictrlcreatebutton("Test 1",$Left,100,100)
local $Button2 = Guictrlcreatebutton("Test 2",$Centered,70,100)
local $Button3 = Guictrlcreatebutton("Test 3",$Right-25,100,100)

GUISetState()

While 1
  Local $msg = GUIGetMsg()
  Switch $msg

     Case -3
         Exit

     Case $cancel
          Exit

     Case $back
        GUIDelete()
        _Inception2()

    EndSwitch
WEnd

EndFunc

Again, I know there is a better way.

Ideally, I liked what Valuater did in his Autoit 1-2-3 program where there was one window that changed as you hit next. I just don't know how to create something like that or, what I should even be looking for in order to study how to create that.

Thank you in advance!

EDIT> Edited code for clarity

Edited by RegularGuy

Share this post


Link to post
Share on other sites
ProgAndy

What about something like this?

#include<WindowsConstants.au3>
Opt("GUIOnEventMode", 1)

Global $hStepGUIS[3]

$hGUI = GUICreate("MainGUI", 400, 400)
GUISetOnEvent(-3, "_Main_Exit")

$hStepGUIS[0] = GUICreate("Step1", 400, 370, 0, 0, $WS_CHILD, $WS_EX_CONTROLPARENT, $hGUI)
GUICtrlCreateButton("&Next", 10, 10, 100, 100)
GUICtrlSetOnEvent(-1, "Step1_Next")


$hStepGUIS[1] = GUICreate("Step2", 400, 370, 0, 0, $WS_CHILD, $WS_EX_CONTROLPARENT, $hGUI)
GUICtrlCreateButton("&Next", 200, 10, 100, 100)
GUICtrlSetOnEvent(-1, "Step2_Next")

$hStepGUIS[2] = GUICreate("Step3", 400, 370, 0, 0, $WS_CHILD, $WS_EX_CONTROLPARENT, $hGUI)
GUICtrlCreateButton("&Back To Start", 200, 200, 100, 100)
GUICtrlSetOnEvent(-1, "Step3_Next")


SwitchToStep(0)
GUISetState(@SW_SHOW, $hGUI)

While 1
    Sleep(100)
WEnd


Func Step1_Next()
    MsgBox(0, "", "Step1 Finished")
    SwitchToStep(1)
EndFunc

Func Step2_Next()
    MsgBox(0, "", "Step 2 stopped")
    SwitchToStep(2)
EndFunc

Func Step3_Next()
    MsgBox(0, "", "Go to beginning now")
    SwitchToStep(0)
EndFunc


Func SwitchToStep($step)
    Local $max = UBound($hStepGUIS) - 1
    If $step < 0 Or $step > $max Then Return SetError(1, 0, 0)
    For $i = 0 To $max
        If $i = $step Then
            GUISetState(@SW_SHOW, $hStepGUIS[$i])
            GUISwitch($hStepGUIS[$i])
        Else
            GUISetState(@SW_HIDE, $hStepGUIS[$i])
        EndIf
    Next
    Return 1
EndFunc

Func _Main_Exit()
    Exit
EndFunc

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Share this post


Link to post
Share on other sites
RegularGuy

Thank you for the post, sorry I didn't respond sooner. This is great for moving forward, could you please demonstrate how you would move backwards? ex. move from step 3 back to step two.

Also, would you recommend this for a wizard that has like 50 different GUI's (or at least different input pages)? That is about the amount that I am looking at creating

Share this post


Link to post
Share on other sites
guinness

Are you sure an 'installer like application' is the best route to take? Even Windows doesn't have that amount of pages to install the operating system.


UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Share this post


Link to post
Share on other sites
ProgAndy

Thank you for the post, sorry I didn't respond sooner. This is great for moving forward, could you please demonstrate how you would move backwards? ex. move from step 3 back to step two.

Also, would you recommend this for a wizard that has like 50 different GUI's (or at least different input pages)? That is about the amount that I am looking at creating

I showed only the next-Button, the Back-Button will be implemented the same way. Using SwitchToStep you can jump to any step you want.

For a 50-Page GUI, I would recommend an additional TreeView on the left side where you can manually jump to the pages

PS: An example of what I mean from monodevelop: http://monodevelop.com/@api/deki/files/189/=OptionsDialogReorg.png

Edited by ProgAndy
  • Like 1

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Share this post


Link to post
Share on other sites
acidman

The easiest way is to create a parent Gui and a bunch of child gui's, which in this case you just Hide and show them when moving to the next Child therefore you can just show Them again if you need to Go back The treeview idea was a good one, but instead of all that code Just use

For the "next" Buttons

Guisetstate($ChildGui1, @sw_hide) 
Guisetstate($ChildGui2, @sw_Show)

And for The "Back Buttons"

Guisetstate($ChildGui1, @sw_Show) 
Guisetstate($ChildGui2, @sw_Hide)

This way you don't need to use all that code, plus its easier to understand.

Edited by ac1dm4nner

[u]My dream is to have a dream...[/u]

Share this post


Link to post
Share on other sites
acidman

The method I showed you when using a treeview you could aswell hide the current Child Gui And Jump to the selected Child Gui, best practises are often the ones we had to practice again and again.


[u]My dream is to have a dream...[/u]

Share this post


Link to post
Share on other sites
Melba23

ac1dm4nner,

There is an "Edit" button on your posts - start using it please. :oops:

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites
ProgAndy

The easiest way is to create a parent Gui and a bunch of child gui's, which in this case you just Hide and show them when moving to the next Child therefore you can just show Them again if you need to Go back The treeview idea was a good one, but instead of all that code Just use

For the "next" Buttons

Guisetstate($ChildGui1, @sw_hide)
Guisetstate($ChildGui2, @sw_Show)

And for The "Back Buttons"

Guisetstate($ChildGui1, @sw_Show)
Guisetstate($ChildGui2, @sw_Hide)

This way you don't need to use all that code, plus its easier to understand.

That is exactly what my code is doing. I just manage the child GUIs in an array and use a function to switch between them.

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

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  

  • Similar Content

    • rcmaehl
      By rcmaehl
      A UDF with Extended Functions for Window Management
       
      Notes:
      Fixes WinGetClassList's barbaric returning of a @LF separated string instead of an array.
       
      Potential Uses:
      Automating applications that change their controls' handles/classes on each launch (e.g. half of Cisco's programs)
       
      Functions:
      _WinGetClassList
      _WinGetClassNNList
      _WindowGetHandleList
      _WindowGetHandleListFromPos
       
      Download: 
      WindowEx.zip  (v0.4)
       
      Changelog:
      10/04/2016 (v0.4): _WinGetClassNNList Fixed : Not Returning an Index when using $2D_ARRAY _WinGetClassNNList Fixed : Not Properly returning $aArray[x][1] on Classes with instances > 9 when using $2D_ARRAY 10/03/2016 (v0.3): _WinGetClassList Added : Exactly the same as WinGetClassList but returns a more civilized Array _WinGetClassNNList Added : Returns Classes and their instances in either a 1D or 2D array depending on Flags _WindowGetHandleList Renamed: _WinGetHandleList SCRIPT BREAKING! _WindowGetHandleListFromPos Renamed: _WinGetHandleListFromPos SCRIPT BREAKING! 10/01/2016 (v0.2): WindowsExConstants.au3 Added : Flags in _WindowGetHandleListFromPos _WindowGetHandleListFromPos Removed: ConsoleWrite left in during debug _WindowGetHandleListFromPos Added : Flag for if part of a Control is at $X, $Y return it as well. 10/01/2016 (v0.1): _WindowGetHandleList Added : Retrieves the handles of classes from a window. _WindowGetHandleListFromPos Added : Retrieves the handles of classes at a specific position from a window. Known and Reported Bugs:
      None reported To Do:
      To Be Decided. Opinions welcome! Upcoming Changes:
      To Be Decided.
    • Reziskonh
      By Reziskonh
      Hi, everybody
      I look for GUI whose behavior similar to the message of an email client or antivirus
      In other words:
          Any PC screen able to calculate the size
          To consider the Task bar size
          To find the lower corner on the right/below and to nestle on it

      Notes:
      In GUI the GUICtrlCreateEdit field (as option) - that can be received and displayed through variable information
      Thanks a lot
      PS
      I use the translator, excuse if something is not clear
       

    • VollachR
      By VollachR
      Hi,
      I'd like to show a progress bar for an operation performed by an external program my script is running silently, I want to show it in a GUI I created using the GUICtrlCreateProgress but I have no idea how to do it.
      The important thing to point out is that there's no way of knowing how long the external program will run, as it is a file splitter and it depends on the size of file it splits and the split parts size.
      Can someone point me in the right direction or give me an example how to do so?
      This is my RunWait command:
      RunWait($MYFILES1 & '\fsplit.exe -split ' & $Size & ' mb ' & $File & " -f " & $File & "." & $extension) It uses multiple variables declared and set earlier in the script, how will I got about having the progress of that command shown using GUICtrlCreateProgress ? Is it possible?
      Thank you.
    • nacerbaaziz
      By nacerbaaziz
      Hello my friends
      I have an inquiry and I hope to find the answer here
      I want to create a graphical user interface
      but I want to hide the system menu
      I mean the window menu
      Is this possible?
      If is possible please give me how to do that
      Thanks in advance
    • helmar
      By helmar
      I was playing around with simple GUI creation.  I tend to like parameter driven coding (in prior life (years ago) as Clipper/FoxPro/dBase coder).  Just wanted to see what I could do with a GUI.
      #Region options, includes Opt('MustDeclareVars', 1) Opt("GUIOnEventMode", 1) ; Change to OnEvent mode #include <GUIConstantsEx.au3> #EndRegion options, includes Global Const $nCols = 2, $nRows = 6, $nSpacer = 10, $nBtnWidth = 150, $nBtnHeight = 30 Global $xName = 0, $xID = 0 Global $nGUIWidth = ($nCols * $nBtnWidth) + (($nCols + 1) * $nSpacer) Global $nGUIHeight = ($nRows * $nBtnHeight) + (($nRows + 1) * $nSpacer) Global $hMainGUI = GUICreate("Calculated GUI", $nGUIWidth, $nGUIHeight, -1, -1) For $xRows = 1 to $nRows ;in this arrangement, tabbing is left to right, then next row For $xCols = 1 to $nCols ;reverse the order of this line with the prior line for top to bottom tabbing, then next col $xName += 1 $xID += 1 Global $Dummy = GUICtrlCreateButton("Button" & $xName, _ ($nBtnWidth * ($xCols - 1)) + (($xCols - 1) * $nSpacer) + $nSpacer, _ ($nBtnHeight* ($xRows - 1)) + (($xRows - 1) * $nSpacer) + $nSpacer, _ $nBtnWidth, _ $nBtnHeight) GUICtrlSetOnEvent($xID+2, "Handler") Next Next GUISetOnEvent($GUI_EVENT_CLOSE, "CloseApp") GUISetState(@SW_SHOW) While 1 Sleep(10) WEnd Func CloseApp() Exit EndFunc Func Handler() MsgBox(0,0,"Button " & @GUI_CtrlId - 2) EndFunc  
×