Sign in to follow this  
Followers 0
ZoScr

How to automatically "click" my script's tray icon?

6 posts in this topic

My script has a tray icon, with tray menu items. I'd like a global hotkey to bring up this menu. Can I do this? Should it be done via somehow clicking the tray icon (I have tried but failed to figure out how to do this), or should I instead just forget this approach and instead have the hotkey popup a new window with a menu?

Thanks in advance...

Share this post


Link to post
Share on other sites



Sample script for showing the traymenu somewhere:

#include <Constants.au3>

Opt("TrayMenuMode", 1)
Opt("WinTitleMatchMode", 4)

Global Const $TPM_BOTTOMALIGN   = 0x0020

$aboutItem  = TrayCreateItem("About")
TrayCreateItem("")
$exitItem   = TrayCreateItem("Exit")

HotKeySet("^!t", "ShowTrayMenu") ; Ctrl + Alt + t

While 1
    $Msg = TrayGetMsg()
    Switch $Msg
        Case $exitItem
            ExitLoop
        Case $aboutItem
            Msgbox(0, "Info", "Just for fun...")
    EndSwitch
WEnd

Exit

Func ShowTrayMenu()
    Local $stPoint = DllStructCreate("int;int")
    DllCall("user32.dll", "int", "GetCursorPos", _
                                "ptr", DllStructGetPtr($stPoint))
    
    DllCall("user32.dll", "int", "TrackPopupMenuEx", _
                                "hwnd", TrayItemGetHandle(0), _
                                "int", $TPM_BOTTOMALIGN, _
                                "int", DllStructGetData($stPoint, 1), _
                                "int", DllStructGetData($stPoint, 2), _
                                "hwnd", WinGetHandle("classname=AutoIt v3"), _
                                "ptr", 0)
EndFunc

Share this post


Link to post
Share on other sites

2nd possibility:

#include <Constants.au3>

Opt("TrayMenuMode", 1)
Opt("WinTitleMatchMode", 4)

Global Const $WM_USER           = 0x0400
Global Const $MY_WM_NOTIFYICON  = $WM_USER + 1
Global Const $WM_LBUTTONDOWN    = 0x0201

$aboutItem  = TrayCreateItem("About")
TrayCreateItem("")
$exitItem   = TrayCreateItem("Exit")

HotKeySet("^!t", "ShowTrayMenu") ; Ctrl + Alt + t

While 1
    $Msg = TrayGetMsg()
    Switch $Msg
        Case $exitItem
            ExitLoop
        Case $aboutItem
            Msgbox(0, "Info", "Just for fun...")
    EndSwitch
WEnd

Exit

Func ShowTrayMenu()
    DllCall("user32.dll", "int", "SendMessage", _
                                "hwnd", WinGetHandle("classname=AutoIt v3"), _
                                "int", $MY_WM_NOTIFYICON, _
                                "int", 0, _
                                "int", $WM_LBUTTONDOWN)
EndFunc

Greets :D

Holger

Share this post


Link to post
Share on other sites

2nd possibility:

Global Const $WM_USER           = 0x0400
Global Const $MY_WM_NOTIFYICON  = $WM_USER + 1
Global Const $WM_LBUTTONDOWN    = 0x0201
Interesting suggestion, Holger! How about if I need to double click the tray icon (as may be the case for a non-AutoIt application's tray menu)?

Thanks!

Share this post


Link to post
Share on other sites

Whenever I try to use $TRAY_EVENT_PRIMARYDOUBLE, it says variable used without being specified. I've searched through all of the included .au3 files that came with autoit, and found no traces of any of the TRAY_EVENT functions. ANY IDEAS????


- Dan [Website]

Share this post


Link to post
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
Sign in to follow this  
Followers 0