WinAPI / WPF:仅为应用程序设置系统游标 [英] WinAPI / WPF: Set system cursor only for application

查看:147
本文介绍了WinAPI / WPF:仅为应用程序设置系统游标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序的UI是自定义渲染的主题。我还想添加新的非默认游标(例如当用户打算调整窗口大小时调整大小游标)以匹配该主题。

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.

使用WinAPI函数 SetCursor 我只能改变应用程序的默认指针,但这还不够,所以我查了 SetSystemCursor 这工作很好。问题是:后一个版本彻底改变了系统范围内的游标,但是我只想为我的应用程序更改这些游标。

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.

我想过复制之前的游标我做了 SetSystemCursor 并在应用程序退出时重新设置它们,但即使我实现了一个终止处理程序,如果进程例如只是崩溃。此外,只要应用程序正在运行,光标仍将在系统范围内更改。

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.

特别是对于resize-cursors,我可以删除窗口样式,无边框窗口,并渲染/实现调整大小的手柄和逻辑自己(然后我可以只钩住鼠标事件),但这只是我最后的手段 - 我宁愿想知道是否可能实现我的目标我做这个繁琐的任务...

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...

对于任何感兴趣的人:UI是用WPF渲染的,但WPF不提供这个功能(再次,他们有它,但只是为默认指针)。如果我必须使用WinAPI或其他低级调用,我不关心我,但是在这一刻,似乎没有符合我的需要:(

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 :(

所以如果有人知道如何改变WPF或WinAPI中的其他系统游标(不是默认的指针)只是为我的应用程序,而不必实现自定义光标逻辑到我的窗口,为此,你会使我的一天。 / p>

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.

推荐答案

我不知道如何在WPF中实现这一点,但如果你想将光标设置为默认之外的其他,那么您的窗口过程应该处理WM_SETCURSOR消息。

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

这篇关于WinAPI / WPF:仅为应用程序设置系统游标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