Jump to content
legend

Traymenu - dllcall

Recommended Posts

legend
#include <Constants.au3>

    Opt("TrayMenuMode", 3) 
    Opt("TrayOnEventMode", 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
            Exit
        Case $aboutItem
            Msgbox(0, "Info", "Just for fun...")
    EndSwitch
WEnd

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

 

I have this code that will show the traymenu near the mouse when you click "t". (compile it and run it and click t).

Now the thing is, if i have another compiled autoit script running, it will no longer show the traymenu, instead it will show:

 

vSqhPoV.png

 

I thought I would solve the issue if I changed the classname "AutoIt v3 GUI", but that didn't solve it:

https://www.autoitscript.com/autoit3/docs/libfunctions/_WinAPI_RegisterClassEx.htm

Edited by legend

Share this post


Link to post
Share on other sites
legend
1 hour ago, InnI said:

You can use some unique title for AutoIt window

...

$title = _WinAPI_CreateGUID()
AutoItWinSetTitle($title)

...

Func ShowTrayMenu()
    DllCall("user32.dll", "int", "SendMessage", "hwnd", WinGetHandle($title), "int", $MY_WM_NOTIFYICON, "int", 0, "int", $WM_LBUTTONDOWN)
EndFunc

 

Thanks a lot lnnl :) learned something new, I didn't new those 2 commands, it works perfectly 

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

×