mydoghasworms Posted January 28, 2014 Share Posted January 28, 2014 I posted this question on StackOverflow, but I don't see a lot of activity there, so I think my chance of getting it answered here is perhaps better: I have an AutoIt script in which I open a settings dialog from a system tray menu entry. When opening the dialog this way, messages via button clicks are not handled. On the other hand, when opening the dialog directly (as indicated in the code below, which you can easily test by uncommenting this call and commenting out the call for the system tray entry), then the messages are handled successfully. Here is my script. When calling SettingsDialog directly (without going via the systray menu), the OK and Cancel buttons work, but otherwise not. (Sorry, I don't know how to format the code nicely. When pasting, I lose the tabs). expandcollapse popup#include <GUIConstantsEx.au3> #include <ButtonConstants.au3> ;; Start program in system tray SetupSystemTrayEntry() ;; When calling settings dialog directly, messages are handled properly ;;SettingsDialog() Func SetupSystemTrayEntry() Opt("TrayMenuMode", 1) $settingsitem = TrayCreateItem("Settings") TrayCreateItem("") $exititem = TrayCreateItem("Exit") TraySetState() While 1 Local $traymsg = TrayGetMsg() Select Case $traymsg = 0 ContinueLoop Case $traymsg = $settingsitem SettingsDialog() ;; Bring up settings dialog Case $traymsg = $exititem Exit ;; Exit program EndSelect WEnd EndFunc ;==>SetupSystemTrayEntry Func SettingsDialog() GUICreate("Settings", 400, 150, @DesktopWidth / 2 - 200, @DesktopHeight / 2 - 75) $ok_button = GUICtrlCreateButton("OK", 100, 100, 80, 25, $BS_DEFPUSHBUTTON) $cancel_button = GUICtrlCreateButton("Cancel", 200, 100, 80, 25) GUISetState() Do ;; These messages are never handled when the dialog is brought up from ;; the system tray menu entry above, but when calling this function ;; directly, it works Local $settmsg = GUIGetMsg() Select Case $settmsg = $ok_button ExitLoop Case $settmsg = $cancel_button ExitLoop EndSelect Until $settmsg = $GUI_EVENT_CLOSE EndFunc ;==>SettingsDialog Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 28, 2014 Moderators Share Posted January 28, 2014 mydoghasworms,Welcome to the AutoIt forum. Your buttons work for me when called from the tray menu - why do you think they do not? expandcollapse popup#include <GUIConstantsEx.au3> #include <ButtonConstants.au3> ;; Start program in system tray SetupSystemTrayEntry() ;; When calling settings dialog directly, messages are handled properly ;;SettingsDialog() Func SetupSystemTrayEntry() Opt("TrayMenuMode", 1) $settingsitem = TrayCreateItem("Settings") TrayCreateItem("") $exititem = TrayCreateItem("Exit") TraySetState() While 1 Local $traymsg = TrayGetMsg() Select Case $traymsg = 0 ContinueLoop Case $traymsg = $settingsitem SettingsDialog() ;; Bring up settings dialog Case $traymsg = $exititem Exit ;; Exit program EndSelect WEnd EndFunc ;==>SetupSystemTrayEntry Func SettingsDialog() GUICreate("Settings", 400, 150, @DesktopWidth / 2 - 200, @DesktopHeight / 2 - 75) $ok_button = GUICtrlCreateButton("OK", 100, 100, 80, 25, $BS_DEFPUSHBUTTON) $cancel_button = GUICtrlCreateButton("Cancel", 200, 100, 80, 25) GUISetState() Do ;; These messages are never handled when the dialog is brought up from ;; the system tray menu entry above, but when calling this function ;; directly, it works Local $settmsg = GUIGetMsg() Select Case $settmsg = $ok_button MsgBox(0, "Hi", "OK Pressed") ExitLoop Case $settmsg = $cancel_button MsgBox(0, "Hi", "Cancel Pressed") ExitLoop EndSelect Until $settmsg = $GUI_EVENT_CLOSE EndFunc ;==>SettingsDialogAnd see here how to post code. 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...
mydoghasworms Posted January 28, 2014 Author Share Posted January 28, 2014 Thanks for the welcome and the hint about the code. The buttons (OK, Cancel) respond when I call that function directly. That is, the popup disappears (as it exits out of that loop). When I open from the system tray as per the example, the buttons do nothing when clicked. Could it be a platform issue? I am running it as an x86 script on Windows 7 64 bit. Link to comment Share on other sites More sharing options...
mydoghasworms Posted January 28, 2014 Author Share Posted January 28, 2014 I just tried your code. When I click a button, it pops up a message box, then does nothing (dialog stays there). Successive button presses do nothing. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 28, 2014 Moderators Share Posted January 28, 2014 mydoghasworms, When I click a button, it pops up a message box, then does nothing (dialog stays there). Successive button presses do nothingWhich is exactly what your code asks the script to do. You run ExitLoop after the button press so you immediately exit the SettingsDialog function. What do you want to happen? 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...
mydoghasworms Posted January 28, 2014 Author Share Posted January 28, 2014 Okay... I see what is happening. When calling directly, the script exits when the function exits, and the dialog disappears. When calling the dialog from the systray function, the function exits, but the dialog is still there, correct? I need to explicitly dismiss/close/exterminate my dialog, is that right? How do I dismiss the dialog? I will check in the API docs quickly... Thanks! Now I see what is happening, so I can be on my merry way again. Link to comment Share on other sites More sharing options...
mydoghasworms Posted January 28, 2014 Author Share Posted January 28, 2014 Now I changed my script to set up the settings dialog once, store the handle in a global variable, and show the dialog when needed. But this is not working as expected. The dialog never shows and the script exits (though it does enter the ShowSettingsDialog function): expandcollapse popup#include <GUIConstantsEx.au3> #include <ButtonConstants.au3> ;; Set up settings dialog InitSettingsDialog(); ;; Start program in system tray SetupSystemTrayEntry() Global $settings_window_handle Func SetupSystemTrayEntry() Opt("TrayMenuMode", 1) $settingsitem = TrayCreateItem("Settings") TrayCreateItem("") $exititem = TrayCreateItem("Exit") TraySetState() While 1 Local $traymsg = TrayGetMsg() Select Case $traymsg = 0 ContinueLoop Case $traymsg = $settingsitem ShowSettingsDialog() ;; Bring up settings dialog Case $traymsg = $exititem Exit ;; Exit program EndSelect WEnd EndFunc ;==>SetupSystemTrayEntry Func InitSettingsDialog() $settings_window_handle = GUICreate("Settings", 400, 150, @DesktopWidth / 2 - 200, @DesktopHeight / 2 - 75) Global $ok_button = GUICtrlCreateButton("OK", 100, 100, 80, 25, $BS_DEFPUSHBUTTON) Global $cancel_button = GUICtrlCreateButton("Cancel", 200, 100, 80, 25) EndFunc ;==>SettingsDialog Func ShowSettingsDialog() GUISetState(@SW_SHOW, $settings_window_handle) Local $settmsg While 1 $settmsg = GUIGetMsg() Select Case $settmsg = $ok_button GUISetState(@SW_HIDE, $settings_window_handle) ExitLoop Case $settmsg = $cancel_button ExitLoop GUISetState(@SW_HIDE, $settings_window_handle) EndSelect WEnd EndFunc Link to comment Share on other sites More sharing options...
mydoghasworms Posted January 28, 2014 Author Share Posted January 28, 2014 OK, I had declared $settings_window_handle after initializing it, so it was local only the initializer function. Now, I tried with the following code, and it shows the dialog successfully, but does not hide it. In this case, it does not reach the Select in the loop. expandcollapse popup#include <GUIConstantsEx.au3> #include <ButtonConstants.au3> Global $settings_window_handle ;; Set up settings dialog InitSettingsDialog(); ;; Start program in system tray SetupSystemTrayEntry() Func SetupSystemTrayEntry() Opt("TrayMenuMode", 1) $settingsitem = TrayCreateItem("Settings") TrayCreateItem("") $exititem = TrayCreateItem("Exit") TraySetState() While 1 Local $traymsg = TrayGetMsg() Select Case $traymsg = 0 ContinueLoop Case $traymsg = $settingsitem ShowSettingsDialog() ;; Bring up settings dialog Case $traymsg = $exititem Exit ;; Exit program EndSelect WEnd EndFunc ;==>SetupSystemTrayEntry Func InitSettingsDialog() $settings_window_handle = GUICreate("Settings", 400, 150, @DesktopWidth / 2 - 200, @DesktopHeight / 2 - 75) Global $ok_button = GUICtrlCreateButton("OK", 100, 100, 80, 25, $BS_DEFPUSHBUTTON) Global $cancel_button = GUICtrlCreateButton("Cancel", 200, 100, 80, 25) EndFunc ;==>SettingsDialog Func ShowSettingsDialog() GUISetState(@SW_SHOW, $settings_window_handle) Local $settmsg While 1 $settmsg = GUIGetMsg() Select Case $settmsg = $ok_button MsgBox(0, "test", "test") GUISetState(@SW_HIDE, $settings_window_handle) ExitLoop Case $settmsg = $cancel_button ExitLoop GUISetState(@SW_HIDE, $settings_window_handle) EndSelect WEnd EndFunc Link to comment Share on other sites More sharing options...
Moderators Solution Melba23 Posted January 28, 2014 Moderators Solution Share Posted January 28, 2014 mydoghasworms,If the GUI is simple, then creating it intially and hiding/showing it as required is always a good idea in my book. Try this slight variation - I also used Switch in place of Select just to show how it is done:expandcollapse popup#include <GUIConstantsEx.au3> ; Do not declare Global variables in a function <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Global $settings_window_handle, $ok_button, $cancel_button ;; Set up settings dialog InitSettingsDialog(); ;; Start program in system tray SetupSystemTrayEntry() Func SetupSystemTrayEntry() Opt("TrayMenuMode", 1) $settingsitem = TrayCreateItem("Settings") TrayCreateItem("") $exititem = TrayCreateItem("Exit") TraySetState() While 1 Switch TrayGetMsg() Case $settingsitem ShowSettingsDialog() ;; Bring up settings dialog Case $exititem Exit ;; Exit program EndSwitch WEnd EndFunc ;==>SetupSystemTrayEntry Func InitSettingsDialog() ; Create $settings_window_handle = GUICreate("Settings", 400, 150, @DesktopWidth / 2 - 200, @DesktopHeight / 2 - 75) $ok_button = GUICtrlCreateButton("OK", 100, 100, 80, 25, $BS_DEFPUSHBUTTON) $cancel_button = GUICtrlCreateButton("Cancel", 200, 100, 80, 25) GUISetState(@SW_HIDE, $settings_window_handle) EndFunc ;==>SettingsDialog Func ShowSettingsDialog() GUISetState(@SW_SHOW, $settings_window_handle) While 1 Switch GUIGetMsg() Case $ok_button MsgBox(0, "test", "test") ExitLoop Case $cancel_button ExitLoop EndSwitch WEnd GUISetState(@SW_HIDE, $settings_window_handle) EndFuncBetter? 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...
mydoghasworms Posted January 29, 2014 Author Share Posted January 29, 2014 Yes, that works! Thanks! So when I compare your source and mine, the only thing you did differently is to initially hide the dialog at the time of creating it? That defies all logic, but at least now it works. Thanks for all your help. Link to comment Share on other sites More sharing options...
mydoghasworms Posted January 29, 2014 Author Share Posted January 29, 2014 BTW, your script was missing #include <ButtonConstants.au3> but that is a mere trifle :-) Thanks again. 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