Set system cursor size

Dan*_*Dan 10 c++ windows winapi windows-10

Is it possible to set the system cursor size to over 32px by 32px?

Currently I am using this code to set the cursors.

#define OEMRESOURCE
#include <windows.h>
#include <chrono>
#include <thread>

int main()
{
    //Load cursor
    const HCURSOR customCursor = LoadCursorFromFile(L"Cursor.cur");

    //Replace system cursor with loaded cursor
    SetSystemCursor(customCursor, OCR_NORMAL);

    //Sleep the current thread to allow the user to play with new cursor
    std::this_thread::sleep_for(std::chrono::milliseconds(5000));

    //Restore original system cursors
    SystemParametersInfo(SPI_SETCURSORS, 0, nullptr, 0);
}
Run Code Online (Sandbox Code Playgroud)

However, even though the cursor file is bigger than 32px by 32px, it is not the cursor gets scaled down.

Another question suggested using LoadImage.

However, using the line

const HCURSOR customCursor = static_cast<HCURSOR>(LoadImage(nullptr, L"Cursor.cur", IMAGE_CURSOR, 0, 0, LR_LOADFROMFILE));
Run Code Online (Sandbox Code Playgroud)

as suggested did not seem to make a difference. Trying to manually set the size, like

const HCURSOR customCursor = static_cast<HCURSOR>(LoadImage(nullptr, L"Cursor.cur", IMAGE_CURSOR, 80, 80, LR_LOADFROMFILE));
Run Code Online (Sandbox Code Playgroud)

affected the quality of the cursor but not the size of it.

Does anyone have any suggestions?


I am currently running Windows 10 on my system

Jin*_*kur -1

#include <windows.h>
#include <stdio.h>
#pragma comment(lib, "user32.lib")

void main()
{
   int fResult;


   fResult = GetSystemMetrics(SM_CYCURSOR); 
}
Run Code Online (Sandbox Code Playgroud)

设置系统光标大小 Ans: 如果系统支持,您可以将大小设置为任何值。是否可以将系统光标大小设置为超过 32 像素 x 32 像素?Ans:测试上面提到的代码,如果它给出 32 作为输出,这意味着你不能超过光标大小对于某些显示器,它可能会给你更大的数字,所以在这些屏幕上你可以有更大的光标大小。所以理想的方法是检查 SM_CYCURSOR SM_CXCURSOR 无论光标大小如何 从文件加载相同大小的光标

nWidth 和 nHeight 参数必须指定当前显示驱动程序支持的宽度和高度,因为系统无法创建其他尺寸的光标。要确定显示驱动程序支持的宽度和高度,请使用 GetSystemMetrics 函数,并指定 SM_CXCURSOR 或 SM_CYCURSOR 值。

在关闭之前,应用程序必须调用 DestroyCursor 函数来释放与光标关联的所有系统资源。

尝试的代码。在具有不同显示驱动程序的不同机器上尝试此操作。chnage 32 到 64

HINSTANCE hinst;            // handle to current instance  
HCURSOR hCurs1, hCurs2;     // cursor handles 

HCURSOR hCurs3;             // cursor handle 

// Yin-shaped cursor AND mask 

