Does NotifyIcon have the equivalent of MouseDown?

I have NotifyIcon in the system tray. How can I tell when a user clicked it down? I assumed that the MouseDown event MouseDown be what I want to use, but it only handles the right-click and middle-click. For a left-click, it is launched only after the user has released (as they just did a normal click in them). Is there a way to get a MouseDown event?

+6
source share
2 answers

This shell design synthesizes a MouseDown message from an up event. You will see why it works this way when you press and hold the button and then start dragging and dropping. Notice how the notification area overflow window pops up and allows you to drag the icon into it to remove it from the visible area. He cannot work in both directions.

Technically, you can connect a window owned by Explorer.exe to get cracks in the messages Explorer does with SetWindowsHookEx (). However, this requires a certain DLL, which you cannot write in C #, it must be entered in Explorer. It is very destabilizing and difficult to defeat competition that is trying to do the same. Also the type of code that causes sleepless nights for the Microsoft appcompat team.

+4
source

It seems that the core Win32 API Shell_NotifyIcon sends a WM_LBUTTONDOWN message when the user clicks the icon. According to MSDN anyway.

Examining the Windows Forms source code for NotifyIcon shows the standard mouse event handling, so if a Win32 message was sent at the "right" time, it will work the way you want / expect.

I have to agree with the previous comment that NotifyIcon will swallow WM_LBUTTONDOWN, since it needs to capture the mouse so that the user can drag and drop the icons.

It is possible that this article on creating a tray icon for WPF will be useful as it shows how to use SetWindowsHookEx , etc. from c #.

+3
source

Source: https://habr.com/ru/post/909688/


All Articles