gminnick Posted March 28, 2009 Share Posted March 28, 2009 I have been using AutoIT for awhile but have been wondering if I understand the Windowing concept. Here is an example of what I am doing I have a main Window (WindowA) with Button1 that when pressed will call a Function (Function1) that creates another Window (WindowB). When I am done with WindowB I have a Close button that will hide the window. I am now back in WindowA. If I click Button1 again, will it create another WindowB or does it know it is already created and just show it? I am wondering if I have many hidden windows because of the fact that every time I call Function1 I am creating another window. Should I create all my windows in the main part of the code and Show and Hide when needed? I have some windows that have Lists that I want to refresh each time I call the window. I tried to search the forums for this but this is a hard question to search for. Thanks, Link to comment Share on other sites More sharing options...
Authenticity Posted March 28, 2009 Share Posted March 28, 2009 I have been using AutoIT for awhile but have been wondering if I understand the Windowing concept.Here is an example of what I am doingI have a main Window (WindowA) with Button1 that when pressed will call a Function (Function1) that creates another Window (WindowB).When I am done with WindowB I have a Close button that will hide the window.I am now back in WindowA. If I click Button1 again, will it create another WindowB or does it know it is already created and just show it?Upon calling GUICreate you're creating a new GUI from scratch, not an existing one of-course.I am wondering if I have many hidden windows because of the fact that every time I call Function1 I am creating another window.Should I create all my windows in the main part of the code and Show and Hide when needed?I have some windows that have Lists that I want to refresh each time I call the window.I tried to search the forums for this but this is a hard question to search for.Thanks,I'd say, if this window may be invoked more frequently then it may be clever to just show/hide the window instead of creating and destroying the window over and over. Otherwise, there is no reason to create another window which may not be invoked at all or just few times. You're deciding the correct path, if applicable ;] Link to comment Share on other sites More sharing options...
Yashied Posted March 28, 2009 Share Posted March 28, 2009 I have a main Window (WindowA) with Button1 that when pressed will call a Function (Function1) that creates another Window (WindowB).When I am done with WindowB I have a Close button that will hide the window.I am now back in WindowA. If I click Button1 again, will it create another WindowB or does it know it is already created and just show it?Here, everything depends on you. You can can create a new window each time you press the button, and you can block it. If you do not control the existence of the window, then every time you click you will create a new window. It is the program does not understand. My UDFs: iKey | FTP Uploader | Battery Checker | Boot Manager | Font Viewer | UDF Keyword Manager | Run Dialog Replacement | USBProtect | 3D Axis | Calculator | Sleep | iSwitcher | TM | NetHelper | File Types Manager | Control Viewer | SynFolders | DLL Helper Animated Tray Icons UDF Library | Hotkeys UDF Library | Hotkeys Input Control UDF Library | Caret Shape UDF Library | Context Help UDF Library | Most Recently Used List UDF Library | Icons UDF Library | FTP UDF Library | Script Communications UDF Library | Color Chooser UDF Library | Color Picker Control UDF Library | IPHelper (Vista/7) UDF Library | WinAPI Extended UDF Library | WinAPIVhd UDF Library | Icon Chooser UDF Library | Copy UDF Library | Restart UDF Library | Event Log UDF Library | NotifyBox UDF Library | Pop-up Windows UDF Library | TVExplorer UDF Library | GuiHotKey UDF Library | GuiSysLink UDF Library | Package UDF Library | Skin UDF Library | AITray UDF Library | RDC UDF Library Appropriate path | Button text color | Gaussian random numbers | Header's styles (Vista/7) | ICON resource enumeration | Menu & INI | Tabbed string size | Tab's skin | Pop-up circular menu | Progress Bar without animation (Vista/7) | Registry export | Registry path jumping | Unique hardware ID | Windows alignment More... Link to comment Share on other sites More sharing options...
gminnick Posted March 28, 2009 Author Share Posted March 28, 2009 Thanks for the information. I am having trouble understanding the logic when I try to create the window and then show it when I need to. Here is a simplified version of what I am trying to do. It does not work correctly but at least it gives some example of where I need help. When I run this and click Connect it will bring up the Authentication window. But if I click Close and then Connect again, it goes straight to the AuthenticationProcess function as though I clicked Connect on the main menu and Continue on the Authenticate Menu and it keeps calling the AuthenticationProcess over and over. When I show an already created menu I am confused about where the While loop should be. I know I don't want to re-create the window and all the buttons again so I made an If Then statement to check for the existence of the window first. Thanks for any help. Are there any tutorials that go into how this process works? #include <GUIConstantsEX.au3> #include <EditConstants.au3> #include <StaticConstants.au3> #include <ListboxConstants.au3> #include <ListViewConstants.au3> #include <ButtonConstants.au3> #include <WindowsConstants.au3> ;Define Global Window variables Dim $mainwindow, $welcomewindow, $authenticatewindow, $GetCompSchedWindow, $SchedJobsWindow ;Define Global variables Dim $mwAddServerButton, $mwAuthenticate, $mwRefreshComputerbutton, $mwComputerSchedbutton, $mwSchedJobsbutton, $MWCancelbutton ;Create Main Menu $mainwindow = GUICreate("Main Menu", 400, 500) GUISetState(@SW_SHOW) GUICtrlCreateLabel ("Main Menu ", 10, 20, 380, 20, $SS_Center) GUICtrlSetFont (-1,12,600) GUICtrlCreateLabel ("Server List", 15, 60, 100) GUICtrlSetFont (-1,10,600) $mwAuthenticate = GUICtrlCreateButton("Connect", 200, 60, 150, 30) GUICtrlSetFont (-1,12,600) $MWCancelbutton = GUICtrlCreateButton("Close", 200, 400, 150, 30) GUICtrlSetFont (-1,12,600) While 1 $msg = GUIGetMsg() Select Case $msg = $mwAuthenticate AuthenticateMenu() Case $msg = $MWcancelbutton CLOSEClicked() ;ExitLoop Case $msg = $GUI_EVENT_CLOSE CLOSEClicked() ;ExitLoop EndSelect WEnd Func ShowMainMenu2() GUISetState(@SW_HIDE) GUISwitch($mainwindow) GUISetState(@SW_SHOW) EndFunc Func AuthenticateMenu() Local $tbUserName, $tbPassword, $tbAltirisServer, $btnContinue, $btnCancel, $intAuthResult If $authenticatewindow Then GUISwitch($authenticatewindow) GUISetState(@SW_SHOW) Else $authenticatewindow = GUICreate("Authentication Process", 400, 400) MsgBox(0,"","Auth Window Created: " & $authenticatewindow) GUISwitch($authenticatewindow) GUISetState(@SW_SHOW) GUICtrlCreateLabel ("Enter Credentials for connecting to Altiris Server", 10, 30, 380, 20, $SS_Center) GUICtrlSetFont (-1,12,600) GUICtrlCreateLabel ("User Name", 30, 80) GUICtrlSetFont (-1,12,600) $tbUserName = GUICtrlCreateInput ("", 150, 80, 100, 20) GUICtrlSetState(-1,$GUI_FOCUS) GUICtrlCreateLabel ("Password ", 30, 120, 100) GUICtrlSetFont (-1,12,600) $tbPassword = GUICtrlCreateInput ("", 150, 120, 100, 20, $ES_PASSWORD) GUICtrlCreateLabel ("Altiris Server", 30, 160, 100) GUICtrlSetFont (-1,12,600) $tbAltirisServer = GUICtrlCreateCombo ( "Server1", 150, 160, 150, 20); create first item GUICtrlSetData(-1,"Server2|Server3") ; add other item GUICtrlCreateLabel ("Enter SA credentials for connecting to Altiris server.",30, 200) GUICtrlCreateLabel ("You do not need to enter Domain as it will be based on Altiris server selected.",30, 220) $btnContinue = GUICtrlCreateButton("Continue", 150, 270, 100, 30, $BS_DEFPUSHBUTTON) GUICtrlSetFont (-1,12,600) $btnCancel = GUICtrlCreateButton("Cancel", 150, 320, 100) GUICtrlSetFont (-1,12,600) EndIf $msg = 0 While 1 $msg = GUIGetMsg() Select Case $msg = $btnContinue $intAuthResult = AuthenticateProcess($tbUserName, $tbPassword, $tbAltirisServer) If $intAuthResult Then ExitLoop Case $msg = $btnCancel ShowMainMenu2() ExitLoop Case $msg = $GUI_EVENT_CLOSE ShowMainMenu2() ExitLoop EndSelect WEnd EndFunc Func AuthenticateProcess($tbUserName, $tbPassword, $tbAltirisServer) Local $strUserName, $strPassword, $strAltirisServer, $strDomain, $intResult SplashTextOn("Connect to Server", "Connecting.....", 300, 50, -1, -1, 0, "", 14) Sleep(5000) SplashOff() Return $intResult EndFunc Func CLOSEClicked() ;Note: at this point @GUI_CTRLID would equal $GUI_EVENT_CLOSE, Exit EndFunc Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted March 28, 2009 Moderators Share Posted March 28, 2009 gminnick,In this case, I would just create and then delete the authentication window. In my opinion you do not gain a great deal by keeping created windows hidden, unless you are going to use them very often or they are very complex and contain ListViews and the like.Look at the following which I hope does what you want (I have stripped out a lot of the code to simplify):expandcollapse popup#include <GUIConstantsEX.au3> #include <StaticConstants.au3> ;Define Global Window variables Dim $mainwindow, $welcomewindow, $authenticatewindow, $GetCompSchedWindow, $SchedJobsWindow ;Define Global variables Global $mwAddServerButton, $mwAuthenticate, $mwRefreshComputerbutton, $mwComputerSchedbutton, $mwSchedJobsbutton, $MWCancelbutton ;Create Main Menu $mainwindow = GUICreate("Main Menu", 400, 500) GUICtrlCreateLabel("Main Menu ", 10, 20, 380, 20, $SS_Center) GUICtrlSetFont(-1, 12, 600) $mwAuthenticate = GUICtrlCreateButton("Connect", 200, 60, 150, 30) GUICtrlSetFont(-1, 12, 600) $MWCancelbutton = GUICtrlCreateButton("Close", 200, 400, 150, 30) GUICtrlSetFont(-1, 12, 600) GUISetState(@SW_SHOW) While 1 Switch GUIGetMsg() Case $mwAuthenticate AuthenticateMenu() Case $MWCancelbutton, $GUI_EVENT_CLOSE CLOSEClicked() EndSwitch WEnd Func AuthenticateMenu() Local $tbUserName, $tbPassword, $tbAltirisServer, $btnContinue, $btnCancel, $intAuthResult GUISetState(@SW_HIDE, $mainwindow) $authenticatewindow = GUICreate("Authentication Process", 400, 400) $btnContinue = GUICtrlCreateButton("Continue", 150, 270, 100, 30) GUICtrlSetFont(-1, 12, 600) $btnCancel = GUICtrlCreateButton("Cancel", 150, 320, 100) GUICtrlSetFont(-1, 12, 600) GUISetState(@SW_SHOW) While 1 Switch GUIGetMsg() Case $btnContinue $intAuthResult = AuthenticateProcess($tbUserName, $tbPassword, $tbAltirisServer) If $intAuthResult Then ContinueCase ; Just carry on with the code for the next case Case $btnCancel, $GUI_EVENT_CLOSE GUIDelete($authenticatewindow) GUISetState(@SW_SHOW, $mainwindow) Return EndSwitch WEnd EndFunc ;==>AuthenticateMenu Func AuthenticateProcess($tbUserName, $tbPassword, $tbAltirisServer) SplashTextOn("Connect to Server", "Connecting.....", 300, 50, -1, -1, 0, "", 14) Sleep(1000) SplashOff() Return 1; To activate the ContinueCase - set to 0 if you want to simulate no connection EndFunc ;==>AuthenticateProcess Func CLOSEClicked() Exit EndFunc ;==>CLOSEClickedIf you want tutorials, you will find good ones here and here.M23P.S. Please use Code tags. Put [code ] before and [/code ] after your posted code (but omit the trailing space - it is only there so the tags display here). It is much easier to read that way. :-) 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...
gminnick Posted March 28, 2009 Author Share Posted March 28, 2009 Thanks for the answer. I actually do have some windows that have Listviews and that could be called over and over. I just picked one to use as an example. I have functions to add servers to a list, retrieve server information, etc... So I would like to learn how to show and hide windows that would be called several times. But overall this is a small program and I could live with creating and deleting. I will check out the tutorials. The program is a front end to a product called Altiris that we use for automating our builds. So I have to connect to the Altiris server and provide routines to add a server to the Deployment Console, get a list of current jobs waiting to run on the servers, and add jobs to the server. Luckily I they have an SDK and when I learned AutoIt could use COM I started on this project, but have very limited understanding of how Windows really work. Thanks again, Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted March 28, 2009 Moderators Share Posted March 28, 2009 gminnick, Here is a short example of using HIDE/SHOW I wrote for someone else on the forums. I hope you find it useful:expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> $Form1 = GUICreate("Window 1", 420, 160) $Button11 = GUICtrlCreateButton("Next", 355, 125, 60, 30) GUISetState(@SW_SHOW) $Form2 = GUICreate("Window 2", 420, 160) $Button21 = GUICtrlCreateButton("Back", 290, 125, 60, 30) $Button22 = GUICtrlCreateButton("Next", 355, 125, 60, 30) GUISetState(@SW_HIDE) $Form3 = GUICreate("Window 3", 420, 160) $Button31 = GUICtrlCreateButton("Back", 290, 125, 60, 30) $Button32 = GUICtrlCreateButton("Exit", 355, 125, 60, 30) GUISetState(@SW_HIDE) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button11 _Form2() EndSwitch WEnd Func _Form2() GUISetState(@SW_HIDE, $Form1) GUISetState(@SW_SHOW, $Form2) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button21 GUISetState(@SW_HIDE, $Form2) GUISetState(@SW_SHOW, $Form1) Return Case $Button22 _Form3() EndSwitch WEnd EndFunc ;==>_Form2 ;new Func _Form3() GUISetState(@SW_HIDE, $Form2) GUISetState(@SW_SHOW, $Form3) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button31 GUISetState(@SW_HIDE, $Form3) GUISetState(@SW_SHOW, $Form2) Return Case $Button32 Exit Return EndSwitch WEnd EndFunc ;==>_Form3 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...
gminnick Posted March 29, 2009 Author Share Posted March 29, 2009 Thanks Melba23. I think I am understanding this better with the 2 examples I have been given. It seems to make this work, you need to create the Windows outside of the functions along with their controls. And any variables assigned to those controls must be global. And the functions just handle Hiding/Showing along with the while loop to capture input for the Window you SHOW. I have been trying to logically think how the process would work, but sometimes you don't really know what is going on under the covers, but it seems pretty straightforward once I see some examples. Thanks to everyone that replied. Each reply helped answer my questions. And thanks for taking the time to reply so quickly. Very much appreciated. 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