Jump to content

[Tutorial] Using 2 or more GUIs at the same time in a single loop! Easy and uncomplicated, for beginners!


JScript
 Share

Recommended Posts

Hello everyone!

I see that many people still have problems to use two GUIs in the same program, running at the same time (or nearly ...)!

Thinking about it, I decided to post this short tutorial on using two or more windows controlled in the same loop (While-Wend).

Yes, I yours that most already know how to proceed, but beginners may not know...

Here is a small demo:

; #INDEX# =======================================================================================================================
; Title .........: 2GuisInOneLoop.au3
; Module ........: Main Form
; Author ........: João Carlos (jscript) - (C) DVI-Notebook 2008.6-2011.10, dvi-suporte@hotmail.com
; Support .......:
; AutoIt Version.: 3.3.0.0++
; Language ......: English
; Description ...: 2 Gui Forms in one script using same loop!!!
; ===============================================================================================================================

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

Opt('MustDeclareVars', 1); Ensures that all variables are required to be declared!

;#Variables#-----------------------------------------------------------
; Used by form 01
Local $hForm1, $iButton1
Local $iMenu1, $iMItem1_1, $iMItem1_2, $iMenu1_2, $iMItem1_3
; Used by form 02
Local $hForm2, $iButton2
Local $iMenu2, $iMItem2_1, $iMItem2_2, $iMenu2_2, $iMItem2_3
; Used by both GUIs
Local $aGuiEvt, $sFileOpen
;----------------------------------------------------------------------

;#Start_Form1_Creation-------------------------------------------------
$hForm1 = GUICreate("GUI Form 01", 372, 267, 184, 116)
$iMenu1 = GUICtrlCreateMenu("File")
$iMItem1_1 = GUICtrlCreateMenuItem("Open", $iMenu1)
$iMItem1_2 = GUICtrlCreateMenuItem("Exit", $iMenu1)
$iMenu1_2 = GUICtrlCreateMenu("Help")
$iMItem1_3 = GUICtrlCreateMenuItem("About", $iMenu1_2)
$iButton1 = GUICtrlCreateButton("Clik here!", 136, 112, 75, 25)
GUISetState(@SW_SHOW)
;----------------------------------------------------------------------

;#Start_Form2_Creation-------------------------------------------------
$hForm2 = GUICreate("GUI Form 02", 372, 267, -1, -1)
$iMenu2 = GUICtrlCreateMenu("File")
$iMItem2_1 = GUICtrlCreateMenuItem("Open", $iMenu2)
$iMItem2_2 = GUICtrlCreateMenuItem("Exit", $iMenu2)
$iMenu2_2 = GUICtrlCreateMenu("Help")
$iMItem2_3 = GUICtrlCreateMenuItem("About", $iMenu2_2)
$iButton2 = GUICtrlCreateButton("Clik here!", 136, 112, 75, 25)
GUISetState(@SW_SHOW)
;----------------------------------------------------------------------

