[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 589
  • Last Modified:

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.

0
salted
Asked:
salted
  • 6
  • 4
  • 4
  • +1
1 Solution
 
AndyAinscowCommented:
That should not be a problem - it will be put into the message quue of the window.

Are you experiencing a problem?
0
 
saltedAuthor Commented:
What should not be a problem? No one's offered a solution that would solve this problem.
0
 
AndyAinscowCommented:
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.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
saltedAuthor Commented:
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?
0
 
alb66Commented:
Try to call SetCapture() before send mouse message.

SetCapture( hHiddenWnd );
SendMessage( hHiddenWnd, WM_MOUSEMOVE, .... );
ReleaseCapture();
0
 
AndyAinscowCommented:
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.
0
 
saltedAuthor Commented:
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.
0
 
AndyAinscowCommented:
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, ....)

0
 
alb66Commented:
It should be the following:

void CWndThatHidesYourWnd::OnMouseMove(UINT nFlags, CPoint point)
{
        // convert the coordinate for the destination client area
      ClientToScreen( &point );
      ScreenToClient( hHiddenWnd, &point );

        // send the message
      SendMessage( hHiddenWnd, WM_MOUSEMOVE, nFlags, MAKELPARAM( lpPoint.x, lpPoint.y )
}

Anyway, WM_MOUSMOVE doesn't move the cursor; it notify the window that cursor was moved.


0
 
alb66Commented:
Call SetCapture() before SendMessage() as I wrote in my first comment.
0
 
AndyAinscowCommented:
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
0
 
saltedAuthor Commented:
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 :-)
0
 
alb66Commented:
I think both windows should receive the notification.
0
 
AndyAinscowCommented:
< so am I right in thinking both windows will receive the notification? >

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

Computer101
EE Admin
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 6
  • 4
  • 4
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now