mr-es335 Posted Sunday at 07:56 PM Posted Sunday at 07:56 PM Good day, I have two buttons, Option 1 and Option 2. Option 1 appears to work without issue. However, Option 2, appears to get "stuck"...and I am not sure why? expandcollapse popup; ----------------------------------------------- #RequireAdmin ; ----------------------------------------------- #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <MsgBoxConstants.au3> ; ----------------------------------------------- Opt("GUIOnEventMode", 1) ; ----------------------------------------------- Global $Form1, $sCol1Row1, $sCol1Row2 Global $sLabel1, $sOption1Label Global $sLabel2, $sOption2Label ; ----------------------------------------------- Form1() ; ----------------------------------------------- Func Form1() $Form1 = GUICreate("", 235, 75) GUISetFont(14, 800, 0, "Calibri") ; ----------------------------------------------- GUISetOnEvent($GUI_EVENT_CLOSE, "_CloseForm") ; ----------------------------------------------- $sCol1Row1 = GUICtrlCreateButton("For Option 1", 10, 10, 215, 25) GUICtrlSetOnEvent($sCol1Row1, "Option1") $sCol1Row2 = GUICtrlCreateButton("For Option 2", 10, 40, 215, 25) GUICtrlSetOnEvent($sCol1Row2, "Option2") ; ----------------------------------------------- GUISetState(@SW_SHOW, $Form1) ; ----------------------------------------------- While 1 Sleep(40) WEnd EndFunc ;==>Form1 ; ----------------------------------------------- Func Option1() $sLabel1 = GUICreate("", 75, 23, 620, 48, $WS_POPUP, $WS_EX_TOPMOST) GUISetFont(14, 800, 0, "Calibri") GUISetBkColor(0x3D3D3D) GUISetOnEvent($GUI_EVENT_CLOSE, "_CloseForm") ; ----------------------------------------------- $sOption1Label = GUICtrlCreateLabel("Option 1", 0, 0, 75, 23, $SS_CENTER) GUICtrlSetColor(-1, 0xFFFFFF) GUICtrlSetOnEvent($sOption1Label, "_ColRow") ; ----------------------------------------------- GUISetState(@SW_SHOW) GUICtrlSetState($sCol1Row1, $GUI_DISABLE) ;~ ConsoleWrite($sCol1Row1) EndFunc ;==>Option1 ; ----------------------------------------------- Func Option2() $sLabel2 = GUICreate("", 75, 23, 620, 48, $WS_POPUP, $WS_EX_TOPMOST) GUISetFont(14, 800, 0, "Calibri") GUISetBkColor(0x3D3D3D) GUISetOnEvent($GUI_EVENT_CLOSE, "_CloseForm") ; ----------------------------------------------- $sOption2Label = GUICtrlCreateLabel("Option 2", 0, 0, 75, 23, $SS_CENTER) GUICtrlSetColor(-1, 0xFFFFFF) GUICtrlSetOnEvent($sOption2Label, "_ColRow") ; ----------------------------------------------- GUISetState(@SW_SHOW) GUICtrlSetState($sCol1Row2, $GUI_DISABLE) ;~ ConsoleWrite($sCol1Row2) EndFunc ;==>Option1 ; ----------------------------------------------- Func _ColRow() ConsoleWrite("@GUI_CtrlId=" & @GUI_CtrlId & @CRLF) Switch @GUI_CtrlId Case $sOption1Label WinClose($sLabel1) Case $sOption2Label WinClose($sLabel2) EndSwitch EndFunc ;==>_ColRow ; ----------------------------------------------- Func _CloseForm() Switch @GUI_WinHandle Case $Form1 MsgBox($MB_OK, "GUI Event", "You selected CLOSE in the main window! Exiting...", 1) Exit Case $sLabel1 GUIDelete(@GUI_WinHandle) GUICtrlSetState($sCol1Row1, $GUI_ENABLE) Case $sLabel2 GUIDelete(@GUI_WinHandle) GUICtrlSetState($sCol1Row2, $GUI_ENABLE) EndSwitch EndFunc ;==>_CloseForm ; ----------------------------------------------- mr-es335 Sentinel Music Studios
pixelsearch Posted Sunday at 10:08 PM Posted Sunday at 10:08 PM It seems to me that the issue comes from this function, where both $sOption1Label and $sOption2Label got the same value Func _ColRow() ConsoleWrite("@GUI_CtrlId=" & @GUI_CtrlId & @CRLF) Switch @GUI_CtrlId Case $sOption1Label WinClose($sLabel1) Case $sOption2Label WinClose($sLabel2) EndSwitch EndFunc ;==>_ColRow $sOption1Label = 5 when you create its GUI (option 1) $sOption2Label = 5 when you create its GUI (option 2) Why do they have the same value ? Because you delete the 1st GUI before creating the 2nd GUI, so the (now deleted) Control ID's values in GUI1 are now reused for GUI2 controls @Melba23 explains this better than I do in this post, where a user had similar issues to yours. This could be a start to solve your issue. Good luck "I think you are searching a bug where there is no bug... don't listen to bad advice."
mr-es335 Posted Sunday at 10:38 PM Author Posted Sunday at 10:38 PM Thanks, pixelsearch. Sad-to-say, the discussion is way above my understanding. Is the following workable? expandcollapse popup; ----------------------------------------------- #include <FontConstants.au3> #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> ; ----------------------------------------------- Opt("GUIOnEventMode", 1) ; ----------------------------------------------- Global $g_hGUI2, $g_idButton2 Global $sFontName = "Corbel Bold", $iFontSize = 16, $iFontWt = 800 ; ----------------------------------------------- gui1() ; ----------------------------------------------- Func gui1() Local $iFontSize = 14 ; ----------------- Local $hGUI1 = GUICreate("Main GUI", 250, 40, 825, 110, $WS_POPUP, $WS_EX_TOPMOST) GUISetFont($iFontSize, $iFontWt, $GUI_FONTNORMAL, $sFontName) GUISetBkColor(0x3D3D3D) ; ----------------------------------------------- Local $idButton1 = GUICtrlCreateLabel("Item 1", 0, 10, 100, 25, $SS_CENTER) GUICtrlSetColor(-1, 0xFFFFFF) GUICtrlSetOnEvent($idButton1, "On_Button1") ; ----------------- Local $idButton2 = GUICtrlCreateLabel("Item 2", 75, 10, 100, 25, $SS_CENTER) GUICtrlSetColor(-1, 0xFFFFFF) GUICtrlSetOnEvent(-1, "On_Button2") ; ----------------- Local $idButton3 = GUICtrlCreateLabel("Exit", 150, 10, 100, 25, $SS_CENTER) GUICtrlSetColor(-1, 0xFFFFFF) GUICtrlSetOnEvent(-1, "On_Button3") ; ----------------------------------------------- GUISetState(@SW_SHOW, $hGUI1) ; ----------------------------------------------- While 1 Sleep(10) WEnd EndFunc ;==>gui1 ; ----------------------------------------------- ; ----------------------------------------------- Func On_Button1() ConsoleWrite("@GUI_CtrlId=" & @GUI_CtrlId & @CRLF) MsgBox($MB_OK, "Item 1", "Item 1 was selected...", 1) EndFunc ;==>On_Button1 ; ----------------------------------------------- Func On_Button2() ConsoleWrite("@GUI_CtrlId=" & @GUI_CtrlId & @CRLF) MsgBox($MB_OK, "Item 2", "Item 2 was selected...", 1) EndFunc ;==>On_Button3 ; ----------------------------------------------- Func On_Button3() ConsoleWrite("@GUI_CtrlId=" & @GUI_CtrlId & @CRLF) MsgBox($MB_OK, "Item 3", "Exiting...",1) Exit EndFunc ;==>On_Button3 ; ----------------------------------------------- mr-es335 Sentinel Music Studios
pixelsearch Posted Sunday at 11:22 PM Posted Sunday at 11:22 PM 42 minutes ago, mr-es335 said: Is the following workable? Sure it is, as you don't delete/recreate GUI's during the script, which means all controls variables values will be different. 43 minutes ago, mr-es335 said: Sad-to-say, the discussion is way above my understanding One important point in the discussion is : take care of your variable values if these variables correspond to controls that have been deleted (because you deleted their GUI) For example, your initial script could be amended like this, by adding 2 lines in this function : Func _CloseForm() Switch @GUI_WinHandle Case $Form1 MsgBox($MB_OK, "GUI Event", "You selected CLOSE in the main window! Exiting...", 1) Exit Case $sLabel1 GUIDelete(@GUI_WinHandle) $sOption1Label = 0 ; force this control variable value to 0, because its GUI is deleted <=============== GUICtrlSetState($sCol1Row1, $GUI_ENABLE) Case $sLabel2 GUIDelete(@GUI_WinHandle) $sOption2Label = 0 ; force this control variable value to 0, because its GUI is deleted <=============== GUICtrlSetState($sCol1Row2, $GUI_ENABLE) EndSwitch EndFunc ;==>_CloseForm Now your 1st script should run correctly, even if you choose "Option 1" then "Option 2" mr-es335 1 "I think you are searching a bug where there is no bug... don't listen to bad advice."
mr-es335 Posted Monday at 12:01 AM Author Posted Monday at 12:01 AM (edited) pixelsearch, Thanks...and marked!!! Is this amendment, the "logical" way to proceed? "Other" "CloseForm()" examples, do NOT appear to employ such an "amendment"? PS: At present I am dissecting ioa747's previous OnEventMode sampling...in an attempt "...to get my head around it..." Edited Monday at 12:55 AM by mr-es335 mr-es335 Sentinel Music Studios
pixelsearch Posted Monday at 01:35 AM Posted Monday at 01:35 AM 1 hour ago, mr-es335 said: Is this amendment, the "logical" way to proceed? No it is not, but as you're using global variables for your control id's AND these variables (which can correspond to deleted controls) are tested in other functions, like _ColRow() , then you have to find a way to forget their values when their GUI's are deleted (if you want to keep this style of scripting) In fact, instead of constantly deleting/recreating your GUI's, then you could create them only once, then hide them (instead of deleting them) . Doing so would assign an increasing control ID value to each control, no matter the GUI where this control lies. That's what Melba23 recommends in his discussion (link in my 1st post) "I think you are searching a bug where there is no bug... don't listen to bad advice."
mr-es335 Posted Monday at 02:23 AM Author Posted Monday at 02:23 AM (edited) pixelsearch, What you, and Melba, are stating is, indeed, both a practicable and logical methodology to abide by. Is it possible to provide a simple two GUI example - with a _Close_Form function, so that I dissect such in order to learn more about this methodology? Any assistance here would be - believe me, greatly appreciated! To [hopefully] demonstrate that I have NOT been idle, have a peep at the following: expandcollapse popup; ----------------------------------------------- #RequireAdmin ; ----------------------------------------------- #include <AutoItConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <MsgBoxConstants.au3> ; ----------------------------------------------- Opt("GUIOnEventMode", 1) ; ----------------------------------------------- Global $Form1, $sCol1Row1, $sCol1Row2 Global $sLabelA, $sColRowA ; ----------------------------------------------- Form1() ; ----------------------------------------------- Func Form1() $Form1 = GUICreate("", 235, 75) GUISetFont(14, 800, 0, "Calibri") ; ----------------------------------------------- GUISetOnEvent($GUI_EVENT_CLOSE, "_CloseForm") ; ----------------------------------------------- $sCol1Row1 = GUICtrlCreateButton("Item 1", 10, 10, 215, 25) GUICtrlSetOnEvent($sCol1Row1, "Item1") $sCol1Row2 = GUICtrlCreateButton("Item 2", 10, 40, 215, 25) GUICtrlSetOnEvent($sCol1Row2, "Item2") ; ----------------------------------------------- GUISetState(@SW_SHOW, $Form1) ; ----------------------------------------------- While 1 Sleep(40) WEnd EndFunc ;==>Form1 ; ----------------------------------------------- Func Item1() MsgBox($MB_OK, "", "You selected Item 1...", 1) EndFunc ;==>Item1 ; ----------------------------------------------- Func Item2() $sLabelA = GUICreate("", 250, 23, 620, 48, $WS_POPUP, $WS_EX_TOPMOST) GUISetFont(14, 800, 0, "Calibri") GUISetBkColor(0x3D3D3D) GUISetOnEvent($GUI_EVENT_CLOSE, "_CloseForm") ; ----------------------------------------------- $sColRowA = GUICtrlCreateLabel("You have selected Item 2...", 0, 0, 250, 23, $SS_CENTER) GUICtrlSetColor(-1, 0xFFFFFF) GUICtrlSetOnEvent($sColRowA, "_ColRow") ; ----------------------------------------------- GUISetState(@SW_SHOW) GUICtrlSetState($sCol1Row2, $GUI_DISABLE) EndFunc ;==>Item2 ; ----------------------------------------------- Func _ColRow() ConsoleWrite("@GUI_CtrlId=" & @GUI_CtrlId & @CRLF) Switch @GUI_CtrlId Case $sColRowA WinClose($sLabelA) EndSwitch EndFunc ;==>_ColRow ; ----------------------------------------------- Func _CloseForm() ConsoleWrite("@GUI_CtrlId=" & @GUI_CtrlId & @CRLF) Switch @GUI_WinHandle Case $Form1 MsgBox($MB_OK, "GUI Event", "You selected [X] in the main window! Exiting...", 1) Exit Case $sLabelA GUIDelete(@GUI_WinHandle) GUICtrlSetState($sCol1Row2, $GUI_ENABLE) EndSwitch EndFunc ;==>_CloseForm ; ----------------------------------------------- Edited Monday at 02:27 AM by mr-es335 mr-es335 Sentinel Music Studios
Solution pixelsearch Posted Monday at 04:25 AM Solution Posted Monday at 04:25 AM 2 hours ago, mr-es335 said: Is it possible to provide a simple two GUI example - with a _Close_Form function, so that I dissect such in order to learn more about this methodology? Any assistance here would be - believe me, greatly appreciated! I did that in the script below, based on your initial script : * The 3 GUI's are created only once * The "option 2" GUI got a Close button (no $WS_POPUP style) just to indicate that it is possible, when you click its Close button, to hide the GUI without closing/deleting the GUI * That's why you'll find similar parts of code in both functions _ColRow() when you click a label, and _CloseForm (when you click a GUI Close button) : "similar parts of code" means hide a GUI but don't close/delete it (except for the main GUI which normally exits when you click its Close button) expandcollapse popup; ----------------------------------------------- #RequireAdmin ; ----------------------------------------------- #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <MsgBoxConstants.au3> ; ----------------------------------------------- Opt("GUIOnEventMode", 1) ; ----------------------------------------------- Global $Form1, $sCol1Row1, $sCol1Row2 Global $sLabel1, $sOption1Label Global $sLabel2, $sOption2Label ; ----------------------------------------------- Forms() ; ----------------------------------------------- Func Forms() $Form1 = GUICreate("", 235, 75) GUISetFont(14, 800, 0, "Calibri") GUISetOnEvent($GUI_EVENT_CLOSE, "_CloseForm") $sCol1Row1 = GUICtrlCreateButton("For Option 1", 10, 10, 215, 25) GUICtrlSetOnEvent($sCol1Row1, "Option1") $sCol1Row2 = GUICtrlCreateButton("For Option 2", 10, 40, 215, 25) GUICtrlSetOnEvent($sCol1Row2, "Option2") ; ----------------------------------------------- $sLabel1 = GUICreate("", 75, 23, 620, 48, $WS_POPUP, $WS_EX_TOPMOST) GUISetFont(14, 800, 0, "Calibri") GUISetBkColor(0x3D3D3D) GUISetOnEvent($GUI_EVENT_CLOSE, "_CloseForm") $sOption1Label = GUICtrlCreateLabel("Option 1", 0, 0, 75, 23, $SS_CENTER) GUICtrlSetColor(-1, 0xFFFFFF) GUICtrlSetOnEvent($sOption1Label, "_ColRow") ; ----------------------------------------------- $sLabel2 = GUICreate("", 75, 23, 620, 48, -1, $WS_EX_TOPMOST) GUISetFont(14, 800, 0, "Calibri") GUISetBkColor(0x3D3D3D) GUISetOnEvent($GUI_EVENT_CLOSE, "_CloseForm") $sOption2Label = GUICtrlCreateLabel("Option 2", 0, 0, 75, 23, $SS_CENTER) GUICtrlSetColor(-1, 0xFFFFFF) GUICtrlSetOnEvent($sOption2Label, "_ColRow") ; ----------------------------------------------- GUISwitch($Form1) GUISetState(@SW_SHOW) While 1 Sleep(10) WEnd EndFunc ;==>Forms ; ----------------------------------------------- Func Option1() GUICtrlSetState($sCol1Row1, $GUI_DISABLE) GUISwitch($sLabel1) GUISetState(@SW_SHOW) EndFunc ;==>Option1 ; ----------------------------------------------- Func Option2() GUICtrlSetState($sCol1Row2, $GUI_DISABLE) GUISwitch($sLabel2) GUISetState(@SW_SHOW) EndFunc ;==>Option2 ; ----------------------------------------------- Func _ColRow() ; ConsoleWrite("@GUI_CtrlId=" & @GUI_CtrlId & @CRLF) Switch @GUI_CtrlId Case $sOption1Label GUISetState(@SW_HIDE, $sLabel1) GUISwitch($Form1) GUICtrlSetState($sCol1Row1, $GUI_ENABLE) Case $sOption2Label GUISetState(@SW_HIDE, $sLabel2) GUISwitch($Form1) GUICtrlSetState($sCol1Row2, $GUI_ENABLE) EndSwitch EndFunc ;==>_ColRow ; ----------------------------------------------- Func _CloseForm() Switch @GUI_WinHandle Case $Form1 MsgBox($MB_OK, "GUI Event", "You selected CLOSE in the main window! Exiting...", 1) Exit Case $sLabel1 GUISetState(@SW_HIDE, $sLabel1) GUISwitch($Form1) GUICtrlSetState($sCol1Row1, $GUI_ENABLE) Case $sLabel2 GUISetState(@SW_HIDE, $sLabel2) GUISwitch($Form1) GUICtrlSetState($sCol1Row2, $GUI_ENABLE) EndSwitch EndFunc ;==>_CloseForm Hope it helps mr-es335 1 "I think you are searching a bug where there is no bug... don't listen to bad advice."
mr-es335 Posted Monday at 12:35 PM Author Posted Monday at 12:35 PM (edited) pixelsearch, A couple of "things"... 1) Thank you so very, very much. Both you and ioa747 have been instrumental in assisting me and my "un-Vulcanized" brain to at least - in some minuscule manner, of being to understand, at least in some small part, what endeavor you happen to be assisting me with at any particular time. 2) The 3GUI example is based on a one provided by ioa747 - so I cannot take ALL the credit for that one - if indeed, any credit can be rightly assumed. 3) The example you have provided is "very clean and top-down" - which I am sure would make Melba very happy. • The example is also very easy to understand - which is appreciated. I thank you again, pixelsearch, for your time, attention and efforts on my behalf. Both are very much appreciated! PS: I have updated the "Solution" to your final offering! Edited Monday at 12:37 PM by mr-es335 pixelsearch 1 mr-es335 Sentinel Music Studios
mr-es335 Posted Monday at 02:04 PM Author Posted Monday at 02:04 PM (edited) pixelsearch, As I will be implementing labels instead of buttons, I have updated specific portions for your initial script. Here is my sampling: Spoiler expandcollapse popup#cs From pixelsearch...with gratitude! Removed any-and-all font references Updated label height from 23 to 15 Added SplashTextOn function to Labels Added 3rd option, for exiting MainForms() • Added an Exit to this function. Commented out GUISetOnEvent($GUI_EVENT_CLOSE, "_CloseForm") for labels as these are not required here. Commented out Case $sOption1#LabelGUI as these are no longer required as well. #ce ; ----------------------------------------------- #RequireAdmin ; ----------------------------------------------- #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <MsgBoxConstants.au3> ; ----------------------------------------------- Opt("GUIOnEventMode", 1) ; ----------------------------------------------- Global $Form1, $sCol1Row1, $sCol1Row2, $sCol1Row3 Global $sOption1LabelGUI, $sOption1Label Global $sOption2LabelGUI, $sOption2Label Global $sOption3LabelGUI, $sOption3Label ; ----------------------------------------------- MainForms() ; ----------------------------------------------- Func MainForms() $Form1 = GUICreate("", 235, 105) GUISetOnEvent($GUI_EVENT_CLOSE, "_CloseForm") $sCol1Row1 = GUICtrlCreateButton("For Option 1", 10, 10, 215, 25) GUICtrlSetOnEvent($sCol1Row1, "Option1") $sCol1Row2 = GUICtrlCreateButton("For Option 2", 10, 40, 215, 25) GUICtrlSetOnEvent($sCol1Row2, "Option2") $sCol1Row3 = GUICtrlCreateButton("For Option 3", 10, 70, 215, 25) GUICtrlSetOnEvent($sCol1Row3, "Option3") ; ----------------------------------------------- $sOption1LabelGUI = GUICreate("", 75, 15, 620, 48, $WS_POPUP, $WS_EX_TOPMOST) ;~ GUISetOnEvent($GUI_EVENT_CLOSE, "_CloseForm") $sOption1Label = GUICtrlCreateLabel("Option 1", 0, 0, 75, 15, $SS_CENTER) GUICtrlSetOnEvent($sOption1Label, "_ColRow") ; ----------------------------------------------- $sOption2LabelGUI = GUICreate("", 75, 15, 620, 48, $WS_POPUP, $WS_EX_TOPMOST) ;~ GUISetOnEvent($GUI_EVENT_CLOSE, "_CloseForm") $sOption2Label = GUICtrlCreateLabel("Option 2", 0, 0, 75, 15, $SS_CENTER) GUICtrlSetOnEvent($sOption2Label, "_ColRow") ; ----------------------------------------------- $sOption3LabelGUI = GUICreate("", 75, 15, 620, 48, $WS_POPUP, $WS_EX_TOPMOST) ;~ GUISetOnEvent($GUI_EVENT_CLOSE, "_CloseForm") $sOption3Label = GUICtrlCreateLabel("Option 3", 0, 0, 75, 15, $SS_CENTER) GUICtrlSetOnEvent($sOption3Label, "_ColRow") ; ----------------------------------------------- GUISwitch($Form1) GUISetState(@SW_SHOW) While 1 Sleep(10) WEnd EndFunc ;==>MainForms ; ----------------------------------------------- Func Option1() GUICtrlSetState($sCol1Row1, $GUI_DISABLE) GUISwitch($sOption1LabelGUI) GUISetState(@SW_SHOW) EndFunc ;==>Option1 ; ----------------------------------------------- Func Option2() GUICtrlSetState($sCol1Row2, $GUI_DISABLE) GUISwitch($sOption2LabelGUI) GUISetState(@SW_SHOW) EndFunc ;==>Option2 ; ----------------------------------------------- Func Option3() GUICtrlSetState($sCol1Row3, $GUI_DISABLE) GUISwitch($sOption3LabelGUI) GUISetState(@SW_SHOW) EndFunc ;==>Option3 ; ----------------------------------------------- Func _ColRow() ConsoleWrite("@GUI_CtrlId=" & @GUI_CtrlId & @CRLF) Switch @GUI_CtrlId Case $sOption1Label GUISetState(@SW_HIDE, $sOption1LabelGUI) Option1Selected() GUISwitch($Form1) GUICtrlSetState($sCol1Row1, $GUI_ENABLE) Case $sOption2Label GUISetState(@SW_HIDE, $sOption2LabelGUI) Option2Selected() GUISwitch($Form1) GUICtrlSetState($sCol1Row2, $GUI_ENABLE) Case $sOption3Label GUISetState(@SW_HIDE, $sOption3LabelGUI) Option3Selected() GUISwitch($Form1) GUICtrlSetState($sCol1Row3, $GUI_ENABLE) EndSwitch EndFunc ;==>_ColRow ; ----------------------------------------------- Func Option1Selected() Local $sMessage = "Option 1 Selected..." & @CRLF & @CRLF, $iWidth = 350, $iHeight = 45 Local $iOpt = 1, $sFontName = "FuturaBQ-DemiBold", $iFontSize = 14 ; ----------------------------------------------- SplashTextOn("", $sMessage, $iWidth, $iHeight, -1, 400, $iOpt, $sFontName, $iFontSize) Sleep(1000) SplashOff() EndFunc ;==>Option1Selected ; ----------------------------------------------- Func Option2Selected() Local $sMessage = "Option 2 Selected..." & @CRLF & @CRLF, $iWidth = 350, $iHeight = 45 Local $iOpt = 1, $sFontName = "FuturaBQ-DemiBold", $iFontSize = 14 ; ----------------------------------------------- SplashTextOn("", $sMessage, $iWidth, $iHeight, -1, 400, $iOpt, $sFontName, $iFontSize) Sleep(1000) SplashOff() EndFunc ;==>Option2Selected ; ----------------------------------------------- Func Option3Selected() Local $sMessage = "Option 3 Selected...and exiting..." & @CRLF & @CRLF, $iWidth = 350, $iHeight = 45 Local $iOpt = 1, $sFontName = "FuturaBQ-DemiBold", $iFontSize = 14 ; ----------------------------------------------- SplashTextOn("", $sMessage, $iWidth, $iHeight, -1, 400, $iOpt, $sFontName, $iFontSize) Sleep(1000) SplashOff() ; ----------------------------------------------- ;~ Exit MainForms() GUIDelete() Exit EndFunc ;==>Option3Selected ; ----------------------------------------------- Func _CloseForm() Switch @GUI_WinHandle Case $Form1 MsgBox(0, "", "Exiting Main...", 1) Exit #cs Case $sOption1LabelGUI GUISetState(@SW_HIDE, $sOption1LabelGUI) GUISwitch($Form1) GUICtrlSetState($sCol1Row1, $GUI_ENABLE) Case $sOption2LabelGUI GUISetState(@SW_HIDE, $sOption2LabelGUI) GUISwitch($Form1) GUICtrlSetState($sCol1Row2, $GUI_ENABLE) Case $sOption3LabelGUI GUISetState(@SW_HIDE, $sOption3LabelGUI) GUISwitch($Form1) #ce GUICtrlSetState($sCol1Row3, $GUI_ENABLE) EndSwitch EndFunc ;==>_CloseForm ; ----------------------------------------------- My query is with Func Option3Selected()...is this an appropriate means of exiting the script? Thanks again! PS: I have 7 children. When the wife or I did anything "nice" for the children, they would then say, "Thank you! Thank you! Thank you! Not enough Thank you's!"...repeating the phrase some 3 times. Seems appropriate here!! Edited Monday at 02:11 PM by mr-es335 mr-es335 Sentinel Music Studios
pixelsearch Posted Monday at 03:51 PM Posted Monday at 03:51 PM 1 hour ago, mr-es335 said: My query is with Func Option3Selected()...is this an appropriate means of exiting the script? I won't use Option3Selected() to exit the script. Of course you could do it that way as the keyword "Exit" will exit the script from anywhere, but as you already got the Close button in the main GUI that exits, then why adding an additional exit way elsewhere ? Just use the Option3Selected() in the same way you used Option1Selected() and Option2Selected() , to accomplish a particular task. When this task ends, then you'll simply use the main GUI Close button to exit and end the script. "I think you are searching a bug where there is no bug... don't listen to bad advice."
mr-es335 Posted Monday at 04:40 PM Author Posted Monday at 04:40 PM (edited) pixelsearch, What if I am implementing $WS_POPUP" for the main GUI? Thus, no [X] option. The main GUI will implement 3 options, two for application-specific functions, and 1 option for exit...unless there is another way of accomplishing the later. $GUI_EVENT_CLOSE - dialog box being closed (either by defined button or system menu). • I would assume that "system menu" would refer to [X]? Edited Monday at 04:45 PM by mr-es335 mr-es335 Sentinel Music Studios
pixelsearch Posted Monday at 06:01 PM Posted Monday at 06:01 PM 1 hour ago, mr-es335 said: What if I am implementing $WS_POPUP" for the main GUI? Thus, no [X] option. Of course if there is no [X] option in the main GUI, then you need another option to quit. Then the 3rd label could do the job. mr-es335 1 "I think you are searching a bug where there is no bug... don't listen to bad advice."
mr-es335 Posted Monday at 11:31 PM Author Posted Monday at 11:31 PM Good day, One last "thing"...what is the purpose|reasoning behind the implementation of the "underscore" before the function name - for example, "_CloseForm"? mr-es335 Sentinel Music Studios
mr-es335 Posted yesterday at 03:16 PM Author Posted yesterday at 03:16 PM ...ooooppppssss... An example with comments...some do require further explanation...if at all possible... [⚠ <<<<==== Explain! ====>>>> ⚠] Spoiler expandcollapse popup; ----------------------------------------------- #RequireAdmin ; ----------------------------------------------- #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <MsgBoxConstants.au3> ; ----------------------------------------------- Opt("GUIOnEventMode", 1) ; ----------------------------------------------- Global $Form1, $sCol1Row1, $sCol1Row2 Global $Form2, $sGUI2Button Global $Form3, $sGUI3Button ; ----------------------------------------------- ;~ 1a) This script consists of 3 forms, $Form1, $Form2 and $Form3. ;~ 1b) Launching the script, launches $Form1. ;~ 1c) REMEMBER: All Forms are to be created first, with each Form ;~ being diplayed or hidden when-and-where required. Forms() ; ----------------------------------------------- ; ----------------------------------------------- Func Forms() ;~ 2a) $Form1 is created $Form1 = GUICreate("Form1", 235, 75) ;~ 2b) As noted: Defines a user function to be called when a [system button] is clicked. ;~ • The called user function is [_CloseForm] ;~ • The [system button] that is invoked here is the [X] window control GUISetOnEvent($GUI_EVENT_CLOSE, "_CloseForm") ; ----------------- ;~ 2c) The $Form1 button, Button 1 is created $sCol1Row1 = GUICtrlCreateButton("Form1 Button 1", 10, 10, 215, 25) ;~ 2d) As noted: "Defines a user-defined function to be called when a [control] is clicked." ;~ • The called user function is [_Form1Button1] ;~ • The [control] that is invoked here is the $Form1 button GUICtrlSetOnEvent($sCol1Row1, "_Form1Button1") ; ----------------- ;~ 2e) The $Form1 button, Button 2 is created $sCol1Row2 = GUICtrlCreateButton("Form1 Button 2", 10, 40, 215, 25) ;~ See: 2#) above. GUICtrlSetOnEvent($sCol1Row2, "_Form1Button2") ; ----------------------------------------------- ; ----------------------------------------------- ;~ 3a) $Form2 is created $Form2 = GUICreate("Form2", 150, 25, -1, 400) ;~ See: 2b) above. ;~ • User function: [_CloseForm] ;~ • [system button]: [X] GUISetOnEvent($GUI_EVENT_CLOSE, "_CloseForm") ; ----------------- ;~ 3b) The $Form2 button is created $sGUI2Button = GUICtrlCreateButton("Form2 Button", 0, 0, 75, 23) ;~ See: 2d) above. ;~ • User function: [_ColRow] ;~ • [control]: $Form2 button GUICtrlSetOnEvent($sGUI2Button, "_ColRow") ; ----------------------------------------------- ;~ 3c) $Form3 is created $Form3 = GUICreate("Form3", 150, 25, -1, 400) ;~ See: 2b) above. ;~ • User function: [_CloseForm] ;~ • [system button]: [X] GUISetOnEvent($GUI_EVENT_CLOSE, "_CloseForm") ; ----------------- ;~ 3d) The $Form3 button is created $sGUI3Button = GUICtrlCreateButton("Form3 Button", 0, 0, 75, 23) ;~ See: 2d) above. ;~ • User function: [_ColRow] ;~ • [control]: $Form3 button GUICtrlSetOnEvent($sGUI3Button, "_ColRow") ; ----------------------------------------------- ; ----------------------------------------------- ;~ 4a) $Form1 is made the [current] window GUISwitch($Form1) ;~ 4b) $Form1 is then displayed GUISetState(@SW_SHOW) ;~ 4c) While|WEnd is provied to reduce CPU cycles?? ⚠ <<<<==== Explain! ====>>>> ⚠ ;~ Just idle around While 1 Sleep(10) WEnd EndFunc ;==>Forms ; ----------------------------------------------- ; ----------------------------------------------- #cs 5) NOT TOO SURE WHAT OCCURS HERE!!! ⚠ <<<<==== Explain! ====>>>> ⚠ a) What do we know? b) That the $Form1 button was previously created c) The _Form1Button1 function was previously called by $Form1 d) Thus, these functions must provide the [action] that will be implemented when a specfic [control] is selected. #ce ; ----------------------------------------------- Func _Form1Button1() ;~ 6a) When the $Form1 button is invoked, the [state] of the button text is disabled. ;~ • This state is required so as not to be able to invoke that control a subsequent time. GUICtrlSetState($sCol1Row1, $GUI_DISABLE) ;~ 6b) $Form2 is made the [current] window GUISwitch($Form2) ;~ 6c) $Form1 is then displayed GUISetState(@SW_SHOW) EndFunc ;==>_Form1Button1 ; ----------------------------------------------- ;~ 7) See 6a) to 6c) above Func _Form1Button2() GUICtrlSetState($sCol1Row2, $GUI_DISABLE) GUISwitch($Form3) GUISetState(@SW_SHOW) EndFunc ;==>_Form1Button2 ; ----------------------------------------------- ; ----------------------------------------------- #cs 8) AGAIN, NOT TOO SURE WHAT OCCURS HERE!!! ⚠ <<<<==== Explain! ====>>>> ⚠ a) What do we know? b) This is the user function called by the invocation of the $Form2 button [control] and the $Form3 button [control] c) As noted, the @GUI_CtrlId macro: Last click GUI Control identifier. Only valid in an event Function. #ce ; ----------------------------------------------- Func _ColRow() ;~ ConsoleWrite("@GUI_CtrlId=" & @GUI_CtrlId & @CRLF) ;~ 9a) What has been ascertained by the ConsoleWrite statement above: ;~ @GUI_CtrlId=5: The invocation of the $Form2 button ;~ @GUI_CtrlId=6: The invocation of the $Form3 button Switch @GUI_CtrlId ;~ 9c) The CtrlId of the $Form# button that was last selected, will be made ;~ the [current] window - being either $Form2 or $Form3 Case $sGUI2Button ;~ ConsoleWrite("From 3b) above" & @CRLF) ;~ 9d) The $Form2 button was selected ;~ 9e) $Form2 is hidden - thus $Form2 must have bee exited somehow?!? ⚠ <<<<==== Explain! ====>>>> ⚠ ;~ 9f) Must be the result of the $Form2 button being invoked GUISetState(@SW_HIDE, $Form2) ;~ 9g) $Form1 is displayed - though not too sure how exactly, ;~ but is logical based on the above GUISetState(@SW_HIDE, $Form2) statement ⚠ <<<<==== Explain! ====>>>> ⚠ GUISwitch($Form1) ;~ 9h) $Form1 Button text is enabled [logical] GUICtrlSetState($sCol1Row1, $GUI_ENABLE) Case $sGUI3Button ;~ ConsoleWrite("From 3d) above" & @CRLF) ;~ See 9a) to 9h) above GUISetState(@SW_HIDE, $Form3) GUISwitch($Form1) GUICtrlSetState($sCol1Row2, $GUI_ENABLE) EndSwitch EndFunc ;==>_ColRow ; ----------------------------------------------- #cs 10) AGAIN, NOT TOO SURE WHAT OCCURS HERE!!! ⚠ <<<<==== Explain! ====>>>> ⚠ a) What do we know? b) This is the user function called by the invocation of the $Form# [system button] - that being the [X] #ce ; ----------------------------------------------- Func _CloseForm() Switch @GUI_WinHandle Case $Form1 ;~ 11a) The $Form1 [control] was selected ;~ 11b) The message beign displayed upon exit MsgBox($MB_OK, "Exit Main Form", "Exiting...", 1) ;~ 11c) The exit statment, thus, terminating the script Exit Case $Form2 ;~ 11c) See: 11a) above ;~ 11d) What is occuring here is identical to that which occured in the ⚠ <<<<==== Explain! ====>>>> ⚠ ;~ [_ColRow] function, see 9a), Thus, the explantion provided there ;~ will suffice here! GUISetState(@SW_HIDE, $Form2) GUISwitch($Form1) GUICtrlSetState($sCol1Row1, $GUI_ENABLE) Case $Form3 ;~ 11#) See: 11a) above GUISetState(@SW_HIDE, $Form3) GUISwitch($Form1) GUICtrlSetState($sCol1Row2, $GUI_ENABLE) EndSwitch EndFunc ;==>_CloseForm ; ----------------------------------------------- mr-es335 Sentinel Music Studios
pixelsearch Posted yesterday at 03:21 PM Posted yesterday at 03:21 PM (edited) 15 hours ago, mr-es335 said: One last "thing"...what is the purpose|reasoning behind the implementation of the "underscore" before the function name - for example, "_CloseForm"? My guess is that adding an underscore at the beginning of a function name allows you to quickly differentiate what follows : 1) AutoIt native functions (Jon's functions) No underscore at the beginning of their names, for example Beep, Exit, FileReadToArray etc... These native functions are not part of any AutoIt include file. 2) User defined functions (the "rest of the world" functions) Good idea to start their name with an underscore, just to quickly differentiate them from 1) For example _ArrayDisplay (found in an AutoIt include file) , _Exit (you could create this function) , _FileReadToArray (found in an AutoIt include file) Now you can see there is a big difference between FileReadToArray (Jon's) and _FileReadToArray (found in an AutoIt include file) . So it's a good idea to create your personal function named _CloseForm, in case Jon already got a native function named CloseForm ! Also don't forget this point : what if Jon creates a native function named "CloseForm" in a future AutoIt release ? Then your script won't work anymore [if you also used "CloseForm"] with this error : "CloseForm() already defined." Theorically, all users functions should be created starting with an underscore : it would make their script easily readable because : 1) If you read their script and find a function name without an underscore, then you will be 100% sure it's an AutoIt native function. 2) If you find a function name starting with an underscore, then you are sure it's part of an include file OR you just added it in your script (for ex. _CloseForm) Now the remaining question could be : "what if I create a function name starting with an underscore but this name and its underscore already exists in an include file ?" Edited yesterday at 03:25 PM by pixelsearch typo mr-es335 1 "I think you are searching a bug where there is no bug... don't listen to bad advice."
mr-es335 Posted yesterday at 04:09 PM Author Posted yesterday at 04:09 PM pixelsearch, You stated, "Now the remaining question could be: 'what if I create a function name starting with an underscore but this name and its underscore already exists in an include file ?' " Does this happen, and if so, how often? Possible solution, as further underscore, thus, __CloseForm(), or the implementation of some other "legal" character. mr-es335 Sentinel Music Studios
argumentum Posted yesterday at 05:10 PM Posted yesterday at 05:10 PM 1 hour ago, mr-es335 said: thus, __CloseForm() we use double underscore "__" to mark as non-user function. Something internal. Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
pixelsearch Posted yesterday at 06:15 PM Posted yesterday at 06:15 PM 1 hour ago, mr-es335 said: Does this happen, and if so, how often? No big deal, just make it simple : use a single underscore, check the help file (while scripting) to make sure the name with underscore doesn't already exists. And if you don't check the help file, then you'll always got one of these 2 errors, for example with this silly script ! #include <Array.au3> Func _ArrayDisplay($aArray) EndFunc * Au3Check (when saving your script) => error: _ArrayDisplay() already defined. * Then if you run the script => Duplicate function name : _ArrayDisplay() 2 hours ago, mr-es335 said: 4c) While|WEnd is provided to reduce CPU cycles?? No, the loop While...WEnd is provided so the script doesn't end immediately ! Try to comment out the While...WEnd loop and see what happens : $Form1 will be displayed a couple of ms then the script ends. This While...WEnd loop is an endless loop and you're "stuck" inside it while the script is running (when no event is triggered, for example clicking a button etc...) . Just add a counter inside it to see how it goes : Local $iCount = 0 While 1 $iCount +=1 ConsoleWrite($iCount & @CRLF) Sleep(10) ; prevents hogging all the CPU (+++) WEnd See how the counter constantly increases in the Console ? It shows that you're stuck inside this loop (as ConsoleWrite is constantly called) until you choose to exit the script. 2 hours ago, mr-es335 said: Func ...() EndFunc #cs 5) NOT TOO SURE WHAT OCCURS HERE!!! 8) AGAIN, NOT TOO SURE WHAT OCCURS HERE!!! 10) AGAIN, NOT TOO SURE WHAT OCCURS HERE!!! #ce Func ...() EndFunc What do you expect that could happen between functions ? Nothing. When a function ends (EndFunc) then as showed before, you're stuck in the While...WEnd loop, waiting for another event to occur (user closes a GUI, presses a button etc...) 2 hours ago, mr-es335 said: 9e) $Form2 is hidden - thus $Form2 must have been exited somehow?!? $Form2 is hidden because of this line which immediately follows your "9e" comment : GUISetState(@SW_HIDE, $Form2) You don't have to "exit" a window to hide it, you can simply apply a line of code, anywhere in your script, to hide it : that's the purpose of GUISetState(@SW_HIDE, $Form2) In this script (unfortunately) clicking buttons in Form2 and Form3 have the same effect than clicking the {X] button to close their GUI's . It would be better to add some "real action" that will happen when you click the buttons, instead of simply mimicking a Windows Close when you click the buttons. But you'll certainly do this in your final project. 2 hours ago, mr-es335 said: 9g) $Form1 is displayed - though not too sure how exactly, but is logical based on the above GUISetState(@SW_HIDE, $Form2) statement GUISetState(@SW_HIDE, $Form2) has nothing to do with the fact that $Form1 is displayed because GUISetState(@SW_HIDE, $Form2) simply hides $Form2, no more, no less. In this script, $Form1 is never hidden but it may be covered by other windows and we probably would like, when needed, to make $Form1 not only "current" (GUISwitch) but also "active" (on top, with focus) using WinActivate (as correctly stated in the help file, topic GUISwitch) To achieve this, I suggest these modifications in functions _ColRow and _CloseForm : Func _ColRow() Switch @GUI_CtrlId Case $sGUI2Button GUISetState(@SW_HIDE, $Form2) GUICtrlSetState($sCol1Row1, $GUI_ENABLE) Case $sGUI3Button GUISetState(@SW_HIDE, $Form3) GUICtrlSetState($sCol1Row2, $GUI_ENABLE) EndSwitch GUISwitch($Form1) If Not WinActive($Form1) Then WinActivate($Form1) EndFunc ;==>_ColRow Func _CloseForm() Switch @GUI_WinHandle Case $Form1 MsgBox($MB_OK, "Exit Main Form", "Exiting...", 1) Exit Case $Form2 GUISetState(@SW_HIDE, $Form2) GUICtrlSetState($sCol1Row1, $GUI_ENABLE) Case $Form3 GUISetState(@SW_HIDE, $Form3) GUICtrlSetState($sCol1Row2, $GUI_ENABLE) EndSwitch GUISwitch($Form1) If Not WinActive($Form1) Then WinActivate($Form1) EndFunc ;==>_CloseForm This will activate $Form1 if it was covered by another window, when you click on buttons or close Form2 / Form3 Of course, if you intentionally minimized $Form1 then it won't have any effect. In this case ($Form1 minimized by the user) then it requires an additional line of code. Hope I answered all your questions, time to rest... mr-es335 and Musashi 1 1 "I think you are searching a bug where there is no bug... don't listen to bad advice."
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