JScript Posted October 2, 2011 Share Posted October 2, 2011 (edited) 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:expandcollapse popup; #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 ;==>_IsClosedGuisJoão Carlos. Edited October 2, 2011 by jscript http://forum.autoitbrasil.com/ (AutoIt v3 Brazil!!!) Somewhere Out ThereJames Ingram Download Dropbox - Simplify your life!Your virtual HD wherever you go, anywhere! Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted October 2, 2011 Moderators Share Posted October 2, 2011 jscript,Or they could read the Managing Multiple GUIs tutorial in the Wiki. M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
JScript Posted October 2, 2011 Author Share Posted October 2, 2011 (edited) I did not realize there was already a tutorial on that! If any moderator want to delete the entire thread, no problem! João Carlos. Edited October 2, 2011 by jscript http://forum.autoitbrasil.com/ (AutoIt v3 Brazil!!!) Somewhere Out ThereJames Ingram Download Dropbox - Simplify your life!Your virtual HD wherever you go, anywhere! Link to comment Share on other sites More sharing options...
Valuater Posted October 2, 2011 Share Posted October 2, 2011 Nice job explaining though JS... Also noted the last line on the wiki "only one method per script please!"...so real... lol 8) Link to comment Share on other sites More sharing options...
JScript Posted October 2, 2011 Author Share Posted October 2, 2011 @Valuater, Yes, I saw, thanks. João Carlos. http://forum.autoitbrasil.com/ (AutoIt v3 Brazil!!!) Somewhere Out ThereJames Ingram Download Dropbox - Simplify your life!Your virtual HD wherever you go, anywhere! Link to comment Share on other sites More sharing options...
Mikeman27294 Posted October 11, 2011 Share Posted October 11, 2011 jscript, Or they could read the Managing Multiple GUIs tutorial in the Wiki. 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now