baconaise Posted December 1, 2020 Share Posted December 1, 2020 Greetings! Will someone please tell me why buttons 2-1 and 3-1 seem to respond as though they are button 1-1, and why buttons 2-2 and 3-2 seem to respond as though they are button 1-2? expandcollapse popup#include <AutoItConstants.au3> #include <MsgBoxConstants.au3> #include <GUIConstants.au3> Opt("GUIOnEventMode", 1) Func Create_Main_GUI() Global $Main_GUI = GUICreate("Main GUI", 200, 120) GUISetOnEvent($GUI_EVENT_CLOSE, "Exiting_Function") Global $Main_GUI_Button_1 = GUICtrlCreateButton("Main Button 1", 0, 0, 200, 40) GUICtrlSetOnEvent($Main_GUI_Button_1, "Do_Events_Specified_By_Which_Button_Was_Pushed") Global $Main_GUI_Button_2 = GUICtrlCreateButton("Main Button 2", 0, 40, 200, 40) GUICtrlSetOnEvent($Main_GUI_Button_2, "Do_Events_Specified_By_Which_Button_Was_Pushed") Global $Main_GUI_Button_3 = GUICtrlCreateButton("Main Button 3", 0, 80, 200, 40) GUICtrlSetOnEvent($Main_GUI_Button_3, "Do_Events_Specified_By_Which_Button_Was_Pushed") EndFunc Func Do_Events_Specified_By_Which_Button_Was_Pushed() Switch @GUI_CtrlId Case $Main_GUI_Button_1 Local $Mouse_Position = MouseGetPos() If Not WinExists("Secondary Selection Window") Then Global $Secondary_Selection_Window = GUICreate("Secondary Selection Window", 160, 69, $Mouse_Position[0] - 80, $Mouse_Position[1] - 10, $WS_POPUPWINDOW) Global $Kill_Secondary_Selection_Window = GUICtrlCreateButton("X", 0, 0, 160, 23) GUICtrlSetOnEvent($Kill_Secondary_Selection_Window, "Do_Events_Specified_By_Which_Button_Was_Pushed") Global $Secondary_Selection_Window_Choice_1_Spawned_From_Main_GUI_Button_1 = GUICtrlCreateButton("Choice 1-1", 0, 23, 160, 23) GUICtrlSetOnEvent($Secondary_Selection_Window_Choice_1_Spawned_From_Main_GUI_Button_1, "Do_Events_Specified_By_Which_Button_Was_Pushed") Global $Secondary_Selection_Window_Choice_2_Spawned_From_Main_GUI_Button_1 = GUICtrlCreateButton("Choice 1-2", 0, 46, 160, 23) GUICtrlSetOnEvent($Secondary_Selection_Window_Choice_2_Spawned_From_Main_GUI_Button_1, "Do_Events_Specified_By_Which_Button_Was_Pushed") WinSetOnTop($Secondary_Selection_Window, "", $WINDOWS_ONTOP) GUISetState(@SW_SHOW, $Secondary_Selection_Window) EndIf Case $Main_GUI_Button_2 Local $Mouse_Position = MouseGetPos() If Not WinExists("Secondary Selection Window") Then Global $Secondary_Selection_Window = GUICreate("Secondary Selection Window", 160, 69, $Mouse_Position[0] - 80, $Mouse_Position[1] - 10, $WS_POPUPWINDOW) Global $Kill_Secondary_Selection_Window = GUICtrlCreateButton("X", 0, 0, 160, 23) GUICtrlSetOnEvent($Kill_Secondary_Selection_Window, "Do_Events_Specified_By_Which_Button_Was_Pushed") Global $Secondary_Selection_Window_Choice_1_Spawned_From_Main_GUI_Button_2 = GUICtrlCreateButton("Choice 2-1", 0, 23, 160, 23) GUICtrlSetOnEvent($Secondary_Selection_Window_Choice_1_Spawned_From_Main_GUI_Button_2, "Do_Events_Specified_By_Which_Button_Was_Pushed") Global $Secondary_Selection_Window_Choice_2_Spawned_From_Main_GUI_Button_2 = GUICtrlCreateButton("Choice 2-2", 0, 46, 160, 23) GUICtrlSetOnEvent($Secondary_Selection_Window_Choice_2_Spawned_From_Main_GUI_Button_2, "Do_Events_Specified_By_Which_Button_Was_Pushed") WinSetOnTop($Secondary_Selection_Window, "", $WINDOWS_ONTOP) GUISetState(@SW_SHOW, $Secondary_Selection_Window) EndIf Case $Main_GUI_Button_3 Local $Mouse_Position = MouseGetPos() If Not WinExists("Secondary Selection Window") Then Global $Secondary_Selection_Window = GUICreate("Secondary Selection Window", 160, 69, $Mouse_Position[0] - 80, $Mouse_Position[1] - 10, $WS_POPUPWINDOW) Global $Kill_Secondary_Selection_Window = GUICtrlCreateButton("X", 0, 0, 160, 23) GUICtrlSetOnEvent($Kill_Secondary_Selection_Window, "Do_Events_Specified_By_Which_Button_Was_Pushed") Global $Secondary_Selection_Window_Choice_1_Spawned_From_Main_GUI_Button_3 = GUICtrlCreateButton("Choice 3-1", 0, 23, 160, 23) GUICtrlSetOnEvent($Secondary_Selection_Window_Choice_1_Spawned_From_Main_GUI_Button_3, "Do_Events_Specified_By_Which_Button_Was_Pushed") Global $Secondary_Selection_Window_Choice_2_Spawned_From_Main_GUI_Button_3 = GUICtrlCreateButton("Choice 3-2", 0, 46, 160, 23) GUICtrlSetOnEvent($Secondary_Selection_Window_Choice_2_Spawned_From_Main_GUI_Button_3, "Do_Events_Specified_By_Which_Button_Was_Pushed") WinSetOnTop($Secondary_Selection_Window, "", $WINDOWS_ONTOP) GUISetState(@SW_SHOW, $Secondary_Selection_Window) EndIf Case $Kill_Secondary_Selection_Window GUIDelete($Secondary_Selection_Window) Case $Secondary_Selection_Window_Choice_1_Spawned_From_Main_GUI_Button_1 GUIDelete($Secondary_Selection_Window) MsgBox($MB_OK,"You selected 1-1", "$Secondary_Selection_Window_Choice_1_Spawned_From_Main_GUI_Button_1") Case $Secondary_Selection_Window_Choice_2_Spawned_From_Main_GUI_Button_1 GUIDelete($Secondary_Selection_Window) MsgBox($MB_OK,"You selected 1-2", "$Secondary_Selection_Window_Choice_2_Spawned_From_Main_GUI_Button_1") Case $Secondary_Selection_Window_Choice_1_Spawned_From_Main_GUI_Button_2 GUIDelete($Secondary_Selection_Window) MsgBox($MB_OK,"You selected 2-1", "$Secondary_Selection_Window_Choice_1_Spawned_From_Main_GUI_Button_2") Case $Secondary_Selection_Window_Choice_2_Spawned_From_Main_GUI_Button_2 GUIDelete($Secondary_Selection_Window) MsgBox($MB_OK,"You selected 2-2", "$Secondary_Selection_Window_Choice_2_Spawned_From_Main_GUI_Button_2") Case $Secondary_Selection_Window_Choice_1_Spawned_From_Main_GUI_Button_3 GUIDelete($Secondary_Selection_Window) MsgBox($MB_OK,"You selected 3-1", "$Secondary_Selection_Window_Choice_1_Spawned_From_Main_GUI_Button_3") Case $Secondary_Selection_Window_Choice_2_Spawned_From_Main_GUI_Button_3 GUIDelete($Secondary_Selection_Window) MsgBox($MB_OK,"You selected 3-2", "$Secondary_Selection_Window_Choice_2_Spawned_From_Main_GUI_Button_3") EndSwitch EndFunc Func Exiting_Function() Exit EndFunc Create_Main_GUI() GUISetState(@SW_SHOW, $Main_GUI) While 1 Sleep(10) WEnd Link to comment Share on other sites More sharing options...
GokAy Posted December 1, 2020 Share Posted December 1, 2020 Hey, having global variables inside a function may be causing. Try putting global declarations outside at the top, and assign to variable only inside the function. Link to comment Share on other sites More sharing options...
baconaise Posted December 1, 2020 Author Share Posted December 1, 2020 Thanks for the suggestion. I rewrote it as you suggested, but it is still suffering from the same problem: The buttons on the Secondary Selection Window are all behaving as though the first button clicked is $Main_GUI_Button_1, regardless of if you click $Main_GUI_Button_1, $Main_GUI_Button_2, or $Main_GUI_Button_3. expandcollapse popup#include <AutoItConstants.au3> #include <MsgBoxConstants.au3> #include <GUIConstants.au3> Opt("GUIOnEventMode", 1) Func Declare_All_The_Variables() Global $Main_GUI Global $Main_GUI_Button_1 Global $Main_GUI_Button_2 Global $Main_GUI_Button_3 Global $Secondary_Selection_Window Global $Kill_Secondary_Selection_Window Global $Secondary_Selection_Window_Choice_1_Spawned_From_Main_GUI_Button_1 Global $Secondary_Selection_Window_Choice_2_Spawned_From_Main_GUI_Button_1 Global $Secondary_Selection_Window_Choice_1_Spawned_From_Main_GUI_Button_2 Global $Secondary_Selection_Window_Choice_2_Spawned_From_Main_GUI_Button_2 Global $Secondary_Selection_Window_Choice_1_Spawned_From_Main_GUI_Button_3 Global $Secondary_Selection_Window_Choice_2_Spawned_From_Main_GUI_Button_3 EndFunc Func Create_Main_GUI() $Main_GUI = GUICreate("Main GUI", 200, 120) GUISetOnEvent($GUI_EVENT_CLOSE, "Exiting_Function") $Main_GUI_Button_1 = GUICtrlCreateButton("Main Button 1", 0, 0, 200, 40) GUICtrlSetOnEvent($Main_GUI_Button_1, "Do_Events_Specified_By_Which_Button_Was_Pushed") $Main_GUI_Button_2 = GUICtrlCreateButton("Main Button 2", 0, 40, 200, 40) GUICtrlSetOnEvent($Main_GUI_Button_2, "Do_Events_Specified_By_Which_Button_Was_Pushed") $Main_GUI_Button_3 = GUICtrlCreateButton("Main Button 3", 0, 80, 200, 40) GUICtrlSetOnEvent($Main_GUI_Button_3, "Do_Events_Specified_By_Which_Button_Was_Pushed") EndFunc Func Do_Events_Specified_By_Which_Button_Was_Pushed() Switch @GUI_CtrlId Case $Main_GUI_Button_1 Local $Mouse_Position = MouseGetPos() If Not WinExists("Secondary Selection Window") Then $Secondary_Selection_Window = GUICreate("Secondary Selection Window", 160, 69, $Mouse_Position[0] - 80, $Mouse_Position[1] - 10, $WS_POPUPWINDOW) $Kill_Secondary_Selection_Window = GUICtrlCreateButton("X", 0, 0, 160, 23) GUICtrlSetOnEvent($Kill_Secondary_Selection_Window, "Do_Events_Specified_By_Which_Button_Was_Pushed") $Secondary_Selection_Window_Choice_1_Spawned_From_Main_GUI_Button_1 = GUICtrlCreateButton("Choice 1-1", 0, 23, 160, 23) GUICtrlSetOnEvent($Secondary_Selection_Window_Choice_1_Spawned_From_Main_GUI_Button_1, "Do_Events_Specified_By_Which_Button_Was_Pushed") $Secondary_Selection_Window_Choice_2_Spawned_From_Main_GUI_Button_1 = GUICtrlCreateButton("Choice 1-2", 0, 46, 160, 23) GUICtrlSetOnEvent($Secondary_Selection_Window_Choice_2_Spawned_From_Main_GUI_Button_1, "Do_Events_Specified_By_Which_Button_Was_Pushed") WinSetOnTop($Secondary_Selection_Window, "", $WINDOWS_ONTOP) GUISetState(@SW_SHOW, $Secondary_Selection_Window) EndIf Case $Main_GUI_Button_2 Local $Mouse_Position = MouseGetPos() If Not WinExists("Secondary Selection Window") Then $Secondary_Selection_Window = GUICreate("Secondary Selection Window", 160, 69, $Mouse_Position[0] - 80, $Mouse_Position[1] - 10, $WS_POPUPWINDOW) $Kill_Secondary_Selection_Window = GUICtrlCreateButton("X", 0, 0, 160, 23) GUICtrlSetOnEvent($Kill_Secondary_Selection_Window, "Do_Events_Specified_By_Which_Button_Was_Pushed") $Secondary_Selection_Window_Choice_1_Spawned_From_Main_GUI_Button_2 = GUICtrlCreateButton("Choice 2-1", 0, 23, 160, 23) GUICtrlSetOnEvent($Secondary_Selection_Window_Choice_1_Spawned_From_Main_GUI_Button_2, "Do_Events_Specified_By_Which_Button_Was_Pushed") $Secondary_Selection_Window_Choice_2_Spawned_From_Main_GUI_Button_2 = GUICtrlCreateButton("Choice 2-2", 0, 46, 160, 23) GUICtrlSetOnEvent($Secondary_Selection_Window_Choice_2_Spawned_From_Main_GUI_Button_2, "Do_Events_Specified_By_Which_Button_Was_Pushed") WinSetOnTop($Secondary_Selection_Window, "", $WINDOWS_ONTOP) GUISetState(@SW_SHOW, $Secondary_Selection_Window) EndIf Case $Main_GUI_Button_3 Local $Mouse_Position = MouseGetPos() If Not WinExists("Secondary Selection Window") Then $Secondary_Selection_Window = GUICreate("Secondary Selection Window", 160, 69, $Mouse_Position[0] - 80, $Mouse_Position[1] - 10, $WS_POPUPWINDOW) $Kill_Secondary_Selection_Window = GUICtrlCreateButton("X", 0, 0, 160, 23) GUICtrlSetOnEvent($Kill_Secondary_Selection_Window, "Do_Events_Specified_By_Which_Button_Was_Pushed") $Secondary_Selection_Window_Choice_1_Spawned_From_Main_GUI_Button_3 = GUICtrlCreateButton("Choice 3-1", 0, 23, 160, 23) GUICtrlSetOnEvent($Secondary_Selection_Window_Choice_1_Spawned_From_Main_GUI_Button_3, "Do_Events_Specified_By_Which_Button_Was_Pushed") $Secondary_Selection_Window_Choice_2_Spawned_From_Main_GUI_Button_3 = GUICtrlCreateButton("Choice 3-2", 0, 46, 160, 23) GUICtrlSetOnEvent($Secondary_Selection_Window_Choice_2_Spawned_From_Main_GUI_Button_3, "Do_Events_Specified_By_Which_Button_Was_Pushed") WinSetOnTop($Secondary_Selection_Window, "", $WINDOWS_ONTOP) GUISetState(@SW_SHOW, $Secondary_Selection_Window) EndIf Case $Kill_Secondary_Selection_Window GUIDelete($Secondary_Selection_Window) Case $Secondary_Selection_Window_Choice_1_Spawned_From_Main_GUI_Button_1 GUIDelete($Secondary_Selection_Window) MsgBox($MB_OK,"You selected 1-1", "$Secondary_Selection_Window_Choice_1_Spawned_From_Main_GUI_Button_1") Case $Secondary_Selection_Window_Choice_2_Spawned_From_Main_GUI_Button_1 GUIDelete($Secondary_Selection_Window) MsgBox($MB_OK,"You selected 1-2", "$Secondary_Selection_Window_Choice_2_Spawned_From_Main_GUI_Button_1") Case $Secondary_Selection_Window_Choice_1_Spawned_From_Main_GUI_Button_2 GUIDelete($Secondary_Selection_Window) MsgBox($MB_OK,"You selected 2-1", "$Secondary_Selection_Window_Choice_1_Spawned_From_Main_GUI_Button_2") Case $Secondary_Selection_Window_Choice_2_Spawned_From_Main_GUI_Button_2 GUIDelete($Secondary_Selection_Window) MsgBox($MB_OK,"You selected 2-2", "$Secondary_Selection_Window_Choice_2_Spawned_From_Main_GUI_Button_2") Case $Secondary_Selection_Window_Choice_1_Spawned_From_Main_GUI_Button_3 GUIDelete($Secondary_Selection_Window) MsgBox($MB_OK,"You selected 3-1", "$Secondary_Selection_Window_Choice_1_Spawned_From_Main_GUI_Button_3") Case $Secondary_Selection_Window_Choice_2_Spawned_From_Main_GUI_Button_3 GUIDelete($Secondary_Selection_Window) MsgBox($MB_OK,"You selected 3-2", "$Secondary_Selection_Window_Choice_2_Spawned_From_Main_GUI_Button_3") EndSwitch EndFunc Func Exiting_Function() Exit EndFunc Declare_All_The_Variables() Create_Main_GUI() GUISetState(@SW_SHOW, $Main_GUI) While 1 Sleep(10) WEnd Link to comment Share on other sites More sharing options...
GokAy Posted December 1, 2020 Share Posted December 1, 2020 They are still within a function More like this. Don't need the GUI stuff ina function I believe but this looks neater to me, idk. expandcollapse popup#include <AutoItConstants.au3> #include <MsgBoxConstants.au3> #include <GUIConstants.au3> Opt("GUIOnEventMode", 1) Global $Main_GUI Global $Main_GUI_Button_1 Global $Main_GUI_Button_2 Global $Main_GUI_Button_3 Global $Secondary_Selection_Window Global $Kill_Secondary_Selection_Window Global $Secondary_Selection_Window_Choice_1_Spawned_From_Main_GUI_Button_1 Global $Secondary_Selection_Window_Choice_2_Spawned_From_Main_GUI_Button_1 Global $Secondary_Selection_Window_Choice_1_Spawned_From_Main_GUI_Button_2 Global $Secondary_Selection_Window_Choice_2_Spawned_From_Main_GUI_Button_2 Global $Secondary_Selection_Window_Choice_1_Spawned_From_Main_GUI_Button_3 Global $Secondary_Selection_Window_Choice_2_Spawned_From_Main_GUI_Button_3 Create_Main_GUI() Func Create_Main_GUI() $Main_GUI = GUICreate("Main GUI", 200, 120) GUISetOnEvent($GUI_EVENT_CLOSE, "Exiting_Function") $Main_GUI_Button_1 = GUICtrlCreateButton("Main Button 1", 0, 0, 200, 40) GUICtrlSetOnEvent($Main_GUI_Button_1, "Do_Events_Specified_By_Which_Button_Was_Pushed") $Main_GUI_Button_2 = GUICtrlCreateButton("Main Button 2", 0, 40, 200, 40) GUICtrlSetOnEvent($Main_GUI_Button_2, "Do_Events_Specified_By_Which_Button_Was_Pushed") $Main_GUI_Button_3 = GUICtrlCreateButton("Main Button 3", 0, 80, 200, 40) GUICtrlSetOnEvent($Main_GUI_Button_3, "Do_Events_Specified_By_Which_Button_Was_Pushed") GUISetState(@SW_SHOW, $Main_GUI) While 1 Sleep(10) WEnd EndFunc Func Do_Events_Specified_By_Which_Button_Was_Pushed() Switch @GUI_CtrlId Case $Main_GUI_Button_1 Local $Mouse_Position = MouseGetPos() If Not WinExists("Secondary Selection Window") Then $Secondary_Selection_Window = GUICreate("Secondary Selection Window", 160, 69, $Mouse_Position[0] - 80, $Mouse_Position[1] - 10, $WS_POPUPWINDOW) $Kill_Secondary_Selection_Window = GUICtrlCreateButton("X", 0, 0, 160, 23) GUICtrlSetOnEvent($Kill_Secondary_Selection_Window, "Do_Events_Specified_By_Which_Button_Was_Pushed") $Secondary_Selection_Window_Choice_1_Spawned_From_Main_GUI_Button_1 = GUICtrlCreateButton("Choice 1-1", 0, 23, 160, 23) GUICtrlSetOnEvent($Secondary_Selection_Window_Choice_1_Spawned_From_Main_GUI_Button_1, "Do_Events_Specified_By_Which_Button_Was_Pushed") $Secondary_Selection_Window_Choice_2_Spawned_From_Main_GUI_Button_1 = GUICtrlCreateButton("Choice 1-2", 0, 46, 160, 23) GUICtrlSetOnEvent($Secondary_Selection_Window_Choice_2_Spawned_From_Main_GUI_Button_1, "Do_Events_Specified_By_Which_Button_Was_Pushed") WinSetOnTop($Secondary_Selection_Window, "", $WINDOWS_ONTOP) GUISetState(@SW_SHOW, $Secondary_Selection_Window) EndIf Case $Main_GUI_Button_2 Local $Mouse_Position = MouseGetPos() If Not WinExists("Secondary Selection Window") Then $Secondary_Selection_Window = GUICreate("Secondary Selection Window", 160, 69, $Mouse_Position[0] - 80, $Mouse_Position[1] - 10, $WS_POPUPWINDOW) $Kill_Secondary_Selection_Window = GUICtrlCreateButton("X", 0, 0, 160, 23) GUICtrlSetOnEvent($Kill_Secondary_Selection_Window, "Do_Events_Specified_By_Which_Button_Was_Pushed") $Secondary_Selection_Window_Choice_1_Spawned_From_Main_GUI_Button_2 = GUICtrlCreateButton("Choice 2-1", 0, 23, 160, 23) GUICtrlSetOnEvent($Secondary_Selection_Window_Choice_1_Spawned_From_Main_GUI_Button_2, "Do_Events_Specified_By_Which_Button_Was_Pushed") $Secondary_Selection_Window_Choice_2_Spawned_From_Main_GUI_Button_2 = GUICtrlCreateButton("Choice 2-2", 0, 46, 160, 23) GUICtrlSetOnEvent($Secondary_Selection_Window_Choice_2_Spawned_From_Main_GUI_Button_2, "Do_Events_Specified_By_Which_Button_Was_Pushed") WinSetOnTop($Secondary_Selection_Window, "", $WINDOWS_ONTOP) GUISetState(@SW_SHOW, $Secondary_Selection_Window) EndIf Case $Main_GUI_Button_3 Local $Mouse_Position = MouseGetPos() If Not WinExists("Secondary Selection Window") Then $Secondary_Selection_Window = GUICreate("Secondary Selection Window", 160, 69, $Mouse_Position[0] - 80, $Mouse_Position[1] - 10, $WS_POPUPWINDOW) $Kill_Secondary_Selection_Window = GUICtrlCreateButton("X", 0, 0, 160, 23) GUICtrlSetOnEvent($Kill_Secondary_Selection_Window, "Do_Events_Specified_By_Which_Button_Was_Pushed") $Secondary_Selection_Window_Choice_1_Spawned_From_Main_GUI_Button_3 = GUICtrlCreateButton("Choice 3-1", 0, 23, 160, 23) GUICtrlSetOnEvent($Secondary_Selection_Window_Choice_1_Spawned_From_Main_GUI_Button_3, "Do_Events_Specified_By_Which_Button_Was_Pushed") $Secondary_Selection_Window_Choice_2_Spawned_From_Main_GUI_Button_3 = GUICtrlCreateButton("Choice 3-2", 0, 46, 160, 23) GUICtrlSetOnEvent($Secondary_Selection_Window_Choice_2_Spawned_From_Main_GUI_Button_3, "Do_Events_Specified_By_Which_Button_Was_Pushed") WinSetOnTop($Secondary_Selection_Window, "", $WINDOWS_ONTOP) GUISetState(@SW_SHOW, $Secondary_Selection_Window) EndIf Case $Kill_Secondary_Selection_Window GUIDelete($Secondary_Selection_Window) Case $Secondary_Selection_Window_Choice_1_Spawned_From_Main_GUI_Button_1 GUIDelete($Secondary_Selection_Window) MsgBox($MB_OK,"You selected 1-1", "$Secondary_Selection_Window_Choice_1_Spawned_From_Main_GUI_Button_1") Case $Secondary_Selection_Window_Choice_2_Spawned_From_Main_GUI_Button_1 GUIDelete($Secondary_Selection_Window) MsgBox($MB_OK,"You selected 1-2", "$Secondary_Selection_Window_Choice_2_Spawned_From_Main_GUI_Button_1") Case $Secondary_Selection_Window_Choice_1_Spawned_From_Main_GUI_Button_2 GUIDelete($Secondary_Selection_Window) MsgBox($MB_OK,"You selected 2-1", "$Secondary_Selection_Window_Choice_1_Spawned_From_Main_GUI_Button_2") Case $Secondary_Selection_Window_Choice_2_Spawned_From_Main_GUI_Button_2 GUIDelete($Secondary_Selection_Window) MsgBox($MB_OK,"You selected 2-2", "$Secondary_Selection_Window_Choice_2_Spawned_From_Main_GUI_Button_2") Case $Secondary_Selection_Window_Choice_1_Spawned_From_Main_GUI_Button_3 GUIDelete($Secondary_Selection_Window) MsgBox($MB_OK,"You selected 3-1", "$Secondary_Selection_Window_Choice_1_Spawned_From_Main_GUI_Button_3") Case $Secondary_Selection_Window_Choice_2_Spawned_From_Main_GUI_Button_3 GUIDelete($Secondary_Selection_Window) MsgBox($MB_OK,"You selected 3-2", "$Secondary_Selection_Window_Choice_2_Spawned_From_Main_GUI_Button_3") EndSwitch EndFunc Func Exiting_Function() Exit EndFunc Link to comment Share on other sites More sharing options...
Nine Posted December 1, 2020 Share Posted December 1, 2020 The GuiDelete deletes all control ids. When you recreate them, it will take place of the empty spaces number. So in your case, it thinks it is always first main button. So you should create all secondary windows at first then hide and show appropriately. That way all control ids will have different numbers. baconaise 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
baconaise Posted December 1, 2020 Author Share Posted December 1, 2020 49 minutes ago, Nine said: The GuiDelete deletes all control ids. When you recreate them, it will take place of the empty spaces number. So in your case, it thinks it is always first main button. So you should create all secondary windows at first then hide and show appropriately. That way all control ids will have different numbers. That makes sense! Thank you. My actual purpose would require something like 300 GUIs to do that--have any cleaner way to do that? Link to comment Share on other sites More sharing options...
pixelsearch Posted December 1, 2020 Share Posted December 1, 2020 (edited) If you run the script from Scite, then you can debug with ConsoleWrite() showing all control ID's. Here is what you will find : Func Do_Events_Specified_By_Which_Button_Was_Pushed() Switch @GUI_CtrlId Case $Main_GUI_Button_1 Case ... Case $Secondary_Selection_Window_Choice_2_Spawned_From_Main_GUI_Button_3 EndSwitch ConsoleWrite( _ $Main_GUI_Button_1 & " " & _ $Main_GUI_Button_2 & " " & _ $Main_GUI_Button_3 & " " & _ $Kill_Secondary_Selection_Window & " " & _ $Secondary_Selection_Window_Choice_1_Spawned_From_Main_GUI_Button_1 & " " & _ $Secondary_Selection_Window_Choice_2_Spawned_From_Main_GUI_Button_1 & " " & _ $Secondary_Selection_Window_Choice_1_Spawned_From_Main_GUI_Button_2 & " " & _ $Secondary_Selection_Window_Choice_2_Spawned_From_Main_GUI_Button_2 & " " & _ $Secondary_Selection_Window_Choice_1_Spawned_From_Main_GUI_Button_3 & " " & _ $Secondary_Selection_Window_Choice_2_Spawned_From_Main_GUI_Button_3 & " " & @CRLF) EndFunc Console result : 3 4 5 6 7 8 3 4 5 6 7 8 3 4 5 6 7 8 7 8 3 4 5 6 7 8 7 8 3 4 5 6 7 8 7 8 7 8 3 4 5 6 7 8 7 8 7 8 Id's 3, 4, 5 are always for $Main_GUI_Button_1, $Main_GUI_Button_2, $Main_GUI_Button_3 Id 6 is always for $Kill_Secondary_Selection_Window Issue comes for Id's 7 and 8 which will be soon triplicated in your function. The console result (above) shows what happens when you click in this specific order : * Main Button 3 => choice 3-1 (message box is correct) then * Main Button 2 => choice 2-1 (message box is correct) then * Main Button 1 => choice 1-1 (message box is correct) At this stage, you notice that several variables (Case) got the same value in your function and the "first" id's 7 and 8 which will be first accessed correspond to : * $Secondary_Selection_Window_Choice_1_Spawned_From_Main_GUI_Button_1 = 7 * $Secondary_Selection_Window_Choice_2_Spawned_From_Main_GUI_Button_1 = 8 Which means that from now on, all clicks on main button 2 & 3 will display wrong results. It's important to remember that deleting a GUI doesn't "blank" the variables assigned to the deleted id's I had a similar problem once with this kind of script : $hGUI_Preview = GUICreate(...) ... GUIDelete($hGUI_Preview) ... If $hGUI_Preview Then ; very bad ! It's bad because deleting the GUI doesn't blank $hGUI_Preview which still contains a value until the end of time. If one really needs the "If" test, then It can be scripted like this : $hGUI_Preview = GUICreate(...) ... GUIDelete($hGUI_Preview) $hGUI_Preview = 0 ; <============= ... If $hGUI_Preview Then ; now it's ok Edited December 1, 2020 by pixelsearch I saw you just answered to Nine, anyway I'll keep my answer as-is baconaise 1 Link to comment Share on other sites More sharing options...
Nine Posted December 1, 2020 Share Posted December 1, 2020 11 hours ago, baconaise said: My actual purpose would require something like 300 GUIs to do that--have any cleaner way to do that? One way would be to save the control ids in a MAP array that you can delete easily after usage : expandcollapse popup#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Version=Beta #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <AutoItConstants.au3> #include <MsgBoxConstants.au3> #include <GUIConstants.au3> Create_Main_GUI() Func Create_Main_GUI() Local $mGUI[] Local $hGUI = GUICreate("Main GUI", 200, 120) Local $idMain1 = GUICtrlCreateButton("Main 1", 0, 0, 200, 40) Local $idMain2 = GUICtrlCreateButton("Main 2", 0, 40, 200, 40) Local $idMain3 = GUICtrlCreateButton("Main 3", 0, 80, 200, 40) GUISetState() Local $aPos, $nMsg, $idKill, $aKeys While True $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_NONE ; not truly necessary, but avoid triggering Case Else for nothing Case $GUI_EVENT_CLOSE ExitLoop Case $idMain1 If Not WinExists("Secondary Window") Then $aPos = MouseGetPos() $hWindow2 = GUICreate("Secondary Window", 160, 69, $aPos[0] - 80, $aPos[1] - 10, $WS_POPUPWINDOW) $idKill = GUICtrlCreateButton("X", 0, 0, 160, 23) $mGUI["Choice 1-1"] = GUICtrlCreateButton("Choice 1-1", 0, 23, 160, 23) $mGUI["Choice 1-2"] = GUICtrlCreateButton("Choice 1-2", 0, 46, 160, 23) WinSetOnTop($hWindow2, "", $WINDOWS_ONTOP) GUISetState(@SW_SHOW, $hWindow2) EndIf Case $idMain2 If Not WinExists("Secondary Window") Then $aPos = MouseGetPos() $hWindow2 = GUICreate("Secondary Window", 160, 69, $aPos[0] - 80, $aPos[1] - 10, $WS_POPUPWINDOW) $idKill = GUICtrlCreateButton("X", 0, 0, 160, 23) $mGUI["Choice 2-1"] = GUICtrlCreateButton("Choice 2-1", 0, 23, 160, 23) $mGUI["Choice 2-2"] = GUICtrlCreateButton("Choice 2-2", 0, 46, 160, 23) WinSetOnTop($hWindow2, "", $WINDOWS_ONTOP) GUISetState(@SW_SHOW, $hWindow2) EndIf Case $idMain3 If Not WinExists("Secondary Window") Then $aPos = MouseGetPos() $hWindow2 = GUICreate("Secondary Window", 160, 69, $aPos[0] - 80, $aPos[1] - 10, $WS_POPUPWINDOW) $idKill = GUICtrlCreateButton("X", 0, 0, 160, 23) $mGUI["Choice 3-1"] = GUICtrlCreateButton("Choice 3-1", 0, 23, 160, 23) $mGUI["Choice 3-2"] = GUICtrlCreateButton("Choice 3-2", 0, 46, 160, 23) WinSetOnTop($hWindow2, "", $WINDOWS_ONTOP) GUISetState(@SW_SHOW, $hWindow2) EndIf Case $idKill GUIDelete($hWindow2) Local $mGUI[] Case Else $aKeys = MapKeys($mGUI) For $i = 0 to UBound($aKeys)-1 If $mGUI[$aKeys[$i]] = $nMsg Then MsgBox ($MB_SYSTEMMODAL,"Info", "Button " & $aKeys[$i] & " was pressed !") Next EndSwitch WEnd EndFunc Sorry I had to rewrite much of it as I cannot stand very long var names ps. I could have streamlined $idMain1 to $idMain3 as only a few numbers differs , but I will leave it to you if you want. baconaise and pixelsearch 1 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
pixelsearch Posted December 2, 2020 Share Posted December 2, 2020 Thx Nine for your script above, based on Map variables. As I never used them before, it forced me to start study them * First learning was from the help file (AutoIt Beta v3.3.15.3, NOT our actual stable version 3.3.14.5) 7 topics found, i.e. the crucial "Language Reference - variables (maps)", then 4 functions MapAppend, MapExists, MapKeys, MapRemove, not forgetting IsMap() and UBound() * Then your script above, it was ingenious during the Case Else to retrieve the Map keys from the Map values, great ! 2 observations I'd like to share concerning the script : Case $GUI_EVENT_NONE ; not truly necessary, but avoid triggering Case Else for nothing In fact, as soon as this line is commented, a fatal error happens because Case $idKill is immediately triggered ($îdKill being assimilated to 0, just as $GUI_EVENT_NONE) and GUIDelete($hWindow2) generates now the fatal error ("Variable used without being declared") This being said, even with Case $GUI_EVENT_NONE active, we'll notice that Case Else is triggered many times as shown below, where a counter has been added : Local $iCounter = 0 ; to be placed before the While...Wend loop ... Case Else $iCounter += 1 ConsoleWrite($iCounter & " ") $aKeys = MapKeys($mGUI) ... Console display : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30... This should fix it : Case $GUI_EVENT_NONE, $GUI_EVENT_MOUSEMOVE ; 0 & -11 Aargghhh, I notice there's a new version of your animated gif script, great ! ...but lunch & coffee first Link to comment Share on other sites More sharing options...
Nine Posted December 2, 2020 Share Posted December 2, 2020 40 minutes ago, pixelsearch said: fatal error happens because Case $idKill is immediately triggered Ya good point. We could simply initialize $idKill to -999 to eliminate any risk in the future development of the script. 42 minutes ago, pixelsearch said: Case $GUI_EVENT_NONE, $GUI_EVENT_MOUSEMOVE Yep another good point, we can just add any unless events in fact... “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
pixelsearch Posted December 2, 2020 Share Posted December 2, 2020 1 hour ago, Nine said: we can just add any unless events in fact... Nah... no need, other events are just triggered from time to time during the While...Wend loop, a right click here and there, a minimize/restore from time to time etc... The 2 events that happen hundred of times are (almost) always $GUI_EVENT_NONE and $GUI_EVENT_MOUSEMOVE 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