Jump to content

GUICreate() and GUIDelete()


Go to solution Solved by argumentum,

Recommended Posts

Posted

Good day,

I have some major issues regarding the above two "commands"?

For example, what is wrong with the following?:

; -----------------------------------------------
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
; -----------------------------------------------
#AutoIt3Wrapper_Au3Check_Parameters=-q -d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7
; -----------------------------------------------
Opt("MustDeclareVars", 1)
; -----------------------------------------------
_Form1()
; -----------------------------------------------
Func _Form1()
    ConsoleWrite("Inside _Form1()" & @CRLF)
    Local $MainGui1 = GUICreate("_Form1", 170, 75)
    GUISetFont(14, 800, 0, "Calibri")
    ; -----------------------------------------------
    Local $sCol1Row1 = GUICtrlCreateButton("Go to Form2", 10, 10, 150, 25)
    Local $sCol1Row2 = GUICtrlCreateButton("Exit Me", 10, 40, 150, 25)
    ; -----------------------------------------------
    GUISetState(@SW_SHOW)
    ; -----------------------------------------------
    While 1
        Local $nMsg = GUIGetMsg()
        ; -----------------
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                Exit
            Case $sCol1Row1
                GUIDelete($MainGui1)
                _Form2()
            Case $sCol1Row2
                _ExitMe()
        EndSwitch
    WEnd
EndFunc   ;==>_Form1
; -----------------------------------------------
Func _Form2()
    ConsoleWrite("Inside _Form2()" & @CRLF)
    Local $MainGui2 = GUICreate("_Form2", 170, 75)
    GUISetFont(14, 800, 0, "Calibri")
    ; -----------------------------------------------
    Local $sColRow = GUICtrlCreateButton("Return to Form1", 10, 10, 150, 25)
    ; -----------------------------------------------
    GUISetState(@SW_SHOW)
    ; -----------------------------------------------
    While 1
        Local $nMsg = GUIGetMsg()
        ; -----------------
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                Exit
            Case $sColRow
                GUIDelete($MainGui2)
                ConsoleWrite("Returning to Form1" & @CRLF)
                _Form1()
        EndSwitch
    WEnd
EndFunc   ;==>_Form2
; -----------------------------------------------
Func _ExitMe()
    ConsoleWrite("Inside _ExitMe()" & @CRLF)
    Exit
EndFunc   ;==>_ExitMe
; -----------------------------------------------

Please understand that I am a rank neophyte here...so, please be patient with me!!

I have been told that the above is incorrect... "... because both function Func _Form1() and Func _Form2() are never ended!" If so, what is purpose of "GUIDelete($MainGui1)" then?

Posted
; -----------------------------------------------
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
; -----------------------------------------------
#AutoIt3Wrapper_Au3Check_Parameters=-q -d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7
; -----------------------------------------------
Opt("MustDeclareVars", 1)
; -----------------------------------------------
_Form1()
; -----------------------------------------------
Func _Form1()
    ConsoleWrite("Inside _Form1()" & @CRLF)
    Local $MainGui1 = GUICreate("_Form1", 170, 75)
    #forceref $MainGui1 ; because $MainGui1 is not used, ..if you are going to use it.
    GUISetFont(14, 800, 0, "Calibri")
    ; -----------------------------------------------
    Local $sCol1Row1 = GUICtrlCreateButton("Go to Form2", 10, 10, 150, 25)
    Local $sCol1Row2 = GUICtrlCreateButton("Exit Me", 10, 40, 150, 25)
    ; -----------------------------------------------
    GUISetState(@SW_SHOW)
    ; -----------------------------------------------
    While 1
        ; -----------------
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE, $sCol1Row2
                _ExitMe()
            Case $sCol1Row1
;~                 GUIDelete($MainGui1) ; shouldn't delete itself
                GUISetState(@SW_HIDE)
                _Form2()
                GUISetState(@SW_SHOW)
        EndSwitch
    WEnd