BYTE ANDmaskCursor[] = 
{ 
    0xFF, 0xFC, 0x3F, 0xFF,   // line 1 
    0xFF, 0xC0, 0x1F, 0xFF,   // line 2 
    0xFF, 0x00, 0x3F, 0xFF,   // line 3 
    0xFE, 0x00, 0xFF, 0xFF,   // line 4 

    0xF7, 0x01, 0xFF, 0xFF,   // line 5 
    0xF0, 0x03, 0xFF, 0xFF,   // line 6 
    0xF0, 0x03, 0xFF, 0xFF,   // line 7 
    0xE0, 0x07, 0xFF, 0xFF,   // line 8 

    0xC0, 0x07, 0xFF, 0xFF,   // line 9 
    0xC0, 0x0F, 0xFF, 0xFF,   // line 10 
    0x80, 0x0F, 0xFF, 0xFF,   // line 11 
    0x80, 0x0F, 0xFF, 0xFF,   // line 12 

    0x80, 0x07, 0xFF, 0xFF,   // line 13 
    0x00, 0x07, 0xFF, 0xFF,   // line 14 
    0x00, 0x03, 0xFF, 0xFF,   // line 15 
    0x00, 0x00, 0xFF, 0xFF,   // line 16 

    0x00, 0x00, 0x7F, 0xFF,   // line 17 
    0x00, 0x00, 0x1F, 0xFF,   // line 18 
    0x00, 0x00, 0x0F, 0xFF,   // line 19 
    0x80, 0x00, 0x0F, 0xFF,   // line 20 

    0x80, 0x00, 0x07, 0xFF,   // line 21 
    0x80, 0x00, 0x07, 0xFF,   // line 22 
    0xC0, 0x00, 0x07, 0xFF,   // line 23 
    0xC0, 0x00, 0x0F, 0xFF,   // line 24 

    0xE0, 0x00, 0x0F, 0xFF,   // line 25 
    0xF0, 0x00, 0x1F, 0xFF,   // line 26 
    0xF0, 0x00, 0x1F, 0xFF,   // line 27 
    0xF8, 0x00, 0x3F, 0xFF,   // line 28 

    0xFE, 0x00, 0x7F, 0xFF,   // line 29 
    0xFF, 0x00, 0xFF, 0xFF,   // line 30 
    0xFF, 0xC3, 0xFF, 0xFF,   // line 31 
    0xFF, 0xFF, 0xFF, 0xFF    // line 32 
};

// Yin-shaped cursor XOR mask 

BYTE XORmaskCursor[] = 
{ 
    0x00, 0x00, 0x00, 0x00,   // line 1 
    0x00, 0x03, 0xC0, 0x00,   // line 2 
    0x00, 0x3F, 0x00, 0x00,   // line 3 
    0x00, 0xFE, 0x00, 0x00,   // line 4 

    0x0E, 0xFC, 0x00, 0x00,   // line 5 
    0x07, 0xF8, 0x00, 0x00,   // line 6 
    0x07, 0xF8, 0x00, 0x00,   // line 7 
    0x0F, 0xF0, 0x00, 0x00,   // line 8 

    0x1F, 0xF0, 0x00, 0x00,   // line 9 
    0x1F, 0xE0, 0x00, 0x00,   // line 10 
    0x3F, 0xE0, 0x00, 0x00,   // line 11 
    0x3F, 0xE0, 0x00, 0x00,   // line 12 

    0x3F, 0xF0, 0x00, 0x00,   // line 13 
    0x7F, 0xF0, 0x00, 0x00,   // line 14 
    0x7F, 0xF8, 0x00, 0x00,   // line 15 
    0x7F, 0xFC, 0x00, 0x00,   // line 16 

    0x7F, 0xFF, 0x00, 0x00,   // line 17 
    0x7F, 0xFF, 0x80, 0x00,   // line 18 
    0x7F, 0xFF, 0xE0, 0x00,   // line 19 
    0x3F, 0xFF, 0xE0, 0x00,   // line 20 

    0x3F, 0xC7, 0xF0, 0x00,   // line 21 
    0x3F, 0x83, 0xF0, 0x00,   // line 22 
    0x1F, 0x83, 0xF0, 0x00,   // line 23 
    0x1F, 0x83, 0xE0, 0x00,   // line 24 

    0x0F, 0xC7, 0xE0, 0x00,   // line 25 
    0x07, 0xFF, 0xC0, 0x00,   // line 26 
    0x07, 0xFF, 0xC0, 0x00,   // line 27 
    0x01, 0xFF, 0x80, 0x00,   // line 28 

    0x00, 0xFF, 0x00, 0x00,   // line 29 
    0x00, 0x3C, 0x00, 0x00,   // line 30 
    0x00, 0x00, 0x00, 0x00,   // line 31 
    0x00, 0x00, 0x00, 0x00    // line 32 
};

// Create a custom cursor at run time. 

hCurs3 = CreateCursor( hinst,   // app. instance 
             19,                // horizontal position of hot spot 
             2,                 // vertical position of hot spot 
             32,                // cursor width 
             32,                // cursor height 
             ANDmaskCursor,     // AND mask 
             XORmaskCursor );   // XOR mask
Run Code Online (Sandbox Code Playgroud)