How do I know the size of a HCURSOR object

前端 未结 3 540
無奈伤痛
無奈伤痛 2021-01-22 13:46

I want to get the height and width of a .cur file without look into its format.

I try to use LoadCursorFromFile() to get a HCURSOR, I suppose there is a API function to

3条回答
  •  情书的邮戳
    2021-01-22 14:27

    Universal C++ code, for any cursor:

    SIZE GetSize(HCURSOR ico)
    {
        SIZE res = {0};
        if (ico)
        {
            ICONINFO info = {0};
            if ( ::GetIconInfo(ico, &info)!=0 )
            {
                bool bBWCursor = (info.hbmColor==NULL);
                BITMAP bmpinfo = {0};
                if (::GetObject( info.hbmMask, sizeof(BITMAP), &bmpinfo)!=0)
                {
                    res.cx = bmpinfo.bmWidth;
                    res.cy = abs(bmpinfo.bmHeight) / (bBWCursor ? 2 : 1);
                }
    
                ::DeleteObject(info.hbmColor);
                ::DeleteObject(info.hbmMask);
            }
        }
        return res;
    }
    

提交回复
热议问题