从 Windows 上的另一个进程更改窗口上的鼠标光标
我有一个进程 A,它启动进程 B。我在 A 中加载鼠标光标,并且我希望 A 在鼠标位于 B 窗口上时更改鼠标光标。是否可以?
我尝试从 A 调用 SetCursor当鼠标位于 B 上时,但即使我处理 B 中的 WM_SETCURSOR 消息,光标永远不会改变。我错过了什么吗?
I have a process A, that launches a process B. I load a mouse cursor in A, and I want A to change the mouse cursor when the mouse is on the B window. Is it possible?
I tried to call SetCursor from A when the mouse is over B, but even if I handle the WM_SETCURSOR message in B, the cursor never changes. Am I missing something?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
窗口在另一个窗口上方时控制鼠标的唯一方法是捕获鼠标(请参阅 SetCapture),或者通过设置系统鼠标,但我非常怀疑你想做后者。
不幸的是,捕获鼠标意味着您将所有鼠标事件发送到您的窗口而不是他们的窗口,因此他们的 GUI 无法使用。
唯一的其他解决方案是 API 挂钩和代码注入到 B,您可以在其中管理 WM_MOUSEMOVE 等任何消息并从应用程序本身调用 SetCursor,可能使用某种进程间通信方法从应用程序 A 获取要设置的光标。
The only way a window can control the mouse when it's over another window is by capturing the mouse (see SetCapture), or by setting the system mouse, but I very much doubt you want to do the latter.
Unfortunately capturing the mouse means you get all the mouse events sent to your window rather than theirs, so their GUI is unusable.
The only other solution is API hooking and code injection into B where you manage any messages such as WM_MOUSEMOVE and call SetCursor from within the application itself, possibly using some method of interprocess communication to get what cursor to set from application A.
应用程序可以控制它们自己的光标。从 A 调用
SetCursor()
是不可能的。请注意,SetCursor()
没有参数指定要对哪个应用程序进行更改。这是因为更改是在调用应用程序中进行的。您需要将代码注入 B 中以实现所需的更改。
Applications are in control of their own cursors. Calling
SetCursor()
cannot from A cannot possibly work. Notice thatSetCursor()
has no parameters specifying which application the change is to be made to. This is because the change is made in the calling application.You will need to inject code into B to effect the desired change.
您可以使用
SetClassLong
和GCL_HCURSOR
更改子进程的默认光标。不过,这不会影响子级使用SetCursor
显式更改其自己的光标时显示的内容,只会影响在未指定任何其他内容时显示的默认值。警告:程序可能永远不会显示其默认光标,在这种情况下,这不会产生任何效果。You can change the child process' default cursor using
SetClassLong
withGCL_HCURSOR
. This won't affect what's displayed when the child usesSetCursor
to explicitly change its own cursor though, just the default that's displayed when it hasn't specified anything else. Warning: it's possible that a program may never display its default cursor at all, in which case this won't have any effect.