System tray button count

Discuss other programming languages besides AutoHotkey
lexikos
Posts: 9780
Joined: 30 Sep 2013, 04:07
Contact:

Re: System tray button count

Post by lexikos » 09 Jan 2023, 22:53

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.

User avatar
JoeWinograd
Posts: 2246
Joined: 10 Feb 2014, 20:00
Location: U.S. Central Time Zone

Re: System tray button count

Post by JoeWinograd » 10 Jan 2023, 00:27

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

User avatar
JoeWinograd
Posts: 2246
Joined: 10 Feb 2014, 20:00
Location: U.S. Central Time Zone

Re: System tray button count

Post by JoeWinograd » 11 Jan 2023, 21:53

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

lexikos
Posts: 9780
Joined: 30 Sep 2013, 04:07
Contact:

Re: System tray button count

Post by lexikos » 13 Jan 2023, 21:22

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.

User avatar
JoeWinograd
Posts: 2246
Joined: 10 Feb 2014, 20:00
Location: U.S. Central Time Zone

Re: System tray button count

Post by JoeWinograd » 13 Jan 2023, 21:55

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!

lexikos
Posts: 9780
Joined: 30 Sep 2013, 04:07
Contact:

Re: System tray button count

Post by lexikos » 13 Jan 2023, 22:26

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.

User avatar
JoeWinograd
Posts: 2246
Joined: 10 Feb 2014, 20:00
Location: U.S. Central Time Zone

Re: System tray button count

Post by JoeWinograd » 13 Jan 2023, 22:57

lexikos wrote:You were already relying on it, by omitting wParam rather than passing the tray icon ID.
True enough.

Post Reply

Return to “Other Programming Languages”