开发者

Change the mouse cursor on a window from another process on Windows

开发者 https://www.devze.com 2023-03-18 16:32 出处:网络
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 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 neve开发者_如何学运维r changes. Am I missing something?


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.


Applications are in control of their own cursors. Calling SetCursor() cannot from A cannot possibly work. Notice that SetCursor() 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.


You can change the child process' default cursor using SetClassLong with GCL_HCURSOR. This won't affect what's displayed when the child uses SetCursor 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消