amin84 Posted August 5, 2010 Share Posted August 5, 2010 Hi, I'm trying to make a script that will have multiple GUIs (Main GUI, About GUI and Help GUI, ...). I want to make it that if they click on About, it will bring About GUI and it will disable selecting the Main GUI until about is closed (with close button or OK button). Same thing with help and so on. I know how to open a MsgBox with a button but can't figure out multiple GUIs. This is what I got so far: expandcollapse popup#include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> ;Help GUI $helpForm = GUICreate("Help", 322, 234, 302, 218) $helpGrp = GUICtrlCreateGroup("", 8, 8, 305, 185) $helpGuiLbl = GUICtrlCreateLabel("Help GUI", 80, 80, 154, 41) GUICtrlSetFont(-1, 24, 400, 0, "MS Sans Serif") GUICtrlCreateGroup("", -99, -99, 1, 1) $helpOkBtn = GUICtrlCreateButton("&OK", 120, 200, 83, 25) ;About GUI $aboutForm = GUICreate("About", 322, 234, 302, 218) $aboutGrp = GUICtrlCreateGroup("", 8, 8, 305, 185) $aboutGuiLbl = GUICtrlCreateLabel("About GUI", 80, 80, 154, 41) GUICtrlSetFont(-1, 24, 400, 0, "MS Sans Serif") GUICtrlCreateGroup("", -99, -99, 1, 1) $aboutOkBtn = GUICtrlCreateButton("&OK", 120, 200, 83, 25) ;Main GUI $mainGuiForm = GUICreate("Main GUI", 442, 326, 192, 124) $helpSmnu = GUICtrlCreateMenu("Help") $aboutSmnu = GUICtrlCreateMenuItem("About", $helpSmnu) $helpSmnu = GUICtrlCreateMenuItem("Help", $helpSmnu) $mainGuiGrp = GUICtrlCreateGroup("", 8, 0, 425, 297) $mainGuiLbl = GUICtrlCreateLabel("Main GUI", 152, 128, 138, 41) GUICtrlSetFont(-1, 24, 400, 0, "MS Sans Serif") GUICtrlCreateGroup("", -99, -99, 1, 1) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $aboutSmnu Case $helpSmnu EndSwitch WEnd Any body can help me or show me a tutorial that is close to this one? Tnx a lot. Link to comment Share on other sites More sharing options...
czardas Posted August 5, 2010 Share Posted August 5, 2010 I recommend reading Melba23's tutorial about this.http://www.autoitscript.com/wiki/Managing_Multiple_GUIs operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
amin84 Posted August 6, 2010 Author Share Posted August 6, 2010 THANKS. I just read that article and I rewrote the example I had above for others if they had the same problem: expandcollapse popup#include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> Opt("GUIOnEventMode", 1) Global $mainGuiForm, $aboutOkBtn, $aboutForm, $aboutSmnu, $helpOkBtn, $helpForm, $helpSmnu, $mainGuiForm = 9999 _mainGUI() Func _helpGUI() ;Help GUI $helpForm = GUICreate("Help", 322, 234, 302, 218) GUISetOnEvent($GUI_EVENT_CLOSE, "On_Close") $helpGrp = GUICtrlCreateGroup("", 8, 8, 305, 185) $helpGuiLbl = GUICtrlCreateLabel("Help GUI", 80, 80, 154, 41) GUICtrlSetFont(-1, 24, 400, 0, "MS Sans Serif") GUICtrlCreateGroup("", -99, -99, 1, 1) $helpOkBtn = GUICtrlCreateButton("&OK", 120, 200, 83, 25) GUICtrlSetOnEvent(-1, "On_Button") GUISetState() EndFunc Func _aboutGUI() ;About GUI $aboutForm = GUICreate("About", 322, 234, 302, 218) GUISetOnEvent($GUI_EVENT_CLOSE, "On_Close") $aboutGrp = GUICtrlCreateGroup("", 8, 8, 305, 185) $aboutGuiLbl = GUICtrlCreateLabel("About GUI", 80, 80, 154, 41) GUICtrlSetFont(-1, 24, 400, 0, "MS Sans Serif") GUICtrlCreateGroup("", -99, -99, 1, 1) $aboutOkBtn = GUICtrlCreateButton("&OK", 120, 200, 83, 25) GUICtrlSetOnEvent(-1, "On_Button") GUISetState() EndFunc Func _mainGUI() ;Main GUI $mainGuiForm = GUICreate("Main GUI", 442, 326, 192, 124) GUISetOnEvent($GUI_EVENT_CLOSE, "On_Close") $helpSmnu = GUICtrlCreateMenu("Help") $aboutSmnu = GUICtrlCreateMenuItem("About", $helpSmnu) GUICtrlSetOnEvent(-1, "On_Button") $helpSmnu = GUICtrlCreateMenuItem("Help", $helpSmnu) GUICtrlSetOnEvent(-1, "On_Button") $mainGuiGrp = GUICtrlCreateGroup("", 8, 0, 425, 297) $mainGuiLbl = GUICtrlCreateLabel("Main GUI", 152, 128, 138, 41) GUICtrlSetFont(-1, 24, 400, 0, "MS Sans Serif") GUICtrlCreateGroup("", -99, -99, 1, 1) GUISetState() While 1 Sleep(10) WEnd EndFunc Func On_Close() Switch @GUI_WINHANDLE Case $mainGuiForm Exit Case $aboutForm GUIDelete($aboutForm) GUICtrlSetState($aboutSmnu, $GUI_ENABLE) Case $helpForm GUIDelete($helpForm) GUICtrlSetState($aboutSmnu, $GUI_ENABLE) EndSwitch EndFunc Func On_Button() Switch @GUI_CTRLID Case $aboutSmnu GUICtrlSetState($aboutSmnu, $GUI_DISABLE) _aboutGUI() Case $helpSmnu GUICtrlSetState($helpSmnu, $GUI_DISABLE) _helpGUI() Case $aboutOkBtn GUIDelete($helpForm) GUICtrlSetState($aboutSmnu, $GUI_ENABLE) Case $helpOkBtn GUIDelete($helpForm) GUICtrlSetState($aboutSmnu, $GUI_ENABLE) EndSwitch EndFunc Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted August 6, 2010 Moderators Share Posted August 6, 2010 leomoon, Nice to know it was worth writing the tutorial! Delighted you found it useful. 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...
amin84 Posted August 6, 2010 Author Share Posted August 6, 2010 Ok so now there is a small problem. I know that every GUI will be in a function and you will have 2 functions. One to control the GUIs (On_Close) and one to assign commands to buttons (On_Button) in that example. Now let say we have a MsgBox with Yes and No. How do you map the Yes and No buttons inside the On_Button function? Because in a MsgBox you can't make variables for buttons (or can we?). Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted August 6, 2010 Moderators Share Posted August 6, 2010 leomoon,No you cannot assign variables to MsgBox buttons - nor should you need to. MsgBox is a blocking function - your script pauses until a button on the MsgBox is pressed - at which point the function terminates with a return value which you can use in some decision structure. You main GUI appears unresponsive until the MsgBox is cleared.However, things are not that simple, as the MsgBox can be set as Application, System or Task Modal.WTF, I hear you cry! Here is what these wacky sounding terms actually mean.Normal: This is the default setting. In this case your GUI will react to mouse clicks and will even retake focus from the MsgBox, but will not act on the clicks until the MsgBox is cleared. Try closing the main GUI while the MsgBox is displayed - it will not close unless you clear the Msgbox first:#include <GUIConstantsEx.au3> $hGUI = GUICreate("Test", 500, 500) GUISetState() MsgBox(0, "Blocking", "Press me to continue") While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch WEndSystem Modal: Now the MsgBox remains in view even if the main GUI regains focus, however if the main GUI is closed this will occur as soon as the MsgBox is cleared.#include <GUIConstantsEx.au3> $hGUI = GUICreate("Test", 500, 500) GUISetState() MsgBox(4096, "Blocking", "Press me to continue") While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch WEndTask Modal: Now we get to the real deal - you cannot action anything on the main GUI until the MsgBox is cleared. So you cannot close the main GUI - or do anything else with it at all!#include <GUIConstantsEx.au3> $hGUI = GUICreate("Test", 500, 500) GUISetState() MsgBox(8192, "Blocking", "Press me to continue") While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch WEndAll clear? 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...
amin84 Posted August 7, 2010 Author Share Posted August 7, 2010 I got it now. I was running the MsgBox inside a function and then I was making the button to call that function that's why the msgbox wasn't working. Tnx A LOT for explaining it patiently. Here is another sample with MsgBox.. expandcollapse popup#include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Opt("GUIOnEventMode", 1) Global $mainGuiForm, $runBtn, $cancelBtn, $msgBox = 0 _mainGui() Func _mainGui() $mainGuiForm = GUICreate("Main GUI", 194, 58, 192, 124) GUISetOnEvent($GUI_EVENT_CLOSE, "_onClose") $runBtn = GUICtrlCreateButton("Run", 16, 16, 75, 25, $WS_GROUP) GUICtrlSetOnEvent(-1, "_onBtn") $cancelBtn = GUICtrlCreateButton("Cancel", 104, 16, 75, 25, $WS_GROUP) GUICtrlSetOnEvent(-1, "_onBtn") GUISetState() While 1 Sleep(10) WEnd EndFunc Func _onClose() Switch @GUI_WinHandle Case $mainGuiForm Exit EndSwitch EndFunc Func _onBtn() Switch @GUI_CtrlId Case $runBtn $msgBox = MsgBox(8196, "Proceed...", "Are you sure?") If $msgBox = 6 Then If @OSVersion = "WIN_7" Then GUISetState(@SW_HIDE, $mainGuiForm) MsgBox(0, "", "This program is not for your computer.") Exit Else Exit EndIf EndIf Case $cancelBtn Exit EndSwitch EndFunc Link to comment Share on other sites More sharing options...
czardas Posted August 7, 2010 Share Posted August 7, 2010 Good stuff. operator64 ArrayWorkshop 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