Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
197 views
in Technique[技术] by (71.8m points)

c# - WinAPI / WPF: Set system cursor only for application

I have an application whose UI is custom rendered with a theme. I also want to add new non-default-cursors (like the resize cursors when the user intends to resize the window) to match that theme.

With the WinAPI function SetCursor I am only able to change the default pointer for the application, but this is not enough, so I looked up SetSystemCursor which works just fine. Problem is: The latter version changes the cursors system-wide permanently, but I only want them to be changed for my application only.

I thought about copying the previous cursors before I do the SetSystemCursor and re-set them at application exit, but even when I implement a terminate handler it may not be called if the process e.g. just crashes. Also the cursors would still be changed system-wide as long as the application is running.

Specifically for the resize-cursors, I could just drop the window style, make a borderless window, and render/implement the resizing grips and logic myself (then I could just hook the mouse-over events), but that is really just my last resort - I'd rather like to know if it is possible achieve my goal before I do this cumbersome task...

For anyone who is interested: The UI is rendered with WPF, but WPF doesn't provide this functionality either (again, they have it, but just for the default pointer). It's no concern for me to use the WinAPI or other "low-level" calls if I have to, but at the moment it seems there are none that are fitting my needs :(

So if anybody knows how to change the other system cursors (not the default pointer) in WPF or WinAPI just for my application without having to implement custom cursor-logic to my window just for that, you would make my day.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I don't know how to implement this in WPF, but if you want to set the cursor to something other than default, then your window procedure should handle the WM_SETCURSOR message.

http://msdn.microsoft.com/en-us/library/windows/desktop/ms648382(v=vs.85).aspx


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...