When the LoadCursor function is used to load a cursor from a resource, the resulting HCURSOR can be used across different monitors and always appears at the correct size.
ie: typically:
However, when a cursor is programmatically created from memory (say using LookupIconIdFromDirectoryEx and CreateIconFromResourceEx) the resulting cursor has a fixed resolution. This means it appears at the wrong size on at least one monitor in a mixed DPI multi-monitor setup.
I also checked out the LoadCursorFromFile and it too provides this dynamic resolution behaviour like LoadCursor.
Is there a way to programmatically create a cursor that dynamically switches depending which monitor it's shown on? What magic is going on behind the scenes for cursors loaded with LoadCursor to work differently?
After much experimentation I finally discovered that WPF can load cursors from resource and memory streams and get the correct DPI behaviour if the scaleWithDpi option is used:
public Cursor(Stream cursorStream, bool scaleWithDpi)
Looking at the reference source it ends up in the function LoadFromStream which loads the stream by writing it to a temporary file and the loading from the file. See source
To sum up:
LR_DEFAULTSIZE flag passed to the LoadImage function.There's a new API as of Windows 10 1607 that might help: SetThreadCursorCreationScaling
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With