EndFunc   ;==>_Form1
; -----------------------------------------------
Func _Form2()
    ConsoleWrite("Inside _Form2()" & @CRLF)
    Local $MainGui2 = GUICreate("_Form2", 170, 75)
    GUISetFont(14, 800, 0, "Calibri")
    ; -----------------------------------------------
    Local $sColRow = GUICtrlCreateButton("Return to Form1", 10, 10, 150, 25)
    ; -----------------------------------------------
    GUISetState(@SW_SHOW)
    ; -----------------------------------------------
    While 1
        ; -----------------
        Switch GUIGetMsg()
;~             Case $GUI_EVENT_CLOSE
;~                 Exit ; should go back ?
            Case $sColRow, $GUI_EVENT_CLOSE
                GUIDelete($MainGui2)
                ConsoleWrite("Returning to Form1" & @CRLF)
;~                 _Form1() ; because is hidden
                Return ; to previous GUI
        EndSwitch
    WEnd
EndFunc   ;==>_Form2
; -----------------------------------------------
Func _ExitMe()
    ConsoleWrite("Inside _ExitMe()" & @CRLF)
    GUIDelete()
    Exit
EndFunc   ;==>_ExitMe
; -----------------------------------------------

 

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Posted (edited)

argumentum,

Thanks so very much for the response...appreciated!

So...

;~                 GUIDelete($MainGui1) ; shouldn't delete itself

"Why?" ...and...

;~                 _Form1()
                Return ; to previous GUI

Again, "Why"?

May I ask, "Where are you getting this information from?"
• I am NOT seeing such information anywhere on the AutoIt Forum or via a "Net" search!!

Also,

GUIDelete($MainGui2)

How is the above any different than "GUIDelete($MainGui1)"?

Edited by mr-es335
Posted
3 hours ago, mr-es335 said:

May I ask, "Where are you getting this information from?"

I've got that information from ... my imagination, trying to figure out what you may need to have.
I figure that you have a main gui that you'd like to get back to. So I hide it, load the other gui and when closed unhide the main gui.

I tend to read and chat in code, AutoIt code. Users tend to be very vague in their explanations so code is king. Now you don't read/understand code very much and that limits what I can say.
I thought that the code spoke for itself.

Other than that, all I can do is ignore your questions given that I cause more problems than solutions for you.

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Posted (edited)

argumentum,

Ever since I began working with Autoit, I have been told...time-and-time-and-time again...that the HelpFile is "god"....and that ALL answers to my questions will be obtained in that text.

In light o the present situation, for "GUICreate", we have "Create a GUI window". We are them provided with two examples, the first - being stripped down, is:

#include <GUIConstantsEx.au3>
Example()
Func Example()
    ; Create a GUI with various controls.
    Local $hGUI = GUICreate("Example", 400, 400)
    ; Display the GUI.
    GUISetState(@SW_SHOW, $hGUI)
    ; Loop until the user exits.
    While 1
    WEnd
    ; Delete the previous GUI and all controls.
    GUIDelete($hGUI)
EndFunc   ;==>Example

In the second-to-last line we have, "GUIDelete($hGUI)"...is this NOT an example of a GUI deleting itself! It most certainly appears to be that to me!

For "GUIDelete" we have "Deletes a GUI window and all controls that it contains." And the example provided, again stripped down:

#include <GUIConstantsEx.au3>
Example()
Func Example()
    GUICreate("My GUI")     ; will create a dialog box that when displayed is centered
    GUISetState(@SW_SHOW)     ; will display an empty dialog box
    ; Loop until the user exits.
    While 1
    WEnd
    GUIDelete()    ;    ; will return 1
EndFunc   ;==>Example

Again, in the second-to-last line we have, "GUIDelete()"...is this again...NOT an example of a GUI deleting itself! It most certainly appears to be that to me!

