Page 2 of 2

Re: System tray button count

Posted: 09 Jan 2023, 22:53
by lexikos
I suppose you meant ahk_pid, not ahk_id.
Errors like this are immediately obvious in v2, because an error is thrown when you attempt to do things with a window or control that does not exist.

Re: System tray button count

Posted: 10 Jan 2023, 00:27
by JoeWinograd
lexikos wrote:I suppose you meant ahk_pid, not ahk_id.
Ah, that's it! Thank You, Thank You! One more question: Is it possible to determine inside the AHK_NOTIFYICON function if it was called due to a physical right-click on the icon or the hotkey sending the message?
lexikos wrote:Errors like this are immediately obvious in v2
Good to know for future development, but this particular program is 8,000+ lines, with 118 ErrorLevel!=0 checks (I just counted them), plus almost 1,000 lines from V1 libraries. Converting it to V2 is not on the horizon, so thanks very much for everything that you continue to do for V1. Regards, Joe

Re: System tray button count

Posted: 11 Jan 2023, 21:53
by JoeWinograd
Hi @lexikos,
The test script is working perfectly. I removed the Master instance (no need for it) and made a few cosmetic changes...everything works...left-click on the icon...right-click on the icon...and the hotkey. However, when I integrated the various (working!) components of the test script with my big program, the right and left physical clicks work, but the hotkey does not. The reason seems to be that SendMessage is coming back with FAIL (yes, the big script has the same correct WinTitle as the test script, i.e., ahk_pid %PID%). I thought it would be better to post a new thread with this issue. I'll really appreciate it if you get a chance to look at it and let me know your thoughts. Thanks, Joe

Re: System tray button count

Posted: 13 Jan 2023, 21:22
by lexikos
Is it possible to determine inside the AHK_NOTIFYICON function if it was called due to a physical right-click on the icon or the hotkey sending the message?
Monitor the AHK_NOTIFYICON message to react when the user interacts with the tray icon. Send the message to simulate user interaction with the tray icon. When I first suggested it, I was not expecting you to use OnMessage, because I saw (and still see) no reason to override the default handling.

If you want one instance of the script to trigger some custom action in another instance of the same script, there is no need to use AHK_NOTIFYICON. It doesn't matter that what you are doing is related to the tray icon or tray menu. You can pick any unused or registered message number and send that between instances, or you can use any other method of inter-process communication.

That aside, wParam should always equal AHK_NOTIFYICON (the ID of the tray icon) when the notification comes from the tray. When you send the message, wParam has whatever value you give it, or 0 if you omitted it. AutoHotkey ignores wParam, because it has only one tray icon.
; show context menu on right click - this should actually result in showing menu twice because system should automatically show it
AHK_NOTIFYICON is a custom message, with no system-defined meaning or handling. AutoHotkey has default handling of the message, which will be carried out if you do not return a number.

Re: System tray button count

Posted: 13 Jan 2023, 21:55
by JoeWinograd
lexikos wrote:Monitor the AHK_NOTIFYICON message to react when the user interacts with the tray icon.
Interesting idea. Looking for lParam=0x200 should do it.
lexikos wrote:no reason to override the default handling
Yes, no reason for the right-click, but I'm using it now for left-click to do Menu,Tray,Show (I had been using SKAN's NotifyTrayClick function with the NotifyTrayClick_202: label).
lexikos wrote:If you want one instance of the script to trigger some custom action in another instance of the same script, there is no need to use AHK_NOTIFYICON.
Got it!
lexikos wrote:When you send the message, wParam has whatever value you give it, or 0 if you omitted it. AutoHotkey ignores wParam, because it has only one tray icon.
Ah, I can use wParam for my own purposes knowing that AutoHotkey ignores it... clever!
lexikos wrote:AutoHotkey has default handling of the message, which will be carried out if you do not return a number.
Understood.

Thanks very much!

Re: System tray button count

Posted: 13 Jan 2023, 22:26
by lexikos
JoeWinograd wrote:
13 Jan 2023, 21:55
Ah, I can use wParam for my own purposes knowing that AutoHotkey ignores it... clever!
You were already relying on it, by omitting wParam rather than passing the tray icon ID.

Re: System tray button count

Posted: 13 Jan 2023, 22:57
by JoeWinograd
lexikos wrote:You were already relying on it, by omitting wParam rather than passing the tray icon ID.
True enough.