remin Posted December 19, 2018 Posted December 19, 2018 (edited) I do have one autoit script file with multiple functions. p.e. expandcollapse popup#include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <String.au3> #include <GuiButton.au3> #include <Constants.au3> #include <EditConstants.au3> #include <Misc.au3> #include <MsgBoxConstants.au3> #include <HotString.au3> Func ACase() $Form4=GUICreate("ACase", 100, 195, 290, 142) etc etc GUISetState(@SW_SHOW, $Form4) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE SUB_Write2ini(....) ;I write a few things in an ini file Case $a Case $b etc EndSwitch WEnd EndFunc Func BCase() $Form5=GUICreate("BCase", 100, 195, 290, 142) etc etc GUISetState(@SW_SHOW, $Form5) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE SUB_Write2ini(....) ;I write a few things in an ini file Case $a Case $b etc EndSwitch WEnd EndFunc When I activate the 1st function (ACase), using a shortcut and the 2nd function (BCase) (with a different shortcut) and I click on a button in whatever of these 2 Gui's, I can't use the other Gui anymore. It doesn't do the right thing as if autoit only remembers the Gui I first used. What did I wrong? How can I let autoit know which GUI is active and to connect to the function of that Gui? Hope I made myself clear. Edited December 19, 2018 by remin
careca Posted December 19, 2018 Posted December 19, 2018 (edited) Well, you have 2 loops, when you're inside one, you can't expect anything from the other. I'd go with setonevent, ditch the while loop there, transfer the loop outside of those functions. expandcollapse popup#include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <String.au3> #include <GuiButton.au3> #include <Constants.au3> #include <EditConstants.au3> #include <Misc.au3> #include <MsgBoxConstants.au3> ;#include <HotString.au3> Opt("GUIOnEventMode", 1) Opt("GUIEventOptions", 1) ;============================================================================= Global $Form4, $Form5 ;============================================================================= ACase() While 1 Sleep(100) If WinExists($Form4) = 0 And WinExists($Form5) = 0 Then Exit WEnd ;============================================================================= Func ACase() $Form4=GUICreate("ACase", 200, 195, 290, 142) GUISetOnEvent($GUI_EVENT_CLOSE, "QuitA") GUICtrlCreateButton('open B', 10, 10) GUICtrlSetOnEvent(-1, 'BCase') GUISetState(@SW_SHOW, $Form4) EndFunc ;============================================================================= Func BCase() $Form5=GUICreate("BCase", 200, 195, 290, 142) GUISetOnEvent($GUI_EVENT_CLOSE, "QuitB") GUICtrlCreateButton('message', 10, 10) GUICtrlSetOnEvent(-1, 'mbx') GUISetState(@SW_SHOW, $Form5) EndFunc ;============================================================================= Func QuitA() GUIDelete($Form4) EndFunc ;============================================================================= Func QuitB() GUIDelete($Form5) EndFunc ;============================================================================= Func mbx() MsgBox(64 + 262144, '', 'Ding') EndFunc ;============================================================================= Edited December 19, 2018 by careca Spoiler Renamer - Rename files and folders, remove portions of text from the filename etc. GPO Tool - Export/Import Group policy settings. MirrorDir - Synchronize/Backup/Mirror Folders BeatsPlayer - Music player. Params Tool - Right click an exe to see it's parameters or execute them. String Trigger - Triggers pasting text or applications or internet links on specific strings. Inconspicuous - Hide files in plain sight, not fully encrypted. Regedit Control - Registry browsing history, quickly jump into any saved key. Time4Shutdown - Write the time for shutdown in minutes. Power Profiles Tool - Set a profile as active, delete, duplicate, export and import. Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes. NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s. IUIAutomation - Topic with framework and examples Au3Record.exe
pixelsearch Posted December 19, 2018 Posted December 19, 2018 (edited) Hi remin If you study the following scripts (don't remember where I found them, wiki probably) it may give you ideas to solve your problem. First with GuiGetMsg : expandcollapse popup#include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> ; example of how to manage two GUIs simultaneously using the "advanced" parameter with GUIGetMsg : Yes ! (MessageLoop mode) ; a single While...WEnd loop which distinguishes between the two GUIs, both GUIs and their controls remain active and we stay ; in the main idle loop while we wait Global $g_hGUI2 = 9999 ; Predeclare this variable with dummy value to prevent firing the Case statement, only for GUI2 this time Global $g_idButton3 gui1() Func gui1() Local $hGUI1 = GUICreate("Gui 1", 200, 200, 100, 100) Local $idButton1 = GUICtrlCreateButton("Msgbox 1", 10, 10, 80, 30) Local $idButton2 = GUICtrlCreateButton("Show Gui 2", 10, 60, 80, 30) GUISetState() Local $aMsg While 1 $aMsg = GUIGetMsg(1) ; Use advanced parameter to get array Switch $aMsg[1] ; check which GUI sent the message Case $hGUI1 Switch $aMsg[0] ; Now check for the messages for $hGUI1 Case $GUI_EVENT_CLOSE ; If we get the CLOSE message from this GUI - we exit <<<<<<<<<<<<<<< ExitLoop Case $idButton1 MsgBox($MB_OK, "MsgBox 1", "Test from Gui 1") Case $idButton2 GUICtrlSetState($idButton2, $GUI_DISABLE) gui2() EndSwitch Case $g_hGUI2 Switch $aMsg[0] ; Now check for the messages for $g_hGUI2 Case $GUI_EVENT_CLOSE ; If we get the CLOSE message from this GUI - we just delete the GUI <<<<<<<<<<<<<<< GUIDelete($g_hGUI2) GUICtrlSetState($idButton2, $GUI_ENABLE) Case $g_idButton3 MsgBox($MB_OK, "MsgBox", "Test from Gui 2") EndSwitch EndSwitch WEnd EndFunc ;==>gui1 Func gui2() $g_hGUI2 = GUICreate("Gui 2", 200, 200, 350, 350) $g_idButton3 = GUICtrlCreateButton("MsgBox 2", 10, 10, 80, 30) GUISetState() EndFunc ;==>gui2 Then, as suggested by Careca, with On Event Mode : expandcollapse popup#include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> ; Coders using OnEvent mode do not usually find the same problem with multiple GUIs as they can code separate functions ; for each $GUI_EVENT_CLOSE as shown in this example. Good (OnEvent mode) Opt("GUIOnEventMode", 1) Global $g_hGUI2, $g_idButton2 ; Predeclare these variables gui1() Func gui1() Local $hGUI1 = GUICreate("Gui 1", 200, 200, 100, 100) GUISetOnEvent($GUI_EVENT_CLOSE, "On_Close_Main") ; Run this function when the main GUI [X] is clicked Local $idButton1 = GUICtrlCreateButton("Msgbox 1", 10, 10, 80, 30) GUICtrlSetOnEvent(-1, "On_Button1") $g_idButton2 = GUICtrlCreateButton("Show Gui 2", 10, 60, 80, 30) GUICtrlSetOnEvent(-1, "On_Button2") GUISetState() While 1 Sleep(10) WEnd EndFunc ;==>gui1 Func gui2() $g_hGUI2 = GUICreate("Gui 2", 200, 200, 350, 350) GUISetOnEvent($GUI_EVENT_CLOSE, "On_Close_Secondary") ; Run this function when the secondary GUI [X] is clicked Local $idButton3 = GUICtrlCreateButton("MsgBox 2", 10, 10, 80, 30) GUICtrlSetOnEvent(-1, "On_Button3") GUISetState() EndFunc ;==>gui2 Func On_Close_Main() Exit EndFunc ;==>On_Close_Main Func On_Close_Secondary() GUIDelete($g_hGUI2) GUICtrlSetState($g_idButton2, $GUI_ENABLE) EndFunc ;==>On_Close_Secondary Func On_Button1() MsgBox($MB_OK, "MsgBox 1", "Test from Gui 1") EndFunc ;==>On_Button1 Func On_Button2() GUICtrlSetState($g_idButton2, $GUI_DISABLE) gui2() EndFunc ;==>On_Button2 Func On_Button3() MsgBox($MB_OK, "MsgBox 2", "Test from Gui 2") EndFunc ;==>On_Button3 Good luck Edited December 19, 2018 by pixelsearch remin 1 "I think you are searching a bug where there is no bug... don't listen to bad advice."
remin Posted December 19, 2018 Author Posted December 19, 2018 (edited) 18 minutes ago, careca said: Well, you have 2 loops, when you're inside one, you can't expect anything from the other. I'd go with setonevent, ditch the while loop there, transfer the loop outside of those functions. Thank you, I think that's a lot of work. I do have 29 functions in my script file (not all with a while loop). Maybe it's easier to refuse 2 Gui's at the same time. Is it possible to close all open Autoit Gui's before to create the current Gui? Edited December 19, 2018 by remin
careca Posted December 19, 2018 Posted December 19, 2018 Yep, create a function into a button or something and in that function delete all GUI's and recreate the one you want, depends on what you want exactly. Spoiler Renamer - Rename files and folders, remove portions of text from the filename etc. GPO Tool - Export/Import Group policy settings. MirrorDir - Synchronize/Backup/Mirror Folders BeatsPlayer - Music player. Params Tool - Right click an exe to see it's parameters or execute them. String Trigger - Triggers pasting text or applications or internet links on specific strings. Inconspicuous - Hide files in plain sight, not fully encrypted. Regedit Control - Registry browsing history, quickly jump into any saved key. Time4Shutdown - Write the time for shutdown in minutes. Power Profiles Tool - Set a profile as active, delete, duplicate, export and import. Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes. NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s. IUIAutomation - Topic with framework and examples Au3Record.exe
Moderators Melba23 Posted December 19, 2018 Moderators Posted December 19, 2018 remin, The Managing Multiple GUIs tutorial in the Wiki would be worth reading. 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
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