Sign in to follow this  
Followers 0
PPowerHouseK

Button creates another GUI

4 posts in this topic

Hello,

I am quite new to this language and have tried my best to keep my stupid questions to myself until I have read the documentation and wiki. However it seems as though I have spent a few hrs just trying to find out how to get a simple function to work. I have run the AutoIt 1-2-3 through every tutorial. Perhaps someone here can help shed some light on the matter.

I simple want to open an additional GUI when the More button is pressed and close the previous GUI. Here is what I have now:

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

;begin GUI test
GUICreate("Application Complex") 
$button1 = GUICtrlCreateButton ("More",  10, 10, 150) 
$cancel = GUICtrlCreateButton ( "Cancel",  355, 370, -1)
GUISetState () 

While 1
    $msg = GUIGetMsg()
    
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop 
    
    If $msg = $cancel Then Exitloop

        If $msg = $button1 Then GUICreate("More GUI") 

        If $msg = $button1 Then Exitloop
 
Wend

On that note, is there a way to have it execute a group of commands when the if statement is met, by using brackets of some sort?

For example,

If $msg = $button1 Then (

GUICreate("this")

Beep(500, 1000)

)

Thanks in advance!

Share this post


Link to post
Share on other sites



PPowerHouseK,

Here is one way to do what you want: :x

#include <GUIConstantsEx.au3>

;begin GUI test
GUICreate("Application Complex", 500, 500, 300, 100)
$button1 = GUICtrlCreateButton ("More",  10, 10, 150)
$cancel = GUICtrlCreateButton ( "Cancel",  355, 370, -1)
GUISetState ()

While 1

    Switch GUIGetMsg()

        Case $GUI_EVENT_CLOSE, $cancel
            Exit
        Case $button1
            ; Delete exisiting GUI
            GUIDelete("Application Complex")
            ; Create new GUI
            GUICreate("More GUI", 300, 300)
            GUISetState()
            ; Wait a bit for effect
            Sleep(1000)
            ; Leave this loop
            ExitLoop
    EndSwitch
Wend

; And end up here
MsgBox(0, "Well?", "Now what are you going to do?")

Note that if you use a Switch structure your Cases are nicely laid out - I find it helps maintain the code more easily. :shifty:

execute a group of commands when the if statement is met

You need to use EndIf like this:

If $msg = $button1 Then
    GUICreate("this")
    Beep(500, 1000)
EndIf

You can find out more about it in the Help file under If.

It seems that what you have read so far has not helped a lot (but do not get discouraged - we all started there!). Could I recommend this tutorial? It runs you through the basic things nice and simply - might be just what you need. :P

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

#3 ·  Posted (edited)

Hello,

I am quite new to this language and have tried my best to keep my stupid questions to myself until I have read the documentation and wiki. However it seems as though I have spent a few hrs just trying to find out how to get a simple function to work. I have run the AutoIt 1-2-3 through every tutorial. Perhaps someone here can help shed some light on the matter.

I simple want to open an additional GUI when the More button is pressed and close the previous GUI. Here is what I have now:

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

;begin GUI test
GUICreate("Application Complex") 
$button1 = GUICtrlCreateButton ("More",  10, 10, 150) 
$cancel = GUICtrlCreateButton ( "Cancel",  355, 370, -1)
GUISetState () 

While 1
    $msg = GUIGetMsg()
    
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop 
    
    If $msg = $cancel Then Exitloop

        If $msg = $button1 Then GUICreate("More GUI") 

        If $msg = $button1 Then Exitloop
 
Wend

On that note, is there a way to have it execute a group of commands when the if statement is met, by using brackets of some sort?

For example,

If $msg = $button1 Then (

GUICreate("this")

Beep(500, 1000)

)

Thanks in advance!

To start off I will help you with your if problem.

The correct syntax for an if statement is as so:

If (condition) Then

(instructions)

ElseIf (condition) Then

(instructions)

Else

(Instructions)

EndIf

Therefore, you need only the following:

If (condition) Then

(instructions)

EndIf

Your if statement would, therefore, be:

If $msg = $button1 Then
GUICreate("this")
Beep(500, 1000)
EndIf
[autoit]

Now, to move onto your code.

The corrected version is below with comments to explain what is happening:

[autoit]
#include <GUIConstantsEx.au3>
;GUIButton not needed
;WinConstants not needed

Opt("MustDeclareVars", 1)     ;forces variable decleration - makes for better programming techniques
Local $winhandle      ;Declaring our variables

;begin GUI test
$winhandle = GUICreate("Application Complex")     ;When you create a GUI, it returns something called a winhandle, which is a unique ID for the window.
                                                  ;$winhandle will be given this value. This is used when deleting a window and other functions.
$button1 = GUICtrlCreateButton ("More",  10, 10, 150) 
$cancel = GUICtrlCreateButton ( "Cancel",  355, 370, -1)
GUISetState() 

While 1
    $msg = GUIGetMsg()

        If $msg = $button1 Then 
                GUIDelete($winhandle) ;deletes the old GUI
                $winhandle = GUICreate("More GUI") ;creates the new GUI and assigns the winhandle. The old GUI winhandle is now not needed,
                                                   ;so the variable is recycled.
                GUISetState()
        EndIf

    If $msg = $GUI_EVENT_CLOSE or $msg = $cancel Then
                GUIDelete($winhandle)  ;Deletes the GUI
                ExitLoop
        EndIf

Wend

I have left a few things un-declared for you to declare (it will help you learn - not trying to be nasty).

As you can see, the contents of the while loop is quite different. I have changed the requirements of exitloop, as you can see there is now an or, and we delete the GUI as this makes for good programming practice if your code then continues as if it does, the GUI will stay.

We have got our winhandles which are quite useful. Basically, they are unique ID's of a window.

If you wish to see what a winhandle looks like, create a GUI, and messagebox or label the winhandle value.

I hope this helps you now,

shanet

Edited by shanet

[font="Comic Sans MS"]My code does not have bugs! It just develops random features.[/font]My Projects[list][*]Live Streaming (Not my project, but my edited version)[right]AutoIt Wrappers![/right][/list]Pure randomness[list][*]Small Minds.......................................................................................................[size="1"]Simple progress bar that changes direction at either sides.[/size][*]ChristmasIt AutoIt Christmas Theme..........................................................[size="1"]I WAS BOOOORED![/size][*]DriveToy..............................................................................................................[size="1"]Simple joke script. Trick your friends into thinking their computer drive is haywire![/size][/list]In Development[list][*]Your Background Task Organiser[*]AInstall Second Generation[/list]BEFORE POSTING ON THE FORUMS, TRY THIS:
%programfiles%/AutoIt3/autoit3.chm

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Thanks you so much, you saved me a LOT of time. I will refrain from asking another remedial question until I have read that tutorial you link from beginning to end. :x

EDIT: I posted the above while shanet was replying. Thank you shanet! I appreciate the time you took to help me learn this new language, your kindness could not be appreciated more!

Edited by PPowerHouseK

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  
Followers 0