While 1
    ; # About GUIGetMsg()------------------------------------------- -------------------------
    ; When using the "advanced" parameter, it returns an array with the following information:
    ; $array[0] = 0 or Event ID or Control ID
    ; $array[1] = The window handle the event is from
    ; $array[2] = The control handle the event is from (if applicable)
    ; $array[3] = The current X position of the mouse cursor (relative to the GUI window)
    ; $array[4] = The current Y position of the mouse cursor (relative to the GUI window)
    ;------------------------------------------------- ---------------------------------------
    $aGuiEvt = GUIGetMsg(1) ; (1) = Advanced

    Switch $aGuiEvt[1] ; Handle the event is from
        ; If Form1, then;
        Case $hForm1
            Switch $aGuiEvt[0] ; Handle the event is from (Control ID)
                Case $GUI_EVENT_CLOSE, $iMItem1_2
                    GUISetState(@SW_HIDE, $hForm1) ; Hide, no close!
                    ;---------------------------------------------------------------------------------
                Case $iMItem1_1
                    $sFileOpen = FileOpenDialog("The menu was selected from Gui 01...", @MyDocumentsDir, "All (*.*)", 3, "", $hForm1)
                    ;---------------------------------------------------------------------------------
                Case $iMItem1_3
                    MsgBox(4096, "About (GUI 01)", "João Carlos (jscript) - (C) DVI-Notebook 2008.6-2011.10, dvi-suporte@hotmail.com")
                    ;---------------------------------------------------------------------------------
                Case $iButton1
                    MsgBox(4096, "Inf", "The button was pressed in the Gui 01.")
                    ;---------------------------------------------------------------------------------
            EndSwitch
            ; If Form2, then;
        Case $hForm2
            Switch $aGuiEvt[0] ; Handle the event is from (Control ID)
                Case $GUI_EVENT_CLOSE, $iMItem2_2
                    GUISetState(@SW_HIDE, $hForm2) ; Hide, no close!
                    ;---------------------------------------------------------------------------------
                Case $iMItem2_1
                    $sFileOpen = FileOpenDialog("The menu was selected from Gui 02...", @MyDocumentsDir, "All (*.*)", 3, "", $hForm2)
                    ;---------------------------------------------------------------------------------
                Case $iMItem2_3
                    MsgBox(4096, "About (GUI 02)", "João Carlos (jscript) - (C) DVI-Notebook 2008.6-2011.10, dvi-suporte@hotmail.com")
                    ;---------------------------------------------------------------------------------
                Case $iButton2
                    MsgBox(4096, "Inf", "The button was pressed in the Gui 02.")
                    ;---------------------------------------------------------------------------------
            EndSwitch
    EndSwitch

    ; Checks if the two forms were closed (hide)...
    If _IsClosedGuis($hForm1, $hForm2) Then Exit
WEnd

; #FUNCTION# ====================================================================================================================
; Name ..........: _IsClosedGuis
; Description ...:
; Syntax ........: _IsClosedGuis( $hWnd1, $hWnd2 )
; Parameters ....: $hWnd1               - A handle value.
;                  $hWnd2               - A handle value.
; Return values .: Success              - Returns None
;                                  Failure              - Returns None
; Author ........: João Carlos (Jscript FROM Brazil)
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: _IsClosedGuis( $hWnd1, $hWnd2 )
; ===============================================================================================================================
Func _IsClosedGuis($hWnd1, $hWnd2)
    Local $iState1, $iState2

    $iState1 = WinGetState($hWnd1, "")
    $iState2 = WinGetState($hWnd2, "")

    If Not BitAND($iState1, 2) And Not BitAND($iState2, 2) Then Return 1

    Return 0
EndFunc   ;==>_IsClosedGuis

João Carlos.

Edited by jscript

http://forum.autoitbrasil.com/ (AutoIt v3 Brazil!!!)

Somewhere Out ThereJames Ingram

somewh10.png

dropbo10.pngDownload Dropbox - Simplify your life!
Your virtual HD wherever you go, anywhere!

Link to comment
Share on other sites

  • Moderators

jscript,

Or they could read the Managing Multiple GUIs tutorial in the Wiki. :graduated:

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

I did not realize there was already a tutorial on that! :graduated:

If any moderator want to delete the entire thread, no problem!

João Carlos.

Edited by jscript

http://forum.autoitbrasil.com/ (AutoIt v3 Brazil!!!)

Somewhere Out ThereJames Ingram

somewh10.png

dropbo10.pngDownload Dropbox - Simplify your life!
Your virtual HD wherever you go, anywhere!

Link to comment
Share on other sites

  • 2 weeks later...

jscript,

Or they could read the Managing Multiple GUIs tutorial in the Wiki. :graduated:

M23

Yeah, that is true, but I honestly didnt know about the autoit wiki for about half a year after I found the forums, so I think that this may be a little too important to delete, for those who dont know about the wiki (Until now, hopefully). But I do see where you are coming from, tht is a good point. And JS, this is a good tutorial.

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