Link to home
Start Free TrialLog in
Avatar of salted
salted

asked on

Is it possible to send mousemove messages to particular window that may be hidden?

Is it possible to send mousemove and similar mouse messages directly to a specific window that I have the handle of?

I'm trying to have the window act as if the user clicked on it - even if the window is partially or completely obscured by other windows.

I'm currently using SetForegroundWindow to throw the window to the top, sending the mouse message to click, then restoring the previous foremost window - this is far from ideal though.

Avatar of AndyAinscow
AndyAinscow
Flag of Switzerland image

That should not be a problem - it will be put into the message quue of the window.

Are you experiencing a problem?
Avatar of salted
salted

ASKER

What should not be a problem? No one's offered a solution that would solve this problem.
Question Is it possible to send mousemove and similar mouse messages directly to a specific window that I have the handle of?

Answer - yes, there is no need to use SetForegroundWindow as you have been doing.


so back to my question - Does it not work for you?  If not then what error do you get.
Avatar of salted

ASKER

Andy,

I don't know how to "send mousemove and similar mouse messages directly to a specific window that I have the handle of" that's why I'm asking the question! I've been using API calls to send mouse clicks that the OS processes - of course this isn't working to a hidden window.

So is it possible to send mousemove and similar mouse messages directly to a specific window that I have the handle of? If it is - How?
Try to call SetCapture() before send mouse message.

SetCapture( hHiddenWnd );
SendMessage( hHiddenWnd, WM_MOUSEMOVE, .... );
ReleaseCapture();
Extract from question - I'm currently using SetForegroundWindow to throw the window to the top, sending the mouse message to click, then restoring the previous foremost window


Reading that I took it literally - that you already had it working and you were worried it could give problems for you to remove the SetForegroundWindow call.
Avatar of salted

ASKER

alb66 - I see, thanks :) - I've been using mouse_event to send the messages: http://msdn2.microsoft.com/en-us/library/ms646260.aspx

What exactly do I need to send in the message? Is wm_mousemove enough to move the cursor?

Andy - no problem, sorry I wasn't clear.
SendInput and the earlier functions such as mouse_event AFAIK don't take a window handle - they pass to the foreground window.
You need to try with the ::SendMessage(hWndAppToReceiveMessage, ....)

ASKER CERTIFIED SOLUTION
Avatar of alb66
alb66
Flag of Italy image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Call SetCapture() before SendMessage() as I wrote in my first comment.
If you have coded the app receiving the messages consider a change in logic.
Use RegisterWindowsMessage (hope I spelt it correctly) to send a UNIQUE message to the recipient eg.
SendMessage(hWndRecipient, MY_MESSAGE_FAKE_MOUSE_CLICK,...)
and let the recipient call the appropriate function directly
Avatar of salted

ASKER

Aha! That's perfect alb66 :-D

I hadn't thought of doing it that way, so am I right in thinking both windows will receive the notification?

I'm going to try this out now :-)
I think both windows should receive the notification.
< so am I right in thinking both windows will receive the notification? >

I don't think so.  Only one window will receive the messages.
Forced accept.

Computer101
EE Admin