CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: How to get displayed size of mouse cursor on Windows 10 in program

  1. #1
    Join Date
    May 2020
    Posts
    2

    Angry How to get displayed size of mouse cursor on Windows 10 in program

    I need to know the displayed size of mouse cursor in my C++ Windows 10 program.


    On Windows 10, I make the pointer larger, say 5x than the original.
    Name:  setting.jpg
Views: 34
Size:  23.5 KB


    Then, in my C++/MFC program, I tried these:

    int nXCursor = ::GetSystemMetrics(SM_CXCURSOR);
    int nYCursor = ::GetSystemMetrics(SM_CYCURSOR);

    or
    int nXIcon = ::GetSystemMetrics(SM_CXICON);

    or

    HICON ico = (HICON)GetCursor();

    SIZE res = { 0 };
    if (ico)
    {
    ICONINFO info = { 0 };
    if (::GetIconInfo(ico, &info) != 0)
    {
    BITMAP bmpinfo = { 0 };
    if (::GetObject(info.hbmMask, sizeof(BITMAP), &bmpinfo) != 0)
    {
    res.cx = bmpinfo.bmWidth;
    res.cy = bmpinfo.bmHeight;
    }
    :eleteObject(info.hbmColor);
    :eleteObject(info.hbmMask);
    }
    }

    They all come back with 32, which is original.

    Does anybody know how to get the displayed, enlarged cursor size?

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    19,725

    Re: How to get displayed size of mouse cursor on Windows 10 in program

    I never did it myself...
    Try to use:
    1. GetCursor - to get the cursor handle.
    2. GetIconInfo - to obtain the cursor/icon info (you pass the cursor handle to this function).
    3. The HBITPMAP member(s) of the filled in ICONINFO you can now use to obtain its dimension using GetBitmapDimensionEx function.

    Again: I never used it so am not 100% sure it will work.
    Victor Nijegorodov

  3. #3
    Join Date
    May 2020
    Posts
    2

    Re: How to get displayed size of mouse cursor on Windows 10 in program

    Quote Originally Posted by VictorN View Post
    I never did it myself...
    Try to use:
    1. GetCursor - to get the cursor handle.
    2. GetIconInfo - to obtain the cursor/icon info (you pass the cursor handle to this function).
    3. The HBITPMAP member(s) of the filled in ICONINFO you can now use to obtain its dimension using GetBitmapDimensionEx function.

    Again: I never used it so am not 100% sure it will work.
    Tried with this approach too, not working. Basically from my 3rd way.

    Here it goes again:

    Simplified a bit:

    HICON ico = (HICON)GetCursor();
    SIZE res = { 0 };

    ICONINFO info = { 0 };
    if (::GetIconInfo(ico, &info) != 0)
    {
    BITMAP bmpinfo = { 0 };
    if (::GetObject(info.hbmMask, sizeof(BITMAP), &bmpinfo) != 0)
    {
    res.cx = bmpinfo.bmWidth;
    res.cy = bmpinfo.bmHeight;
    }
    }

    The problem is info.hbmMask is 32 in size, even you copy that to an HBITMAP.

  4. #4
    2kaud's Avatar
    2kaud is online now Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,118

    Re: How to get displayed size of mouse cursor on Windows 10 in program

    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++17 Compiler: Microsoft VS2019 (16.6.1)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)