How to handle WM_SETCURSOR in C #

In the application for the media player, I hid the cursor with SetCursor(NULL) and so that Windows did not indicate a reset cursor state, I processed WM_SETCURSOR in my WndProc method.

 protected override void WndProc(ref Message m) { switch (m.Msg) { case WM.SETCURSOR: base.WndProc(ref m); int lowWord = (m.LParam.ToInt32() << 16) >> 16; if (lowWord == HTCLIENT && FullScreen) { SetCursor(IntPtr.Zero); // hides cursor m.Result = (IntPtr)1; // return TRUE; equivalent in C++ } return; } } 

However, when the cursor is in the client area (aka LOWORD(lParam) == HTCLIENT ), WM_SETCURSOR never starts in WndProc . Therefore, I never receive the WM_SETCURSOR message when the cursor is in the client area, and only receive it when LOWORD(lParam) != HTCLIENT .

However, in Spy ++, it clearly shows that the application received WM_SETCURSOR and WM_MOUSEMOVE .

Where is the message lost / processed? What do I need to do to receive a WM_SETCURSOR message in C #?

+4
source share
1 answer

My application has several panels covering the application. So another user noticed to me that since each control has its own WndProc , the WM_SETCURSOR method WM_SETCURSOR not passed to the form below it. To receive these messages, I would have to override each of these panels with my own WndProc method.

However, the above code works if there are no controls spanning the form in which the cursor is located.

0
source

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


All Articles