Search code examples
c++winapimouse-cursor

Cursor style doesn't stay updated


I have a normal Windows GUI application (made using the API, not MFC) and as I move my mouse on and off the application and the mouse changes styles (like when you move it over the border, it changes to a resize arrow, etc.) but sometimes it "sticks" in that style, so that I can move the mouse around and it will stay in a resize arrow or whatever, even after it's off the window border. It fixes itself if I move it over another control.

It's just an inconvenience, but it looks unprofessional and I would like to fix it. How can I make it where it stays up to date all the time?


Solution

  • Set a valid cursor handle when you register your window class. See WNDCLASSEX::hCursor. Use LoadCursor to load a valid cursor. Like,

    WNDCLASSEX wc = {0};
    ...
    wc.hCursor = LoadCursor(NULL, IDC_ARROW);
    ...
    RegisterClassEx(&wc);