Jump to content
Sign in to follow this  
sahsanu

Understanding how GUI works

Recommended Posts

sahsanu

Hello team,

This is my first post so hello all.

I've started to learn AutoIT a week ago and there are a lot of things that I am missing, please, be patient. I want to made a script that will perform a backup and I will do a GUI (similar to an installer) but I didn't find any example script which covers how GUI windows are created. Don't know whether is better to use HIDE and SHOW or use GuiDelete() or how to achieve that when a window is moved across the screen and then I press the next button, the new window remains in that position instead of in the middle of the screen.

I would like to know which is the best way to achieve what i want to do. Do you know if is out there some example script which I can use to learn how to perform this kind of GUI?.

This is my test script, it only create a window with a start button, check if there is ping to a host and if ping is ok, it goes to the next window:

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

$AHC = GUICreate("Learning AutoIT", 510, 262, -1, -1)
$Group1 = GUICtrlCreateGroup("Learning AutoIT", 16, 16, 481, 201)
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
$label_AHC = GUICtrlCreateLabel("Press start to backup John Doe server", 35, 64, 450, 50)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$start = GUICtrlCreateButton("Start", 376, 224, 121, 33)
GUICtrlSetState($start, $GUI_DEFBUTTON)
GUISetState(@SW_SHOW, $AHC)

$AHC2 = GUICreate("TSO AHC Backup", 510, 262)
$Group2 = GUICtrlCreateGroup("TSO AHC Backup 2", 16, 16, 481, 201)
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
$label_AHC2 = GUICtrlCreateLabel("Test2", 35, 64, 450, 50)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$next1 = GUICtrlCreateButton("Next", 376, 224, 121, 33)
GUICtrlSetState($next1, $GUI_DEFBUTTON)
GUISetState(@SW_HIDE, $AHC2)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $start
            Example()
            MsgBox(64, "Next","Next step")
            GUISetState(@SW_SHOW,$AHC2)
            GUISetState(@SW_HIDE,$AHC)
    EndSwitch
WEnd

Func Example()
    $ping_ip = "localhost"
    $pinging = Ping($ping_ip,100)
    If $pinging Then
    Else
        $retry=MsgBox(5, "Connection failed", "You are not connected to John Doe server." & @CRLF & "Connect to John Doe server and try again.")
        If $retry=4 Then
        Example()
        Else
        Exit
        EndIf
    EndIf
EndFunc

Thank you in advance and sorry if i didn't explain it very well.

Share this post


Link to post
Share on other sites
rasim

sahsanu

Welcome to the forum! :)

As I understand, you want to create a GUI like a setup wizard? Don't need to create many GUI's, just hide/unhide controls or change controls text.

Example:

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

$AHC = GUICreate("Learning AutoIT", 510, 262)

$Group1 = GUICtrlCreateGroup("Learning AutoIT", 16, 16, 481, 201)
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")

$label_AHC = GUICtrlCreateLabel("Press start to backup John Doe server", 35, 64, 450, 50)

GUICtrlCreateGroup("", -99, -99, 1, 1)

$start = GUICtrlCreateButton("Start", 376, 224, 121, 33)
GUICtrlSetState($start, $GUI_DEFBUTTON)

GUISetState(@SW_SHOW, $AHC)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $start
            WinSetTitle($AHC, "", "TSO AHC Backup")
            GUICtrlSetData($Group1, "TSO AHC Backup 2")
            GUICtrlSetData($label_AHC, "Test2")
            GUICtrlSetData($start, "Next")
    EndSwitch
WEnd

:o

Share this post


Link to post
Share on other sites
sahsanu

Welcome to the forum! :)

As I understand, you want to create a GUI like a setup wizard? Don't need to create many GUI's, just hide/unhide controls or change controls text.

Hello rasim, nice to meet you.

Yes I want to create a GUI like a setup wizard ;-). I think that you gave to me the answer I was looking for, thank you very much for your help.

This is the example that I coded. Take a look if you have two minutes and tell me whether this way is the right way to do it.

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

$AHC = GUICreate("Learning AutoIT", 510, 262)
$Group1 = GUICtrlCreateGroup("Learning AutoIT", 16, 16, 481, 201)
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
$label_AHC = GUICtrlCreateLabel("Press start", 35, 64, 450, 50)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$start = GUICtrlCreateButton("Start", 376, 224, 121, 33)
GUICtrlSetState(-1, $GUI_DEFBUTTON)
$next = GUICtrlCreateButton("Next", 376, 224, 121, 33)
GUICtrlSetState(-1, $GUI_HIDE)

GUISetState(@SW_SHOW, $AHC)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $start
                GUICtrlSetData($Group1, "Learning AutoIT - Screen 2")
                GUICtrlSetData($label_AHC, "Test2")
                $next = GUICtrlCreateButton("Next", 376, 224, 121, 33)
        GUICtrlSetState($next, $GUI_DEFBUTTON)
        GUICtrlSetState($start, $GUI_HIDE)
        GUICtrlSetState($next, $GUI_SHOW)
     Case $next
            GUICtrlSetData($Group1, "Learning AutoIT - Screen 3")
                GUICtrlSetData($label_AHC, "Test3")
                $next2 = GUICtrlCreateButton("Next 2", 376, 224, 121, 33)
            GUICtrlSetState($next2, $GUI_DEFBUTTON)
        GUICtrlSetState($next, $GUI_HIDE)
        GUICtrlSetState($next2, $GUI_SHOW)
    EndSwitch
WEnd

Again, thank you very much.

Share this post


Link to post
Share on other sites
rasim

@sahsanu

Hi! Example:

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

$AHC = GUICreate("Learning AutoIT", 510, 262)

$Group1 = GUICtrlCreateGroup("Learning AutoIT", 16, 16, 481, 201)
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
$label_AHC = GUICtrlCreateLabel("Press start", 35, 64, 450, 50)
GUICtrlCreateGroup("", -99, -99, 1, 1)

$next = GUICtrlCreateButton("Start", 376, 224, 121, 33)
GUICtrlSetState(-1, $GUI_DEFBUTTON)

$back = GUICtrlCreateButton("< Back", 250, 224, 121, 33)
GUICtrlSetState(-1, $GUI_HIDE)

GUISetState(@SW_SHOW, $AHC)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $next
            If GUICtrlRead($label_AHC) = "Press start" Then
                GUICtrlSetData($Group1, "Learning AutoIT - Screen 2")
                GUICtrlSetData($label_AHC, "Test2")
                
                GUICtrlSetData($next, "Next >")
                GUICtrlSetState($back, $GUI_SHOW)
            ElseIf GUICtrlRead($label_AHC) = "Test2" Then
                GUICtrlSetData($Group1, "Learning AutoIT - Screen 3")
                GUICtrlSetData($label_AHC, "Test3")
            EndIf
        Case $back
            If GUICtrlRead($label_AHC) = "Test2" Then
                GUICtrlSetData($Group1, "Learning AutoIT")
                GUICtrlSetData($label_AHC, "Press start")
                
                GUICtrlSetData($next, "Start")
                GUICtrlSetState($back, $GUI_HIDE)
            ElseIf GUICtrlRead($label_AHC) = "Test3" Then
                GUICtrlSetData($Group1, "Learning AutoIT - Screen 2")
                GUICtrlSetData($label_AHC, "Test2")
            EndIf
    EndSwitch
WEnd

:)

Share this post


Link to post
Share on other sites
sahsanu

Thank you very much for your help rasim.

Happy New Year :)

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  

×