We have an HwndHost UIElement in our WPF application which is used to display Direct3d graphics, and the only way I have found to set a cursor for the HwndHost UIElment is to call the Win32 API SetCursor(). All of our cursors are resources in managed assemblies, and I would prefer to not change that, but I have not been able to find a way to load one of these cursors via any Win32 APIs like LoadImage().
Does anybody know how to get a handle(hCursor) to a cursor which is a resource in a managed assembly?
Or, is there another way to set a cursor on an HwndHost displaying Direct3D graphics?
The technique I've used in this situation before is:
.cur
files are added to your project as"Embedded Resource"
Stream
to that cursor by usingGetManifestResourceStream
(e.g. use
FileStream
withFileMode.Create
and if you wantFileAttributes.Temporary
)LoadCursorFromFile
to load the data from the file and create a cursor handle which you can then use in SetCursor.http://support.microsoft.com/kb/319292