문제

시스템 트레이에 NotifyIcon이 있습니다.사용자가 왼쪽 클릭 할 때 어떻게 탐지 할 수 있습니까?MouseDown 이벤트가 내가 사용하고자하는 것만 큼 될 것이라고 가정했지만 마우스 오른쪽 클릭과 중간 단추를 처리합니다.왼쪽 버튼을 클릭하면 사용자가 놓인 후에 만 발생합니다 (정상적인 클릭 만 수행 한 것처럼).MouseDown 이벤트 만 얻는 방법이 있습니까?

도움이 되었습니까?

해결책

This is by design, the shell synthesizes the MouseDown message from the up event. You'll see why it works this way when you click and hold the button down and then start dragging. Note how the notification area overflow window pops up and lets you drag the icon into it to remove it from the visible area. It can't work both ways.

Technically you could hook the window owned by Explorer.exe to get a crack at the messages before Explorer does with SetWindowsHookEx(). That however requires a kind of DLL that you cannot write in C#, it needs to be injected into Explorer. Very destabilizing and hard to beat the competition that is trying to do the same thing. Also the kind of code that causes sleepless nights for the Microsoft appcompat team.

다른 팁

It appears that the underlying 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 reveals standard mouse down event handling, so if the Win32 message was being sent at the "correct" time it would work as you want/expect.

I have to agree with a previous comment that NotifyIcon will be swallowing WM_LBUTTONDOWN since it needs to do mouse capture to allow the user to drag the icons about.

It's possible that this article about creating a tray icon for WPF will be useful since it shows how to use SetWindowsHookEx etc from C#.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top