Monitor Tray Icon Right-Click without Blocking other Events Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
Posts: 78
Joined: 10 Feb 2018, 19:05

Monitor Tray Icon Right-Click without Blocking other Events

22 Jan 2019, 13:57

I have a script that monitors 0x404 messages to detect when the script's tray icon is right-clicked, but I noticed that when I do this, the script's normal responses to tray icon events are disabled. Is there any way to restore the default tray functionality of the script while still monitoring right-clicks?
Posts: 5836
Joined: 30 Sep 2013, 06:48

Re: Monitor Tray Icon Right-Click without Blocking other Events  Topic is solved

22 Jan 2019, 15:58

I would say yes, but like always in such a case, a meaningful code snippet would have been nice - because I am sure most people don't know all the messages (like for the right mouse button) without looking them up... and they will have to make assumptions about your code that might turn out wrong (aka "not efficient"). But anyway, here we go, this is how I understand your problem concerning the OnMessage function:

The "script's normal responses" are only disabled by the registered function, if you tell the script to do just this: wrote:What the Function Should Return

If a monitor function uses Return without any parameters, or it specifies a blank value such as "" (or it never uses Return at all), the incoming message goes on to be processed normally when the function finishes. The same thing happens if the function Exits or causes a runtime error such as running a nonexistent file. By contrast, returning an integer causes it to be sent immediately as a reply; that is, the program does not process the message any further. For example, a function monitoring WM_LBUTTONDOWN (0x201) may return an integer to prevent the target window from being notified that a mouse click has occurred. In many cases (such as a message arriving via PostMessage), it does not matter which integer is returned; but if in doubt, 0 is usually safest.

To check this, consider this code snippet:

Code: Select all

OnMessage(0x404, "AHK_NOTIFYICON")

AHK_NOTIFYICON(wParam, lParam) 
    if (lParam = 0x205) 	; WM_RBUTTONDOWN = 0x204, WM_RBUTTONUP = 0x205
        traytip, Right click, on tray icon	; do here whatever you intend with the monitoring
		; return 0  	; uncommenting deactivates further processing of the 0x205 message
By default, the context menu appears when the right mouse button goes up on the icon, hence I took 0x205. Now try it first without return 0 and then uncomment it. In the latter case, the message is not processed any further; in the former, the context menu should be shown.
If you feel adventurous now, you could also try just return (without any parameter like the 0; compare the quote above).
Now, I assumed you copied one of the examples from the forum that contain return 0 or something similar. If the problem persists, please elaborate and show the code you tried so far. Hope this helps!

Return to “Ask For Help”

Who is online

Users browsing this forum: Bing [Bot], DataLife, Google [Bot], Melchisedek, pgeugene, rothvin, roysubs, Spawnova and 55 guests