If cursor was created via CreateCursor
/CreateIconIndirect
/CreateIconFromResource
/CreateIconFromResourceEx
call then there is only one instance of HICON
and you can get bitmap from it with GetIconInfoEx
/GetIconInfoEx
call (as you already doing).
But if cursor was loaded from file or resource via for LoadCursor
/LoadImage
then you can try to get ICONINFOEX
structure with GetIconInfoEx
and then use wResID
/szModName
/szResName
in LoadImage
call with desired size (DPI-aware).
Something like:
UINT dpi = GetDpiForWindow(hWnd);
INT x = GetSystemMetricsForDpi(SM_CXICON, dpi);
INT y = GetSystemMetricsForDpi(SM_CYICON, dpi);
ICONINFOEX iconInfoEx = {0};
GetIconInfoEx(hIcon, &iconInfoEx);
HMODULE hModule = GetModuleHandle(iconInfoEx.szModName);
HCURSOR hCursor = LoadImage(hModule, iconInfoEx.szResName != NULL ? iconInfoEx.szResName : MAKEINTRESOURCE(iconInfoEx.wResID), x, y, LR_DEFAULTSIZE);
Some info on this topic in Raymond Chen blog: