Capturing mouse, key events

J

Jeffrey Tan[MSFT]

Hi Schemer,

Thanks for your feedback.

I do not think this meets your need. With overriding form's WndProc, you
still only can receive messages when the mouse is over the form. If the
mouse moves out of the form, no message will be posted to the form's
WndProc. So I think hook is required for this situation.

Hope this helps.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
S

Schemer

Currently, we have our application working as desired, w/o having to use a
hook.
Here's part of our WndProc:
protected override void WndProc(ref Message m)
{
if (/* something */)
{
// Do stuff
Invalidate();
}
// If we are getting a mouse button up message, and that button is
// associated with the tool in use, then we need to check the
keepCapture
// flag to determine whether to re-capture the mouse.
if ((m.Msg == WM_LBUTTONUP && _curButtonTool == MouseButtons.Left) ||
(m.Msg == WM_MBUTTONUP && _curButtonTool == MouseButtons.Middle) ||
(m.Msg == WM_RBUTTONUP && _curButtonTool == MouseButtons.Right))
{
// Call the base implementation, which causes
// mouse capture to be lost.
base.WndProc (ref m);
// Now re-capture the mouse if requested
if (_keepCapture) {
Capture = true;
}
// No need to call base implementation again
return;
}

base.WndProc(ref m);
}

Left-click activates rubberband drawing. Even when the mouse is outside of
the MDI child window, the window receives the mouse move messages. When the
mouse leaves the main app window, the MDI window doesn't receive the
messages. (We would probably need to install a hook if we wanted to trap
the mouse, even when it was outside the main app window.)
 
J

Jeffrey Tan[MSFT]

Hi Schemer,

Yes, you are right, I am talking about the same thing as you. After setting
Capture to true, the Capture will be "application wide", that is: whenever
the mouse is over a window that is in the same application of the calling
form, the mouse message will be routed to the set capture form. However, it
is not "system wide", that is: whenever the mouse is out of the
application, the mouse message will route to other application.

In windows, if we set capture and mouse button is always down, the capture
will be "system wide".(This is what Scribble application does). So I used
the Journal hook to simulate the Scribble function with mouse button in
release mode.

Anyway, if "application wide" capture is what you want, please feel free to
go with current solution. After all, the hook solution is somewhat complex.

Hope this helps.
==================================================
Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top