Without coming across as being rude or impertinent, all that I was asking is how you derived your comment about "GUIDelete($MainGui1) ; shouldn't delete itself"! Thus, if the GUI is simply to be hidden, why have command to delete the GUI?

For curiosity, would this "work"?

#include <GUIConstantsEx.au3>

Example1()

Func Example1()
    GUICreate("My GUI")     ; will create a dialog box that when displayed is centered
    GUISetState(@SW_SHOW)     ; will display an empty dialog box
    ; Loop until the user exits.
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
        EndSwitch
    WEnd
    $Value = GUIDelete()    ;    ; will return 1
    ConsoleWrite("Example1 return:" & $Value & @CRLF)
    Example2()
EndFunc   ;==>Example1

Func Example2()
    GUICreate("My GUI")     ; will create a dialog box that when displayed is centered
    GUISetState(@SW_SHOW)     ; will display an empty dialog box
    ; Loop until the user exits.
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
        EndSwitch
    WEnd
    $Value = GUIDelete()    ;    ; will return 1
    ConsoleWrite("Example2 return:" & $Value & @CRLF)
EndFunc   ;==>Example2

 

Edited by mr-es335
Posted (edited)
5 hours ago, mr-es335 said:

Thus, if the GUI is simply to be hidden, why have command to delete the GUI?

You have options. You can opt to destroy the GUI ( GuiDelete() ) or just hide it, ..or minimize it, or make the 2nd GUI a child of the 1st one.
Since I have no idea what you envision, I figure that the 1st GUI will be your default, a menu of sorts. Hence my comments.

5 hours ago, mr-es335 said:

Without coming across as being rude or impertinent, all that I was asking...

4 hours ago, mr-es335 said:

Hmmmm...no PM's Huh!!!

I understand you rush to get it working. I just don't know what it is.
And you don't look rude. Just desperate. And yes, it looks impatient but is quite frustrating not having stuff working when the explanations are not clear. But they are clear.
So, how can something be "clearly explain" yet, make no sense !. Welcome to coding :lol:

5 hours ago, mr-es335 said:

Ever since I began working with Autoit, I have been told...time-and-time-and-time again...that the HelpFile is "god"....and that ALL answers to my questions will be obtained in that text.

I call that "the katas". You do the katas just as in martial arts and your Kungfu ( coding Kungfu ) will be good. But you have to do all the Katas/examples otherwise you may be missing that, "little thing", that puts it all together.
Myself started just like you, rude and impatient. Desperate to get it working. ...you are not the first or the only one going through this. Nor the last one.
Knowing your personality profile and the stage in your coding growth, I preemptively removed the PM to you, well knowing that you need this done and I, wishing not to have an impatient user nagging me. ( and yes, you can add a sad face in the like button of this post. I understand )

5 hours ago, mr-es335 said:

For curiosity, would this "work"?

..if it works on your PC is very likely that will work in mine too so, what is your question ? ( rhetorical, needs no answer )

Maybe this does what you envision ?
 

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

Exit CreateTabs()
Func CreateTabs()
    #Region ### START Koda GUI section ### Form=
    Local $Form1 = GUICreate("212576-guicreate-and-guidelete", 400, 100)
    Local $idTab1 = GUICtrlCreateTab(160, 48, 289, 193)
    GUICtrlSetState($idTab1, $GUI_HIDE)
    Local $idTabSheet1 = GUICtrlCreateTabItem("TabSheet1")
    GUICtrlSetState(-1, $GUI_SHOW)
    Local $idBttn1 = GUICtrlCreateButton("in sheet one", 20, 20, 100)
    Local $idTabSheet2 = GUICtrlCreateTabItem("TabSheet2")
    Local $idBttn2 = GUICtrlCreateButton("in sheet two", 40, 40, 100)
    GUICtrlCreateTabItem("")
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                GUIDelete()
                Return

            Case $idBttn1
                GUICtrlSetState($idTabSheet2, $GUI_SHOW)

            Case $idBttn2
                GUICtrlSetState($idTabSheet1, $GUI_SHOW)

        EndSwitch
    WEnd
