Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WinApi, hide cursor inside window client area

Tags:

winapi

I want hide cursor inside window client area without borders and title bar (it is simple opengl application). So, function

    ShowCursor(FALSE);

is not suitable. After some searching the winapi i find this solution:

    //when create window class for application window
    WNDCLASSEX WndClass;
    //...
    BYTE CursorMaskAND[] = { 0xFF };
    BYTE CursorMaskXOR[] = { 0x00 };
    WndClass.hCursor = CreateCursor(NULL, 0,0,1,1, CursorMaskAND, CursorMaskXOR);

Is this a good way to solve this typical task? What way is the best?

like image 611
And390 Avatar asked Jan 30 '26 20:01

And390


1 Answers

MSDN says that you can set the WNDCLASSEX hCursor field to NULL, in which case you must explicitly set the cursor in your window procedure (which means handling the WM_SETCURSOR message). For example:

if (Msg == WM_SETCURSOR && LOWORD(lParam) == HTCLIENT)
{
    SetCursor(NULL);

    return TRUE;
}

// Remainder of window procedure code

Checking for HTCLIENT ensures that the cursor is only hidden in the client area, and that the window frame and caption will use the correct cursors.

like image 92
djhayman Avatar answered Feb 01 '26 21:02

djhayman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!