SetSystemCursor not honoring cursor size

Julian Castillo 0 Reputation points
2025-01-23T20:07:56.85+00:00

I'm currently trying to set the system cursor to loading cursor while I'm processing certain information on my software then restoring the default cursor. But I'm facing an issue when my computer accessibility configuration has the size of mouse computer at maximum value, everything seems to be working while my app is running but when the program finish its execution, some how the cursor is reset to the minimal size value.

Here is a sample code that I'm trying:


#include <iostream>
#include <windows.h>
#include <WinUser.h>
#define OCR_NORMAL 32512
int main()
{
    std::cout << "Hello World!\n";
    auto default_arrow = ::CopyIcon(::LoadCursor(nullptr, IDC_ARROW));
    auto  wait_cursor = ::CopyIcon(::LoadCursor(nullptr, IDC_WAIT));
    ::SetSystemCursor(wait_cursor, OCR_NORMAL);
    std::cout << "load cursor was set\n";
    system("pause");
    // restoring system cursor
    ::SetSystemCursor(default_arrow, OCR_NORMAL);
    system("pause");
    DestroyCursor(wait_cursor);
    DestroyCursor(default_arrow);
    system("pause");
}

Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,717 questions
C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,837 questions
{count} votes

1 answer

Sort by: Most helpful
  1. RLWA32 46,581 Reputation points
    2025-01-23T22:32:01.51+00:00

    Try this -

    #include <iostream>
    #include <windows.h>
    #include <WinUser.h>
    #define OCR_NORMAL 32512
    int main()
    {
        std::cout << "Hello World!\n";
        auto  wait_cursor = ::CopyIcon(::LoadCursor(nullptr, IDC_WAIT));
        // Documentation says that the system will destroy wait_cursor
        ::SetSystemCursor(wait_cursor, OCR_NORMAL);
        std::cout << "load cursor was set\n";
        system("pause");
        ::SystemParametersInfoA(SPI_SETCURSORS, 0, NULL, SPIF_SENDCHANGE);
        std::cout << "Cursors have been reset\n";
    }
    

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.