Is it possible to get notifications of mouse cursor changes? I'm interested in changes caused within my process but a system wide notification would be just as good. Since I'm using third party libraries, there might be several reasons for the cursor to change.
In particular, I'd like to know when the cursor becomes IDC_HAND. Reading online, there doesn't appear to be a notification driven approach to this.
My current solution is to check if the mouse cursor is the same as LoadCursor(nullptr, IDC_HAND). However:
- Could this is causing resource leaks? The documentation for
LoadCursorindicates that if the resource already exists, then a reference to said resource is returned instead of a new resource. Therefore it seems that I should not attempt to release the handle. - Is it costly to perform this check often since
LoadCursorwould be called many times? - Should I cache the
IDC_HANDcursor? If it doesn't exist when I performLoadCursor, when the hand cursor is created, will it necessarily have the same handle? From my tests, the answers appears to be yes.
As far as I can tell, the ideal scenario is that there is a Windows message indicating a cursor change at which stage I could perform the LoadCursor handle check. Are there perhaps alternatives?
Thank you for your time and assistance.
SetCursor()function. - Remy LebeauIDC_HANDat startup, so your call will merely get a reference to the existing cursor. To be notified when the cursor changes, use accessibility. Look for changes toOBJID_CURSOR. - Raymond Chen