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.
System tray button count
Re: System tray button count
I suppose you meant ahk_pid, not ahk_id.
- JoeWinograd
- Posts: 2246
- Joined: 10 Feb 2014, 20:00
- Location: U.S. Central Time Zone
Re: System tray button count
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:I suppose you meant ahk_pid, not ahk_id.
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, Joelexikos wrote:Errors like this are immediately obvious in v2
- JoeWinograd
- Posts: 2246
- Joined: 10 Feb 2014, 20:00
- Location: U.S. Central Time Zone
Re: System tray button count
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
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
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.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?
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.
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.; show context menu on right click - this should actually result in showing menu twice because system should automatically show it
- JoeWinograd
- Posts: 2246
- Joined: 10 Feb 2014, 20:00
- Location: U.S. Central Time Zone
Re: System tray button count
Interesting idea. Looking for lParam=0x200 should do it.lexikos wrote:Monitor the AHK_NOTIFYICON message to react when the user interacts with the tray icon.
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:no reason to override the default handling
Got it!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.
Ah, I can use wParam for my own purposes knowing that AutoHotkey ignores it... clever!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.
Understood.lexikos wrote:AutoHotkey has default handling of the message, which will be carried out if you do not return a number.
Thanks very much!
Re: System tray button count
You were already relying on it, by omitting wParam rather than passing the tray icon ID.JoeWinograd wrote: ↑13 Jan 2023, 21:55Ah, I can use wParam for my own purposes knowing that AutoHotkey ignores it... clever!
- JoeWinograd
- Posts: 2246
- Joined: 10 Feb 2014, 20:00
- Location: U.S. Central Time Zone
Re: System tray button count
True enough.lexikos wrote:You were already relying on it, by omitting wParam rather than passing the tray icon ID.