nend Posted September 3, 2015 Share Posted September 3, 2015 Hi There,Is it possible to do some action before opening tray menu when the icon in the systray is clicked?#NoTrayIcon #include <MsgBoxConstants.au3> #include <TrayConstants.au3> Opt("TrayMenuMode", 1) Example() Func Example() Local $iSettings = TrayCreateMenu("Settings") Local $idAbout = TrayCreateItem("About") Local $idExit = TrayCreateItem("Exit") TraySetState($TRAY_ICONSTATE_SHOW) ; Show the tray menu. While 1 Switch TrayGetMsg() Case $TRAY_EVENT_PRIMARYDOWN ConsoleWrite("Do something before the menu opens" & @CRLF) Case $idAbout MsgBox($MB_SYSTEMMODAL, "", "AutoIt tray menu example." & @CRLF & @CRLF & _ "Version: " & @AutoItVersion & @CRLF & _ "Install Path: " & StringLeft(@AutoItExe, StringInStr(@AutoItExe, "\", 0, -1) - 1)) ; Find the folder of a full path. Case $idExit ; Exit the loop. ExitLoop EndSwitch WEnd EndFunc ;==>ExampleThanks for the help. Link to comment Share on other sites More sharing options...
KaFu Posted September 3, 2015 Share Posted September 3, 2015 WM_ACTIVATEAPP seems to capture tray menu activation. expandcollapse popup#NoTrayIcon #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <Constants.au3> Opt("TrayMenuMode", 1) Example() Func Example() Local $iSettings = TrayCreateMenu("Settings") Local $idAbout = TrayCreateItem("About") GUICreate("") ; create GUI but do not show it, otherwise windows messages will not be received GUIRegisterMsg($WM_ACTIVATEAPP, "WM_ACTIVATEAPP") Local $idExit = TrayCreateItem("Exit") TraySetState() While 1 Switch TrayGetMsg() Case $TRAY_EVENT_PRIMARYDOWN ConsoleWrite("Do something before the menu opens" & @CRLF) Case $idAbout MsgBox(0, "", "AutoIt tray menu example." & @CRLF & @CRLF & _ "Version: " & @AutoItVersion & @CRLF & _ "Install Path: " & StringLeft(@AutoItExe, StringInStr(@AutoItExe, "\", 0, -1) - 1)) ; Find the folder of a full path. Case $idExit ; Exit the loop. ExitLoop EndSwitch WEnd EndFunc ;==>Example Func WM_ACTIVATEAPP($hWnd, $iMsg, $iwParam, $ilParam) If $iwParam = 1 Then ; activated If @AutoItPID = WinGetProcess($hWnd) Then ConsoleWrite("! " & TimerInit() & @TAB & "WM_ACTIVATEAPP" & @TAB & $hWnd & @TAB & $iMsg & @TAB & $iwParam & @TAB & $ilParam & @CRLF) MsgBox(64, "Better...", "...do something quick here and do not block the message queue...") EndIf EndIf Return $GUI_RUNDEFMSG EndFunc ;==>WM_ACTIVATEAPP OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2022-Nov-26) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Feb-16) HMW - Hide my Windows (2018-Sep-16) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2023-Jun-03) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
nend Posted September 4, 2015 Author Share Posted September 4, 2015 WM_ACTIVATEAPP seems to capture tray menu activation. expandcollapse popup#NoTrayIcon #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <Constants.au3> Opt("TrayMenuMode", 1) Example() Func Example() Local $iSettings = TrayCreateMenu("Settings") Local $idAbout = TrayCreateItem("About") GUICreate("") ; create GUI but do not show it, otherwise windows messages will not be received GUIRegisterMsg($WM_ACTIVATEAPP, "WM_ACTIVATEAPP") Local $idExit = TrayCreateItem("Exit") TraySetState() While 1 Switch TrayGetMsg() Case $TRAY_EVENT_PRIMARYDOWN ConsoleWrite("Do something before the menu opens" & @CRLF) Case $idAbout MsgBox(0, "", "AutoIt tray menu example." & @CRLF & @CRLF & _ "Version: " & @AutoItVersion & @CRLF & _ "Install Path: " & StringLeft(@AutoItExe, StringInStr(@AutoItExe, "\", 0, -1) - 1)) ; Find the folder of a full path. Case $idExit ; Exit the loop. ExitLoop EndSwitch WEnd EndFunc ;==>Example Func WM_ACTIVATEAPP($hWnd, $iMsg, $iwParam, $ilParam) If $iwParam = 1 Then ; activated If @AutoItPID = WinGetProcess($hWnd) Then ConsoleWrite("! " & TimerInit() & @TAB & "WM_ACTIVATEAPP" & @TAB & $hWnd & @TAB & $iMsg & @TAB & $iwParam & @TAB & $ilParam & @CRLF) MsgBox(64, "Better...", "...do something quick here and do not block the message queue...") EndIf EndIf Return $GUI_RUNDEFMSG EndFunc ;==>WM_ACTIVATEAPPThanks KaFu,This is just the thing I was looking for.You really helped me! 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