79706139

Date: 2025-07-18 12:05:27
Score: 2
Natty:
Report link

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:

Reasons:
  • Probably link only (1):
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Ends in question mark (2):
Posted by: DJm00n