How to hide the cursor completely?

1

When I call ShowCursor(0) (which by the way, does not take an HWND, this is weird), the cursor is hidden, but when I do a special action, for example resizing the window or drag-and-drop a file, the cursor corresponding to this action appears. I don't want to see the cursor whatever action the user is doing. If you wonder why, it's because I'd like to draw it with OpenGL.

I have a popup and layered window:

#define UNICODE
#include <windows.h>
#include <dwmapi.h>

LRESULT CALLBACK wnd_proc(HWND hWnd, UINT uMsg, WPARAM wp, LPARAM lp){
    switch(uMsg){
        case WM_CREATE: return 0;
        case WM_NCHITTEST: return HTBOTTOM;
        case WM_DESTROY: PostQuitMessage(0); return 0;
        default: return DefWindowProc(hWnd, uMsg, wp, lp);
    }
}

HDC hDC; HGLRC hRC;

int main(void){
    WNDCLASSEX wcx = {};
    wcx.cbSize = sizeof(WNDCLASSEX);
    wcx.lpfnWndProc = wnd_proc;
    wcx.lpszClassName = L"Win32Class";
    wcx.style = CS_OWNDC | CS_HREDRAW | CS_VREDRAW;
    wcx.hbrBackground = CreateSolidBrush(0x00000000);
    wcx.hCursor = LoadCursor(NULL, IDC_ARROW);
    RegisterClassEx(&wcx);

    HWND hWnd = CreateWindowEx(WS_EX_ACCEPTFILES | WS_EX_LAYERED, wcx.lpszClassName,
        L"Win32Window", WS_POPUP | WS_VISIBLE, 50, 50, 800, 400, NULL, NULL, NULL, NULL);

    SetLayeredWindowAttributes(hWnd, RGB(200, 0, 200), 0, LWA_COLORKEY);
    ShowCursor(0);

    /*DWM_BLURBEHIND blur = {0};
    blur.dwFlags = DWM_BB_ENABLE | DWM_BB_BLURREGION;
    blur.fEnable = 1;
    blur.hRgnBlur = CreateRectRgn(0, 0, -1, -1);
    DwmEnableBlurBehindWindow(hWnd, &blur);*/

    MSG msg; while(GetMessage(&msg, NULL, 0, 0)){
        DispatchMessage(&msg);
    }
}

This is a truncated part of my test file. OpenGL is not included, but I just need to know how to delete the cursor.

If you compile and execute it, you can see that when your cursor is on the window, it is not visible, but when you resize the window the cursor appears, same as when you drag-and-drop a file.

c
winapi
asked on Stack Overflow Apr 3, 2020 by (unknown user) • edited Apr 3, 2020 by Remy Lebeau

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0