Set system cursor size
Asked Answered
U

1

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);
}

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));

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));

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

Untrimmed answered 11/3, 2019 at 9:18 Comment(15)
Consider your tags too - this is far from a generic C++ question.Hersey
@Hersey Apologies for that, I have updated them. For some reason I forgot to add them when writing the questionUntrimmed
Ta. Have an upvote!Hersey
@Hersey Merci :)Untrimmed
Sadly though as for the actual question, I ain't the faintest idea.Hersey
I am not able to reproduce this issue myself; SetSystemCursor with an arbitrary size coordinate between 32- to 128 works for meBoarfish
@GovindParmar It's interesting that it works for you. Out of interest are you capped at a min of 32 and a max of 128?Untrimmed
@Untrimmed Nope, just all I've triedBoarfish
@Untrimmed Wait - is the actual cursor in your Cursor.cur file 32x32? If so, that may be the problem. I've been creating my cursors in Visual Studio with the desired size and then using the corresponding x and y sizes in the call to LoadImageBoarfish
@GovindParmar When I opened in Visual Studio, it gives the details, Cursor.cur - Icon [256x226, 32bit, BMP]Untrimmed
#24118264Teucer
@Downvoter why the downvote?Untrimmed
My app has cursors far larger than 32px x 32px. Are you targeting an older version of Windows in your project? (Not sure if that would limit cursor sizes when running on Windows 10/1809.)Dacha
@Dacha I assume I am not targeting an older version of Windows. The properties show I am targeting "Windows 10" using Windows SDK Version "10.0.17763.0"Untrimmed
I don't believe it to be possible to create cursors of other sizes. See learn.microsoft.com/en-us/windows/desktop/api/winuser/… - In particular the SM_CXCURSOR and SM_CYCURSOR and note that they state: 'The system cannot create cursors of other sizes.'.Ias
B
-1
#include <windows.h>
#include <stdio.h>
#pragma comment(lib, "user32.lib")

void main()
{
   int fResult;


   fResult = GetSystemMetrics(SM_CYCURSOR); 
}

Set system cursor size Ans: you can set size to anything if system supports it . Is it possible to set the system cursor size to over 32px by 32px? Ans:Test the code mentioned above If it gives 32 as output that means you cannot exceed cursor size For some Display it may give you higher number so on those screen you can have cursor size larger. So Ideal way is to check for SM_CYCURSOR SM_CXCURSOR whatever is size of cursor Load same size cursor from file

The nWidth and nHeight parameters must specify a width and height that are supported by the current display driver, because the system cannot create cursors of other sizes. To determine the width and height supported by the display driver, use the GetSystemMetrics function, specifying the SM_CXCURSOR or SM_CYCURSOR value.

Before closing, an application must call the DestroyCursor function to free any system resources associated with the cursor.

code to try .try this on different Machines with different display driver.chnage 32 to 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
Babar answered 20/3, 2019 at 19:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.