EndFunc   ;==>CreateTabs

 

Edited by argumentum
English ( one day I'll learn it )

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Posted (edited)

argumentum,

A couple of things...

1) Thanks for the reply and the understanding...both are sincerely appreciated!
2) What I envision is two GUI's - as shown below:
a) Form1 calls Form2, as-well-as, exiting the script
b) Form2 returns to Form1

Here is my initial [...and I believe error-ridden script]:

; -----------------------------------------------
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
; -----------------------------------------------
#AutoIt3Wrapper_Au3Check_Parameters=-q -d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7
; -----------------------------------------------
Opt("MustDeclareVars", 1)
; -----------------------------------------------
_Form1()
; -----------------------------------------------
Func _Form1()
    Local $MainGui1 = GUICreate("_Form1", 170, 75)
    GUISetFont(14, 800, 0, "Calibri")
    ; -----------------------------------------------
    Local $sCol1Row1 = GUICtrlCreateButton("Go to Form2", 10, 10, 150, 25)
    Local $sCol1Row2 = GUICtrlCreateButton("Exit Me", 10, 40, 150, 25)
    ; -----------------------------------------------
    GUISetState(@SW_SHOW)
    ; -----------------------------------------------
    While 1
        Local $nMsg = GUIGetMsg()
        ; -----------------
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                Exit
            Case $sCol1Row1
                GUIDelete($MainGui1)
                _Form2()
            Case $sCol1Row2
                _ExitMe()
        EndSwitch
    WEnd
EndFunc   ;==>_Form1
; -----------------------------------------------
Func _Form2()
    Local $MainGui2 = GUICreate("_Form2", 170, 75)
    GUISetFont(14, 800, 0, "Calibri")
    ; -----------------------------------------------
    Local $sColRow = GUICtrlCreateButton("Return to Form1", 10, 10, 150, 25)
    ; -----------------------------------------------
    GUISetState(@SW_SHOW)
    ; -----------------------------------------------
    While 1
        Local $nMsg = GUIGetMsg()
        ; -----------------
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                Exit
            Case $sColRow
                GUIDelete($MainGui2)
                _Form1()
        EndSwitch
    WEnd
EndFunc   ;==>_Form2
; -----------------------------------------------
Func _ExitMe()
    Exit
EndFunc   ;==>_ExitMe
; -----------------------------------------------

What I require is:

1) Ensure that Form1 is properly "handled"
2) Ensure that Form2 is called properly
3) Ensure that Form2 is exited properly
4) A means of testing the return code from Form2
• I have been looking for means of doing this for some time - to no avail!!

I do hope that the above makes sense?

c.png

Edited by mr-es335
  • Solution
Posted (edited)
; -----------------------------------------------
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
; -----------------------------------------------
#AutoIt3Wrapper_Au3Check_Parameters=-q -d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7
; -----------------------------------------------
Opt("MustDeclareVars", 1)
; -----------------------------------------------
_Form1()
; -----------------------------------------------
Func _Form1()
    Local $iW = 270, $iH = 100
    ConsoleWrite("Inside _Form1()" & @CRLF)
    GUICreate("_Form1", $iW, $iH)
    GUISetFont(14, 800, 0, "Calibri")
    ; -----------------------------------------------
    Local $sCol1Row1 = GUICtrlCreateButton("Go to Form2", 10, 10, $iW - 20, 25)
    Local $sCol1Row2 = GUICtrlCreateButton("Exit Me", 10, 40, $iW - 20, 25)
    Local $sCol1Row3 = GUICtrlCreateLabel("The time returned by Form2", 10, 70, $iW - 20, 25)
    ; -----------------------------------------------
    GUISetState(@SW_SHOW)
    ; -----------------------------------------------
    While 1
        ; -----------------
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE, $sCol1Row2
                _ExitMe()
            Case $sCol1Row1
                GUISetState(@SW_HIDE)
                GUICtrlSetData($sCol1Row3, _Form2($iW, $iH))
                GUISetState(@SW_SHOW)
        EndSwitch
    WEnd
