Windows cursor size

Tuukka Lehtinen 21 Reputation points
2022-04-17T15:18:02.253+00:00

How do i get correct size value of mouse pointer?
I have try: SystemParametersInfo() and cursor bitmap size info. They both return default values. Starting from win3.x
Now the Win10 has this change mouse cursor size feature. That make life more easy. But i din't find eny information
how to get correct size of mouse cursor if you are using large cursor.

The idea is scale to mouse cursor bitmap to correct size. Now this code is working but it use default 32x32 size.

    static Bitmap? CaptureCursor(ref int x, ref int y)
        {
            Bitmap bmp;
            IntPtr hicon;

            CURSORINFO ci = new CURSORINFO();
            ICONINFO icInfo;
            ci.cbSize = Marshal.SizeOf(ci);
            if (GetCursorInfo(ref ci))
            {
                if (ci.flags == CURSOR_SHOWING)
                {
                    hicon = CopyIcon(ci.hCursor);
                    if (GetIconInfo(hicon, out icInfo))
                    {
                        x = ci.ptScreenPos.X - ((int)icInfo.xHotspot);
                        y = ci.ptScreenPos.Y - ((int)icInfo.yHotspot);
                        Icon ic = Icon.FromHandle(hicon);
                        bmp = ic.ToBitmap();

                        return bmp;
                    }
                }
            }
            return null;
        }

https://www.howtogeek.com/427263/how-to-change-the-mouse-pointer-color-and-size-on-windows-10/

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,483 questions
0 comments No comments
{count} votes

Accepted answer
  1. Castorix31 82,501 Reputation points
    2022-04-17T15:42:42.12+00:00

    It is stored in registry :

    HKEY_CURRENT_USER\SOFTWARE\Microsoft\Accessibility
    CursorSize
    or
    HKEY_CURRENT_USER\Control Panel\Cursors
    CursorBaseSize


1 additional answer

Sort by: Most helpful
  1. Dimitriy Ryazantcev 26 Reputation points
    2022-10-30T22:30:34.917+00:00
    /*  
        The standard size is 32x32, even though the cursor is actually just  
        16 pixels large. If a large cursor is set in the accessibility settings,  
        then the cursor increases with 8 pixels for each step.  
    */  
    QSize QWindowsCursor::size() const  
    {  
        const QPair<DWORD,bool> cursorSizeSetting =  
            QWinRegistryKey(HKEY_CURRENT_USER, LR"(Control Panel\Cursors)")  
                           .dwordValue(L"CursorBaseSize");  
        const int baseSize = screenCursorSize(m_screen).width() / 2;  
        if (!cursorSizeSetting.second)  
            return QSize(baseSize / 2, baseSize / 2);  
      
        // The registry values are dpi-independent, so we need to scale the result.  
        int cursorSizeValue = cursorSizeSetting.first * m_screen->logicalDpi().first  
                                                      / m_screen->logicalBaseDpi().first;  
      
        // map from registry value 32-256 to 0-14, and from there to pixels  
        cursorSizeValue = (cursorSizeValue - 2 * baseSize) / baseSize;  
        const int cursorSize = baseSize + cursorSizeValue * (baseSize / 2);  
        return QSize(cursorSize, cursorSize);  
    }  
    

    https://github.com/qt/qtbase/blob/4b9c738185c771127eb8e7c73868f60bd31f7fce/src/plugins/platforms/windows/qwindowscursor.cpp#L657-L679

    In order to answer the question “What is the size of the mouse cursor?” you first have to specify which mouse cursor you are interested in, in the form of an HCURSOR. For example, if you are interested in the size of the arrow cursor, you can call LoadCursor(nullptr, IDC_ARROW).¹

    Once you have your HCURSOR, you can call Get­Icon­Info² to obtain information about it. The bitmaps that are used to draw the cursor are available as the hbmMask and hbmCursor. Interpreting these bitmaps is a bit tricky.

    For color cursors, the hbmMask and hbmColor bitmaps are the same size, each of which is the size of the cursor.

    https://devblogs.microsoft.com/oldnewthing/20210820-00/?p=105593

    0 comments No comments