How to Produce MousePreview Effect (like KeyPreview)

C

Charles Law

I have asked a similar question to this before, but have not found a
satisfactory answer yet, so I thought I would ask it in another way.

KeyPreview, for a form, handily allows keys to be intercepted at form level,
and pre-processed and/or filtered. In the absence of a MousePreview setting,
is there a way to do the same thing for mouse movements and clicks?

TIA

Charles
 
G

Guest

hi Charles

can u be more clear. That is what actually is ur requirement. whether you wanted to do something on your mouse move or stuffs like that

With regards

Sadha Sivam S
 
C

Charles Law

Hi Sadha

I want to handle mouse move events and clicks in a user control, so that
they do not reach any of the controls placed on the user control. So,
suppose I have a user control with a button on it, if the user clicks where
the button is I want to be able to intercept the click and use it to draw a
selection border around the button, rather than call the button's click
event.

Charles


sadha sivam said:
hi Charles,

can u be more clear. That is what actually is ur requirement. whether you
wanted to do something on your mouse move or stuffs like that.
 
C

Charles Law

Hi Anand

Thanks for the link. It looks like it will do just what I want.

Cheers

Charles


Anand[MVP} said:
AFAIK, the only way to do a mousepreview kind of stuff is to use a System Hook.

This KB may help http://support.microsoft.com/default.aspx?scid=KB;EN-US;Q319524

Rgds,
Anand
VB.NET MVP
http://www.dotnetindia.com

Charles Law said:
I have asked a similar question to this before, but have not found a
satisfactory answer yet, so I thought I would ask it in another way.

KeyPreview, for a form, handily allows keys to be intercepted at form level,
and pre-processed and/or filtered. In the absence of a MousePreview setting,
is there a way to do the same thing for mouse movements and clicks?

TIA

Charles
 
C

Charles Law

Hi Anand

I've now had chance to try using a system hook, as described in the article,
but there is a problem. When I insert a hook for an MDI child form, the hook
applies for the entire application, and not just for the child form. I am
effectively getting a preview of mouse events for all forms, and not just
the current form. In this way the effect is different from KeyPreview, which
operates at form level.

Any thoughts?

Charles


Anand[MVP} said:
AFAIK, the only way to do a mousepreview kind of stuff is to use a System Hook.

This KB may help http://support.microsoft.com/default.aspx?scid=KB;EN-US;Q319524

Rgds,
Anand
VB.NET MVP
http://www.dotnetindia.com

Charles Law said:
I have asked a similar question to this before, but have not found a
satisfactory answer yet, so I thought I would ask it in another way.

KeyPreview, for a form, handily allows keys to be intercepted at form level,
and pre-processed and/or filtered. In the absence of a MousePreview setting,
is there a way to do the same thing for mouse movements and clicks?

TIA

Charles
 
G

Guest

AFAIK a hook is specific to a single thread not a window. One thing you can see if look at the hwnd you recieve and handle events that are specific to your window only. Or if each windows is in a seperate thread, then you can hook into events of that thread alone.

Rgds,
Anand
VB.NET MVP
http://www.dotnetindia.com

Charles Law said:
Hi Anand

I've now had chance to try using a system hook, as described in the article,
but there is a problem. When I insert a hook for an MDI child form, the hook
applies for the entire application, and not just for the child form. I am
effectively getting a preview of mouse events for all forms, and not just
the current form. In this way the effect is different from KeyPreview, which
operates at form level.

Any thoughts?

Charles


Anand[MVP} said:
AFAIK, the only way to do a mousepreview kind of stuff is to use a System Hook.

This KB may help http://support.microsoft.com/default.aspx?scid=KB;EN-US;Q319524

Rgds,
Anand
VB.NET MVP
http://www.dotnetindia.com

Charles Law said:
I have asked a similar question to this before, but have not found a
satisfactory answer yet, so I thought I would ask it in another way.

KeyPreview, for a form, handily allows keys to be intercepted at form level,
and pre-processed and/or filtered. In the absence of a MousePreview setting,
is there a way to do the same thing for mouse movements and clicks?

TIA

Charles
 
C

Charles Law

Thanks for the ideas Anand.

Do you know if, having hooked the mouse messages, I can change the message
or redirect it to another window? I can't see anywhere where it says whether
I can modify the MOUSEHOOKSTRUCT structure.

Charles


Anand[MVP} said:
AFAIK a hook is specific to a single thread not a window. One thing you
can see if look at the hwnd you recieve and handle events that are specific
to your window only. Or if each windows is in a seperate thread, then you
can hook into events of that thread alone.
Rgds,
Anand
VB.NET MVP
http://www.dotnetindia.com

Charles Law said:
Hi Anand

I've now had chance to try using a system hook, as described in the article,
but there is a problem. When I insert a hook for an MDI child form, the hook
applies for the entire application, and not just for the child form. I am
effectively getting a preview of mouse events for all forms, and not just
the current form. In this way the effect is different from KeyPreview, which
operates at form level.

Any thoughts?

Charles


Anand[MVP} said:
AFAIK, the only way to do a mousepreview kind of stuff is to use a
System
Hook.
This KB may help http://support.microsoft.com/default.aspx?scid=KB;EN-US;Q319524

Rgds,
Anand
VB.NET MVP
http://www.dotnetindia.com

:

I have asked a similar question to this before, but have not found a
satisfactory answer yet, so I thought I would ask it in another way.

KeyPreview, for a form, handily allows keys to be intercepted at
form
level,
and pre-processed and/or filtered. In the absence of a MousePreview setting,
is there a way to do the same thing for mouse movements and clicks?

TIA

Charles
 
G

Guest

I am not sure if you can do that.. You can supress calling the next in chain, due to which that message can be supressed. But I am not sure if you can chage the data, but you can always try..

Rgds,
Anand
VB.NET MVP
http://www.dotnetindia.com

Charles Law said:
Thanks for the ideas Anand.

Do you know if, having hooked the mouse messages, I can change the message
or redirect it to another window? I can't see anywhere where it says whether
I can modify the MOUSEHOOKSTRUCT structure.

Charles


Anand[MVP} said:
AFAIK a hook is specific to a single thread not a window. One thing you
can see if look at the hwnd you recieve and handle events that are specific
to your window only. Or if each windows is in a seperate thread, then you
can hook into events of that thread alone.
 
C

Charles Law

Good thinking. I had concluded that I could not change the window handle as
initial attempts proved fruitless.

Thanks.

Charles


Whatshisname said:
Charles, you can redirect a message to another window and change it if you
like. Use the API's SendMessage or PostMessage. You can just ignore the
caught message and then create your own message and send it to the window of
your choice.
----- Charles Law wrote: -----

Thanks for the ideas Anand.

Do you know if, having hooked the mouse messages, I can change the message
or redirect it to another window? I can't see anywhere where it says whether
I can modify the MOUSEHOOKSTRUCT structure.

Charles


Anand[MVP} said:
AFAIK a hook is specific to a single thread not a window. One thing
you
can see if look at the hwnd you recieve and handle events that are specific
to your window only. Or if each windows is in a seperate thread, then you
can hook into events of that thread alone.
the
form, the
hook form. I
am not
KeyPreview,
a
intercepted at
form
 

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