471,078 Members | 816 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,078 software developers and data experts.

Receiving mouse events (WM_MOUSEMOVE, etc) outside of form

I'm trying to implement some pretty basic behavior in c#/.net 1.1
Forms but can't seem to find all the requisite pieces. When a user
clicks on the background of the form, I want the app to start
receiving MouseMove updates -- whether the pointer is over the form or
not (this being the crucial part) -- until the next MouseDown. It's
easy to receive MouseMove events while the pointer is over the form
but not when the pointer leaves. (Forms continue to receive
out-of-window MouseMove updates if a mouse-button is held down, ie a
drag, but not when just moving around.)

So, is there some simple way to do this in .NET?

The one approach that I've encounted which seems to have promise is
using the User32 SetCapture function. I can successfully capture the
mouse, but then I'm not sure how to receive the event messages
(specifically WM_MOUSEMOVE).

Okiedokie. Any ideas?? TIA
Nov 16 '05 #1
3 13943
You can use Control.Capture property to get mouse events that happen
outside your form.

Sijin Joseph
http://www.indiangeek.net
http://weblogs.asp.net/sjoseph
Jason wrote:
I'm trying to implement some pretty basic behavior in c#/.net 1.1
Forms but can't seem to find all the requisite pieces. When a user
clicks on the background of the form, I want the app to start
receiving MouseMove updates -- whether the pointer is over the form or
not (this being the crucial part) -- until the next MouseDown. It's
easy to receive MouseMove events while the pointer is over the form
but not when the pointer leaves. (Forms continue to receive
out-of-window MouseMove updates if a mouse-button is held down, ie a
drag, but not when just moving around.)

So, is there some simple way to do this in .NET?

The one approach that I've encounted which seems to have promise is
using the User32 SetCapture function. I can successfully capture the
mouse, but then I'm not sure how to receive the event messages
(specifically WM_MOUSEMOVE).

Okiedokie. Any ideas?? TIA

Nov 16 '05 #2
Well, actually, that only works when _dragging_ outside of the Form
(or control). So, for example, if the user presses a mouse button,
then drags outside the Form/Control while still holding the button,
said Form/Control receives MouseMove updates. However, even if the
Control.Capture is set to true, it won't receive general MouseMove
updates from outside the From... any ideas about how to do this?

Thanks!
Jason

Sijin Joseph <si***************@hotmail.com> wrote in message news:<OA**************@TK2MSFTNGP09.phx.gbl>...
You can use Control.Capture property to get mouse events that happen
outside your form.

Sijin Joseph
http://www.indiangeek.net
http://weblogs.asp.net/sjoseph

Nov 16 '05 #3
Hi Jason,

Mouse capture won't help you with this. Mouse capture in windows works only
while mouse button is held down. Even windows form is designed in a way
where capture is released as soon as a mouse button is released. Otherwise
receiving mouse events from this point on is unreliable.

The only way to track the mouse if not button is pressed, IMHO, is to
install a windows hook. Fortunately WH_MOUSE_LL hooks can be programmed
with .NET.

The following is an article from MSDN Magazine obout writing windows hooks
in .NET

http://msdn.microsoft.com/msdnmag/is...0/CuttingEdge/

The autor (Dino Esposito) doesn't talk about mouse hooks but there are good
helper class for writing windows hooks.

--
HTH
Stoitcho Goutsev (100) [C# MVP]
"Jason" <ja***@mailinator.com> wrote in message
news:4a*************************@posting.google.co m...
I'm trying to implement some pretty basic behavior in c#/.net 1.1
Forms but can't seem to find all the requisite pieces. When a user
clicks on the background of the form, I want the app to start
receiving MouseMove updates -- whether the pointer is over the form or
not (this being the crucial part) -- until the next MouseDown. It's
easy to receive MouseMove events while the pointer is over the form
but not when the pointer leaves. (Forms continue to receive
out-of-window MouseMove updates if a mouse-button is held down, ie a
drag, but not when just moving around.)

So, is there some simple way to do this in .NET?

The one approach that I've encounted which seems to have promise is
using the User32 SetCapture function. I can successfully capture the
mouse, but then I'm not sure how to receive the event messages
(specifically WM_MOUSEMOVE).

Okiedokie. Any ideas?? TIA

Nov 16 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by John Champaign | last post: by
reply views Thread by Stephen Williams | last post: by
2 posts views Thread by KarenP | last post: by
5 posts views Thread by Adeel | last post: by
2 posts views Thread by ahmed.maryam | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.