Naveed Posted July 13, 2010 Posted July 13, 2010 This might be straight forward but i am struggling to work it out. I have included an example of the problem i am having with one of my programs i have built. I am able to launch another gui window without a problem using the guicreate method however i am unable to close this 2nd gui. #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Opt('GuiOnEventMode', 1) Global $gui $gui = GUICreate("test",400,100,-1,-1) GUISetState(@SW_SHOW) GUISetOnEvent($gui_event_close,"Exitgui") $but = GUICtrlCreateButton("Test",10,10,200,50) GUIctrlSetOnEvent($but,"newgui") Func newgui() $gui2 = GUICreate("Test 2",400,100,-1,-1) GUISetState(@SW_SHOW) Do $msg = GUIGetMsg() Until $msg = $GUI_EVENT_CLOSE while 1 WEnd EndFunc Func exitgui() Exit EndFunc While 1 Sleep(10000) WEnd Any help will be much appreciated, thanks Nav
Makaule Posted July 13, 2010 Posted July 13, 2010 You may try to use GUIDelete() or GUISetState(@SW_HIDE, $2nd_GUI) and similar ways.
Naveed Posted July 13, 2010 Author Posted July 13, 2010 You may try to use GUIDelete() or GUISetState(@SW_HIDE, $2nd_GUI) and similar ways.Thanks for that however GuiDelete()doesnt work and guisetstate is no good as i want to close the GUI rather then hide it.
KaFu Posted July 13, 2010 Posted July 13, 2010 You're mixing GuiOnEventMode with GUIGetMsg. If you want to use GUIGetMsg, disable the OnEvent mode at the beginning of the function an reenable it at the end. #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Opt('GuiOnEventMode', 1) Global $gui, $gui2 $gui = GUICreate("test", 400, 100) GUISetState(@SW_SHOW) GUISetOnEvent($gui_event_close, "Exitgui") $but = GUICtrlCreateButton("Test", 10, 10, 200, 50) GUICtrlSetOnEvent($but, "newgui") While 1 Sleep(10) WEnd Func newgui() if IsHWnd($gui2) then GUIDelete($gui2) $gui2 = GUICreate("Test 2", 200, 50) GUISetOnEvent($gui_event_close, "Exitgui") GUISetState(@SW_SHOW) EndFunc ;==>newgui Func exitgui() Switch @GUI_WinHandle Case $gui Exit Case $gui2 GUIDelete($gui2) EndSwitch EndFunc ;==>exitgui OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2025-May-18) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16)
Naveed Posted July 13, 2010 Author Posted July 13, 2010 You're mixing GuiOnEventMode with GUIGetMsg. If you want to use GUIGetMsg, disable the OnEvent mode at the beginning of the function an reenable it at the end. #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Opt('GuiOnEventMode', 1) Global $gui, $gui2 $gui = GUICreate("test", 400, 100) GUISetState(@SW_SHOW) GUISetOnEvent($gui_event_close, "Exitgui") $but = GUICtrlCreateButton("Test", 10, 10, 200, 50) GUICtrlSetOnEvent($but, "newgui") While 1 Sleep(10) WEnd Func newgui() if IsHWnd($gui2) then GUIDelete($gui2) $gui2 = GUICreate("Test 2", 200, 50) GUISetOnEvent($gui_event_close, "Exitgui") GUISetState(@SW_SHOW) EndFunc ;==>newgui Func exitgui() Switch @GUI_WinHandle Case $gui Exit Case $gui2 GUIDelete($gui2) EndSwitch EndFunc ;==>exitgui Thanks for that KaFu that helps alot, does the positioning of onevent mode within the code matter and if so could you please explain why. Thanks once again. Nav
KaFu Posted July 13, 2010 Posted July 13, 2010 does the positioning of onevent mode within the code matter and if so could you please explain why. Yep, it does. Autoit is single threaded, you can always follow the flow with your finger tip. If Onevent mode is enabled, guigetmsg will not work an vice versa. If you want to mix both methods you'll have to do it like this, note that if you're opening the 2nd gui the onevent trigger on the first gui is disabled. expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Opt('GuiOnEventMode', 1) Global $gui, $gui2 $gui = GUICreate("test", 400, 100) GUISetState(@SW_SHOW) GUISetOnEvent($gui_event_close, "Exitgui") $but = GUICtrlCreateButton("Test", 10, 10, 200, 50) GUICtrlSetOnEvent($but, "newgui") While 1 Sleep(10) WEnd Func newgui() If IsHWnd($gui2) Then GUIDelete($gui2) Opt('GuiOnEventMode', 0) $gui2 = GUICreate("Test 2", 200, 50) GUISetState(@SW_SHOW) Do $msg = GUIGetMsg() Until $msg = $gui_event_close GUIDelete($gui2) Opt('GuiOnEventMode', 1) EndFunc ;==>newgui Func exitgui() Switch @GUI_WinHandle Case $gui Exit EndSwitch EndFunc ;==>exitgui OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2025-May-18) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16)
Moderators Melba23 Posted July 13, 2010 Moderators Posted July 13, 2010 Naveed,I would go further than KaFu and say that, as a general rule, you should only ever use just the one mode your script. Switching modes in the same script is fraught with danger and should only be used in the most exceptional circumstances - and even then you should have alarm bells ringing in your head asking why the circumstances are so exceptional and whether it would not be better to recast your code. Here is the same code without a mode change in the function: #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Opt('GuiOnEventMode', 1) Global $gui, $gui2 $gui = GUICreate("test", 400, 100) GUISetState(@SW_SHOW) GUISetOnEvent($gui_event_close, "Exitgui") $but = GUICtrlCreateButton("Test", 10, 10, 200, 50) GUICtrlSetOnEvent($but, "newgui") While 1 Sleep(10) WEnd Func newgui() If IsHWnd($gui2) Then GUIDelete($gui2) $gui2 = GUICreate("Test 2", 200, 50) GUISetState(@SW_SHOW) GUISetOnEvent($gui_event_close, "Exitgui") EndFunc ;==>newgui Func exitgui() Switch @GUI_WinHandle Case $gui Exit Case $gui2 GUIDelete($gui2) EndSwitch EndFunc ;==>exitguiM23 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
Naveed Posted July 13, 2010 Author Posted July 13, 2010 Naveed, I would go further than KaFu and say that, as a general rule, you should only ever use just the one mode your script. Switching modes in the same script is fraught with danger and should only be used in the most exceptional circumstances - and even then you should have alarm bells ringing in your head asking why the circumstances are so exceptional and whether it would not be better to recast your code. Here is the same code without a mode change in the function: #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Opt('GuiOnEventMode', 1) Global $gui, $gui2 $gui = GUICreate("test", 400, 100) GUISetState(@SW_SHOW) GUISetOnEvent($gui_event_close, "Exitgui") $but = GUICtrlCreateButton("Test", 10, 10, 200, 50) GUICtrlSetOnEvent($but, "newgui") While 1 Sleep(10) WEnd Func newgui() If IsHWnd($gui2) Then GUIDelete($gui2) $gui2 = GUICreate("Test 2", 200, 50) GUISetState(@SW_SHOW) GUISetOnEvent($gui_event_close, "Exitgui") EndFunc ;==>newgui Func exitgui() Switch @GUI_WinHandle Case $gui Exit Case $gui2 GUIDelete($gui2) EndSwitch EndFunc ;==>exitgui M23 Thanks for the advice M23, i really appreciate all your help with this, i have definitely gained a better understanding of how the code works, i only wish i knew as much as you guys when it comes to writing auoit script......maybe one day.....
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