Search code examples
c++windowscursorsdlmouse

How to change the mouse cursor to something else in c++?


How can I change the mouse cursor to something else in c++, Windows? I mean, change the pointer to another system default, for example, the hand icon. I don't know what code I can provide you, since I don't really have anything for the mouse. The only thing I have for the mouse, that isn't in use, is to hide it. If this helps tell you what I use or anything like that, here:

SDL_ShowCursor (SDL_DISABLE);

My c++ version isn't the newest, so that is something to note. And hiding the mouse pointer and having a picture follow it isn't something I can do since it uses way too many resources and is slow.


Solution

  • Use SDL_SetCursor If you want a system cursor, you can pass the return value of SDL_CreateSystemCursor to that function. See the documentation:

    https://wiki.libsdl.org/SDL_SetCursor

    https://wiki.libsdl.org/SDL_CreateSystemCursor

    https://web.archive.org/web/20210211163214/https://wiki.libsdl.org/SDL_CreateSystemCursor

    The documentation is currently somewhat lacking. The last link refers to the archived documentation, which contains the list of possible values for SDL_CreateSystemCursor

    Example:

    SDL_Cursor* cursor;
    cursor = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_HAND);
    SDL_SetCursor(cursor);