How to set a cursor of non-standard size in Windows 10?

2

I am attempting to change the cursor in Windows 10 (version 1703) to a custom made one (conditional on some event when a script activates), that is larger than the default 32 by 32 size. The MWE based on my Autohotkey script is the following:

ImagePath = %A_ScriptDir%\foo.cur
Cursor_ID := 32512   ; Standard arrow
Cursor_Size := 128

^0::
    SetSystemCursor( ImagePath, Cursor_ID, Cursor_Size, Cursor_Size )
return

SetSystemCursor( path, id, sizeX, sizeY )
{
    Cursor := DllCall( "LoadImage",
        UInt,0, Str,path, UInt,0x2, Int,sizeX, Int,sizeY, UInt,0x00000010, Ptr)
    DllCall( "SetSystemCursor", Ptr,Cursor, Int,id )
}

(My code is based off of that found at https://autohotkey.com/board/topic/32608-changing-the-system-cursor/.)

As far as I can tell from the documentation of LoadImage, the function SetSystemCursor(...) should load the image with dimensions (sizeX, sizeY) when those parameters are not 0 (since the flag LR_DEFAULTSIZE = 0x00000040 is not set), but instead I get the following behaviour: no matter what sizes I set, the image gets scaled to (sizeX, sizeY), and then down/upscaled to (32, 32). This is most obvious by setting, say Cursor_Size := 2, then I get an upscaled version of a 2 by 2 image.

After some searching around I have found both information suggesting that this should work, and also to the effect that the size of cursors is always dictated by getSystemMetrics(SM_CXCURSOR) and getSystemMetrics(SM_CYCURSOR): The biggest size of Windows Cursor (see also GetSystemMetrics).

Additional tests/ideas I've tried:

  1. I checked the dimensions of the image corresponding to the handle returned by LoadImage, and it seems to be (sizeX, sizeY), just as it should be, therefore the scaling to 32 most likely happens upon executing SetSystemCursor.

  2. I wanted to see if an application-specific cursor could bypass the apparent 32 by 32 restriction, so using Resource Hacker, I replaced one of the resources in Paint. It was scaled down to size 32 in the same way.

  3. Setting the values that are returned by getSystemMetrics(SM_CXCURSOR) and getSystemMetrics(SM_CYCURSOR) might be an option if these indeed restrict cursor sizes, but I could not find an appropriate function. I checked SystemParametersInfo, but the only remotely relevant option I found was SPI_SETCURSORS, and that just reloads the cursors from registry.

    It might be possible to change a registry value, though it would not be my preferred solution, as it would most likely require a reboot to take effect. Additionally, I haven't been able to find the relevant key.

My question would therefore be the following:

Is there a way to add an image of arbitrary size as a cursor in Windows 10, preferably without the need to reboot the computer? If so, how? Do SM_CXCURSOR and SM_CYCURSOR absolutely restrict the cursor's size? If they do, can these values be changed somehow?

EDIT:

It has been pointed out that yes, the documentation of GetSystemMetrics states "the system cannot create cursors of other sizes" than SM_CXCURSOR and SM_CYCURSOR, but at the same time at some of the other webpages I linked, people seem to claim to be able to create arbitrary sized cursors. Hence my request for confirmation/clarification of the matter.

Apart from that, the question about changing these values, or the existence of any other possible workaround would still be important to me.

windows
winapi
windows-10
autohotkey
asked on Stack Overflow Oct 4, 2017 by Taederias • edited Oct 4, 2017 by Taederias

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0