Reputation: 193
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?
Upvotes: 0
Views: 615
Reputation: 12540
The technique I've used in this situation before is:
DllImport("user32.dll", EntryPoint = "LoadCursorFromFileW", CharSet = CharSet.Unicode)
public static extern IntPtr LoadCursorFromFile(String str);
...save your cursor into a temporary file...
IntPtr hCursor = DllImport.LoadCursorFromFile(sFilename);
...use hCursor in the SetCursor...
.cur
files are added to your project as "Embedded Resource"
Stream
to that cursor by using GetManifestResourceStream
FileStream
with FileMode.Create
and if you want FileAttributes.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
Upvotes: 1