EndFunc   ;==>_Form1
; -----------------------------------------------
Func _Form2($iW, $iH)
    ConsoleWrite("Inside _Form2()" & @CRLF)
    Local $MainGui2 = GUICreate("_Form2", $iW, $iH)
    GUISetFont(14, 800, 0, "Calibri")
    ; -----------------------------------------------
    Local $sColRow = GUICtrlCreateButton("Return to Form1", 10, 10, $iW - 20, 25)
    ; -----------------------------------------------
    GUISetState(@SW_SHOW)
    ; -----------------------------------------------
    While 1
        ; -----------------
        Switch GUIGetMsg()
            Case $sColRow, $GUI_EVENT_CLOSE
                GUIDelete($MainGui2)
                ConsoleWrite("Returning to Form1" & @CRLF)
                Return "Time in Form2 was: " & @MIN & ':' & @SEC & '.' & @MSEC; return something back
        EndSwitch
    WEnd
EndFunc   ;==>_Form2
; -----------------------------------------------
Func _ExitMe()
    ConsoleWrite("Inside _ExitMe()" & @CRLF)
    GUIDelete() ; last GUI in the stack of GUIs
    Exit
EndFunc   ;==>_ExitMe
; -----------------------------------------------

..changed my prior example to return something back to the 1st GUI.

36 minutes ago, mr-es335 said:

I do hope that the above makes sense?

..anything can make sense. The question is: does it do what you need. And if it does, then you've got it.

I would not spend much time in correctness. If it does what you need then is good.
If you later learn a thing or two, apply your new coding style to the new projects.

My code can be viewed as sucky, ..I don't mind. As long as it works, it worked.
If you later, much later, become a perfectionist, good for you. You have the experience. But for now, if am not shown a working app, I have no clue of what is the goal of the app and how a user of the app would make sense of the GUI design.

Get the concept working, Then you can worry about coding styles. Otherwise, I doubt anyone can correct the code.

Again, is not personal. The code can be bad or good. It has nothing to do with you being good or bad. Detaching from the fruit of your labor is important. Very important.

Am sure that the Buddha started as a coder, then one day..., he became illuminated :P   

Edit: changed the code a bit to pass parameters back and forth.

Edited by argumentum
better code ?

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Posted (edited)

argumentum,

Well, the above snippet has given me some tangible material to work with!! Thanks!!

Interesting employment of "Local $iW = 270, $iH = 100"...makes perfect sense to do so!!

Is the following "preferable" for Form2?

While 1
        Switch GUIGetMsg()
            Case $sColRow, $GUI_EVENT_CLOSE
                GUIDelete($MainGui2)
                ;Return
                ExitLoop
        EndSwitch
    WEnd

As an afterthought, the following is my ultimate goal for Form2"...thus the requirement of a 2nd form...

d.png

Edited by mr-es335
Posted
3 minutes ago, mr-es335 said:

Is the following "preferable" for Form2?

"preferable", meh. Yes, a clear declaration is always preferable. But AutoIt GuiDelete() based on the last GUI created, so 1,2,3 and removes 3,2,1 as if on a stack of cards you put one on top of the other, removing the one at hand to get to the next one ( if memory serves ). But yes, a declaration is always preferable.

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Posted
5 hours ago, mr-es335 said:

I have been told...time-and-time-and-time again...that the HelpFile is "god".

If the help file is God then the Wiki is the Goddess of AutoIt. The Tutorials you find there explain step by step how to do a specific task.
Example: Managing multiple GUIs

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...