Jump to content

Tray menu action before opening menu


nend
 Share

Recommended Posts

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   ;==>Example

Thanks for the help.

Link to comment
Share on other sites

WM_ACTIVATEAPP seems to capture tray menu activation.

 

#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

 

Link to comment
Share on other sites

WM_ACTIVATEAPP seems to capture tray menu activation.

 

#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

Thanks KaFu,

This is just the thing I was looking for.

You really helped me!

 

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...