473,395 Members | 1,516 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Hover effects, IMessageFilter not working as expected

Hi,
I'm developping a form that renders differently when hovered and trigger
some processing when not hovered (leaved). The thing is, when I leave my
form and another form from my application is underneath, it works fine, but
if I leave my form and anything that is not from my application is
underneath, the Leave event does not fire until I hover something from my
application.

Here's my filtered code for the IMessageFilter (I did not pasted the
declarations, I just pasted my message proc) (at the end of the post)

Can someone tell me what's wrong with this code?

thanks

ThunderMusic

Expand|Select|Wrap|Line Numbers
  1. public bool PreFilterMessage(ref Message m)
  2. {
  3. // Everything is done with WM_MOUSEMOVE
  4. if (m.Msg == WM_MOUSEMOVE)
  5. {
  6. // look if the target is our control or contained by our control
  7. Control ctrl = Control.FromHandle(m.HWnd);
  8. if (ctrl != null && (ctrl == this._container ||
  9. this._container.Contains(ctrl)))
  10. {
  11. // if this message WM_MOUSEMOVE is the first we get,
  12. // we must trigger the MouseEnter event
  13. if (!this._isEntered)
  14. {
  15. // trigger MouseEnter
  16. this.OnMouseEnter();
  17. this._isEntered = true;
  18. }
  19. // Get point (using target control coordinates)
  20. Point pt = new Point(m.LParam.ToInt32());
  21. // convert to controls coordinates if necessary
  22. Point containerPoint;
  23. if (ctrl != this._container)
  24. containerPoint =
  25. this._container.PointToClient(ctrl.PointToScreen(pt));
  26. else
  27. containerPoint = pt;
  28. // Trigger MouseMove
  29. this.OnMouseMove(new MouseEventArgs(MouseButtons.None, 0,
  30. containerPoint.X, containerPoint.Y, 0));
  31. }
  32. else
  33. {
  34. // If the target is not a child and MouseLeaves has not been
  35. triggered
  36. // we must trigger MouseLeave
  37. if (this._isEntered)
  38. {
  39. // Trigger MouseLeave
  40. this.OnMouseLeave();
  41. this._isEntered = false;
  42. }
  43. }
  44. }
  45. return false;
  46. }
  47.  

Oct 26 '06 #1
4 2538
Have you tried using the Activated and Deactivated events instead? See
this from MSDN help:

The Enter and Leave events are suppressed by the Form class. The
equivalent events in the Form class are the Activated and Deactivate
events. The Enter and Leave events are hierarchical and will cascade up
and down the parent chain until the appropriate control is reached. For
example, assume you have a Form with two GroupBox controls, and each
GroupBox control has one TextBox control. When the caret is moved from
one TextBox to the other, the Leave event is raised for the TextBox and
GroupBox, and the Enter event is raised for the other GroupBox and
TextBox.

Bryan Phillips
MCSD, MCDBA, MCSE
Blog: http://bphillips76.spaces.live.com


"ThunderMusic" <No*************************@NoSpAm.comwrote in message
news:eh**************@TK2MSFTNGP02.phx.gbl:
Hi,
I'm developping a form that renders differently when hovered and trigger
some processing when not hovered (leaved). The thing is, when I leave my
form and another form from my application is underneath, it works fine, but
if I leave my form and anything that is not from my application is
underneath, the Leave event does not fire until I hover something from my
application.

Here's my filtered code for the IMessageFilter (I did not pasted the
declarations, I just pasted my message proc) (at the end of the post)

Can someone tell me what's wrong with this code?

thanks

ThunderMusic

Expand|Select|Wrap|Line Numbers
  1. public bool PreFilterMessage(ref Message m)
  2. {
  3.     // Everything is done with WM_MOUSEMOVE
  4.     if (m.Msg == WM_MOUSEMOVE)
  5.     {
  6.         // look if the target is our control or contained by our control
  7.         Control ctrl = Control.FromHandle(m.HWnd);
  8.         if (ctrl != null && (ctrl == this._container ||
  9. this._container.Contains(ctrl)))
  10.         {
  11.             // if this message WM_MOUSEMOVE is the first we get,
  12.             // we must trigger the MouseEnter event
  13.             if (!this._isEntered)
  14.             {
  15.                 // trigger MouseEnter
  16.                 this.OnMouseEnter();
  17.                 this._isEntered = true;
  18.             }
  19.             // Get point (using target control coordinates)
  20.             Point pt = new Point(m.LParam.ToInt32());
  21.             // convert to controls coordinates if necessary
  22.             Point containerPoint;
  23.             if (ctrl != this._container)
  24.                 containerPoint =
  25. this._container.PointToClient(ctrl.PointToScreen(pt));
  26.             else
  27.                 containerPoint = pt;
  28.             // Trigger MouseMove
  29.             this.OnMouseMove(new MouseEventArgs(MouseButtons.None, 0,
  30. containerPoint.X, containerPoint.Y, 0));
  31.         }
  32.         else
  33.         {
  34.             // If the target is not a child and MouseLeaves has not been
  35. triggered
  36.             // we must trigger MouseLeave
  37.             if (this._isEntered)
  38.             {
  39.                 // Trigger MouseLeave
  40.                 this.OnMouseLeave();
  41.                 this._isEntered = false;
  42.             }
  43.         }
  44.     }
  45.     return false;
  46. }
  47.  
Oct 27 '06 #2
hi, thanks for your answer... unfortunately, it's not exactly what I
need... Activate and Deactivate are triggered when a user clicks on a form
(activated) or click on another form or minimize (Deactivate)... The
behavior I need is when the user move his mouse over the form or out of the
form...

I agree that the MouseEnter and MouseLeave of the form are hierarchical,
that's why I did implement IMessageFilter.... Now the thing is, I must
discover how to receive the message (or event) so the program can tell when
the mouse cursor went out of the form's boundaries.

Thanks

ThunderMusic

"Bryan Phillips" <bp*******@nospam.crowechizek.com.spammenotwrote in
message news:O7****************@TK2MSFTNGP05.phx.gbl...
Have you tried using the Activated and Deactivated events instead? See
this from MSDN help:

The Enter and Leave events are suppressed by the Form class. The
equivalent events in the Form class are the Activated and Deactivate
events. The Enter and Leave events are hierarchical and will cascade up
and down the parent chain until the appropriate control is reached. For
example, assume you have a Form with two GroupBox controls, and each
GroupBox control has one TextBox control. When the caret is moved from one
TextBox to the other, the Leave event is raised for the TextBox and
GroupBox, and the Enter event is raised for the other GroupBox and
TextBox.

Bryan Phillips
MCSD, MCDBA, MCSE
Blog: http://bphillips76.spaces.live.com


"ThunderMusic" <No*************************@NoSpAm.comwrote in message
news:eh**************@TK2MSFTNGP02.phx.gbl:
>Hi,
I'm developping a form that renders differently when hovered and trigger
some processing when not hovered (leaved). The thing is, when I leave my
form and another form from my application is underneath, it works fine,
but
if I leave my form and anything that is not from my application is
underneath, the Leave event does not fire until I hover something from my
application.

Here's my filtered code for the IMessageFilter (I did not pasted the
declarations, I just pasted my message proc) (at the end of the post)

Can someone tell me what's wrong with this code?

thanks

ThunderMusic

Expand|Select|Wrap|Line Numbers
  1. public bool PreFilterMessage(ref Message m)
  2. {
  3.     // Everything is done with WM_MOUSEMOVE
  4.     if (m.Msg == WM_MOUSEMOVE)
  5.     {
  6.         // look if the target is our control or contained by our control
  7.         Control ctrl = Control.FromHandle(m.HWnd);
  8.         if (ctrl != null && (ctrl == this._container ||
  9. this._container.Contains(ctrl)))
  10.         {
  11.             // if this message WM_MOUSEMOVE is the first we get,
  12.             // we must trigger the MouseEnter event
  13.             if (!this._isEntered)
  14.             {
  15.                 // trigger MouseEnter
  16.                 this.OnMouseEnter();
  17.                 this._isEntered = true;
  18.             }
  19.             // Get point (using target control coordinates)
  20.             Point pt = new Point(m.LParam.ToInt32());
  21.             // convert to controls coordinates if necessary
  22.             Point containerPoint;
  23.             if (ctrl != this._container)
  24.                 containerPoint =
  25. this._container.PointToClient(ctrl.PointToScreen(pt));
  26.             else
  27.                 containerPoint = pt;
  28.             // Trigger MouseMove
  29.             this.OnMouseMove(new MouseEventArgs(MouseButtons.None, 0,
  30. containerPoint.X, containerPoint.Y, 0));
  31.         }
  32.         else
  33.         {
  34.             // If the target is not a child and MouseLeaves has not been
  35. triggered
  36.             // we must trigger MouseLeave
  37.             if (this._isEntered)
  38.             {
  39.                 // Trigger MouseLeave
  40.                 this.OnMouseLeave();
  41.                 this._isEntered = false;
  42.             }
  43.         }
  44.     }
  45.     return false;
  46. }

Oct 27 '06 #3
Hi,

Here is your problem. You are using MouseMove event which is based on
WM_MOUSEMOVE. This message as any other mouse messages are posted to the
window under the mouse cursor. Because you use message filter you receive
this message if the mouse is over any form (control) that belongs to your
application. However when the mouse moves over window that is not part of
your application we just stop receiving mouse messages and there is no
notification when this happens they just stop. Windows have three solutions
to the problem (at least these are the ones that I can come up with at the
moment): installing window hook WH_MOUSE_LL, using TrackMouseEvent API and
setting mouse capture.

- WH_MOUSE_LL are possible to be implemented in .NET, but it requires using
PInvoke and I think it is the hardest one to implement
- Setint the mouse capture means that the mouse message will be dispatched
to your window even when the mouse cursor is outside of the window. The
problem is that it works only if mouse button has been pressed when the
mouse is inside the window is held down while moving the mouse. WindowsForms
sets the mouse capture when the mouse button is pressed, so it should work
by itself, but if it doesn't work for you that means you want to register
mouse leave not only when the mouse button is down.
- TrackMouseEvent is used internaly by Windows forms and the functionality
is exposed as MouseLeave and MouseHover events. Why don't use these events
instead of implementing your own solution?
The only problem that I see is that you are going to receive mouse leave
even if the mouse is inside the form, but enters some form's child control.
This cases can be filtered our by checking the form hosting tghe control.
The WM_MOUSELEAVE used internally is posted to the message queue, thus can
be handeled with message filter
--
HTH
Stoitcho Goutsev (100)

"ThunderMusic" <No*************************@NoSpAm.comwrote in message
news:Ot****************@TK2MSFTNGP02.phx.gbl...
hi, thanks for your answer... unfortunately, it's not exactly what I
need... Activate and Deactivate are triggered when a user clicks on a
form (activated) or click on another form or minimize (Deactivate)... The
behavior I need is when the user move his mouse over the form or out of
the form...

I agree that the MouseEnter and MouseLeave of the form are hierarchical,
that's why I did implement IMessageFilter.... Now the thing is, I must
discover how to receive the message (or event) so the program can tell
when the mouse cursor went out of the form's boundaries.

Thanks

ThunderMusic

"Bryan Phillips" <bp*******@nospam.crowechizek.com.spammenotwrote in
message news:O7****************@TK2MSFTNGP05.phx.gbl...
>Have you tried using the Activated and Deactivated events instead? See
this from MSDN help:

The Enter and Leave events are suppressed by the Form class. The
equivalent events in the Form class are the Activated and Deactivate
events. The Enter and Leave events are hierarchical and will cascade up
and down the parent chain until the appropriate control is reached. For
example, assume you have a Form with two GroupBox controls, and each
GroupBox control has one TextBox control. When the caret is moved from
one TextBox to the other, the Leave event is raised for the TextBox and
GroupBox, and the Enter event is raised for the other GroupBox and
TextBox.

Bryan Phillips
MCSD, MCDBA, MCSE
Blog: http://bphillips76.spaces.live.com


"ThunderMusic" <No*************************@NoSpAm.comwrote in message
news:eh**************@TK2MSFTNGP02.phx.gbl:
>>Hi,
I'm developping a form that renders differently when hovered and trigger
some processing when not hovered (leaved). The thing is, when I leave my
form and another form from my application is underneath, it works fine,
but
if I leave my form and anything that is not from my application is
underneath, the Leave event does not fire until I hover something from
my
application.

Here's my filtered code for the IMessageFilter (I did not pasted the
declarations, I just pasted my message proc) (at the end of the post)

Can someone tell me what's wrong with this code?

thanks

ThunderMusic

Expand|Select|Wrap|Line Numbers
  1. public bool PreFilterMessage(ref Message m)
  2. {
  3.     // Everything is done with WM_MOUSEMOVE
  4.     if (m.Msg == WM_MOUSEMOVE)
  5.     {
  6.         // look if the target is our control or contained by our control
  7.         Control ctrl = Control.FromHandle(m.HWnd);
  8.         if (ctrl != null && (ctrl == this._container ||
  9. this._container.Contains(ctrl)))
  10.         {
  11.             // if this message WM_MOUSEMOVE is the first we get,
  12.             // we must trigger the MouseEnter event
  13.             if (!this._isEntered)
  14.             {
  15.                 // trigger MouseEnter
  16.                 this.OnMouseEnter();
  17.                 this._isEntered = true;
  18.             }
  19.             // Get point (using target control coordinates)
  20.             Point pt = new Point(m.LParam.ToInt32());
  21.             // convert to controls coordinates if necessary
  22.             Point containerPoint;
  23.             if (ctrl != this._container)
  24.                 containerPoint =
  25. this._container.PointToClient(ctrl.PointToScreen(pt));
  26.             else
  27.                 containerPoint = pt;
  28.             // Trigger MouseMove
  29.             this.OnMouseMove(new MouseEventArgs(MouseButtons.None, 0,
  30. containerPoint.X, containerPoint.Y, 0));
  31.         }
  32.         else
  33.         {
  34.             // If the target is not a child and MouseLeaves has not been
  35. triggered
  36.             // we must trigger MouseLeave
  37.             if (this._isEntered)
  38.             {
  39.                 // Trigger MouseLeave
  40.                 this.OnMouseLeave();
  41.                 this._isEntered = false;
  42.             }
  43.         }
  44.     }
  45.     return false;
  46. }


Oct 27 '06 #4
Great, it seems to work fine now by filtering on the WM_MOUSELEAVE message
in my MessageFilter.

Thanks a lot

ThunderMusic

"Stoitcho Goutsev (100)" <10*@100.coma écrit dans le message de news:
%2******************@TK2MSFTNGP02.phx.gbl...
Hi,

Here is your problem. You are using MouseMove event which is based on
WM_MOUSEMOVE. This message as any other mouse messages are posted to the
window under the mouse cursor. Because you use message filter you receive
this message if the mouse is over any form (control) that belongs to your
application. However when the mouse moves over window that is not part of
your application we just stop receiving mouse messages and there is no
notification when this happens they just stop. Windows have three
solutions to the problem (at least these are the ones that I can come up
with at the moment): installing window hook WH_MOUSE_LL, using
TrackMouseEvent API and setting mouse capture.

- WH_MOUSE_LL are possible to be implemented in .NET, but it requires
using PInvoke and I think it is the hardest one to implement
- Setint the mouse capture means that the mouse message will be dispatched
to your window even when the mouse cursor is outside of the window. The
problem is that it works only if mouse button has been pressed when the
mouse is inside the window is held down while moving the mouse.
WindowsForms sets the mouse capture when the mouse button is pressed, so
it should work by itself, but if it doesn't work for you that means you
want to register mouse leave not only when the mouse button is down.
- TrackMouseEvent is used internaly by Windows forms and the
functionality is exposed as MouseLeave and MouseHover events. Why don't
use these events instead of implementing your own solution?
The only problem that I see is that you are going to receive mouse leave
even if the mouse is inside the form, but enters some form's child
control. This cases can be filtered our by checking the form hosting tghe
control. The WM_MOUSELEAVE used internally is posted to the message queue,
thus can be handeled with message filter
--
HTH
Stoitcho Goutsev (100)

"ThunderMusic" <No*************************@NoSpAm.comwrote in message
news:Ot****************@TK2MSFTNGP02.phx.gbl...
>hi, thanks for your answer... unfortunately, it's not exactly what I
need... Activate and Deactivate are triggered when a user clicks on a
form (activated) or click on another form or minimize (Deactivate)...
The behavior I need is when the user move his mouse over the form or out
of the form...

I agree that the MouseEnter and MouseLeave of the form are hierarchical,
that's why I did implement IMessageFilter.... Now the thing is, I must
discover how to receive the message (or event) so the program can tell
when the mouse cursor went out of the form's boundaries.

Thanks

ThunderMusic

"Bryan Phillips" <bp*******@nospam.crowechizek.com.spammenotwrote in
message news:O7****************@TK2MSFTNGP05.phx.gbl...
>>Have you tried using the Activated and Deactivated events instead? See
this from MSDN help:

The Enter and Leave events are suppressed by the Form class. The
equivalent events in the Form class are the Activated and Deactivate
events. The Enter and Leave events are hierarchical and will cascade up
and down the parent chain until the appropriate control is reached. For
example, assume you have a Form with two GroupBox controls, and each
GroupBox control has one TextBox control. When the caret is moved from
one TextBox to the other, the Leave event is raised for the TextBox and
GroupBox, and the Enter event is raised for the other GroupBox and
TextBox.

Bryan Phillips
MCSD, MCDBA, MCSE
Blog: http://bphillips76.spaces.live.com


"ThunderMusic" <No*************************@NoSpAm.comwrote in message
news:eh**************@TK2MSFTNGP02.phx.gbl:

Hi,
I'm developping a form that renders differently when hovered and
trigger
some processing when not hovered (leaved). The thing is, when I leave
my
form and another form from my application is underneath, it works fine,
but
if I leave my form and anything that is not from my application is
underneath, the Leave event does not fire until I hover something from
my
application.

Here's my filtered code for the IMessageFilter (I did not pasted the
declarations, I just pasted my message proc) (at the end of the post)

Can someone tell me what's wrong with this code?

thanks

ThunderMusic

Expand|Select|Wrap|Line Numbers
  1. public bool PreFilterMessage(ref Message m)
  2. {
  3.     // Everything is done with WM_MOUSEMOVE
  4.     if (m.Msg == WM_MOUSEMOVE)
  5.     {
  6.         // look if the target is our control or contained by our
  7. control
  8.         Control ctrl = Control.FromHandle(m.HWnd);
  9.         if (ctrl != null && (ctrl == this._container ||
  10. this._container.Contains(ctrl)))
  11.         {
  12.             // if this message WM_MOUSEMOVE is the first we get,
  13.             // we must trigger the MouseEnter event
  14.             if (!this._isEntered)
  15.             {
  16.                 // trigger MouseEnter
  17.                 this.OnMouseEnter();
  18.                 this._isEntered = true;
  19.             }
  20.             // Get point (using target control coordinates)
  21.             Point pt = new Point(m.LParam.ToInt32());
  22.             // convert to controls coordinates if necessary
  23.             Point containerPoint;
  24.             if (ctrl != this._container)
  25.                 containerPoint =
  26. this._container.PointToClient(ctrl.PointToScreen(pt));
  27.             else
  28.                 containerPoint = pt;
  29.             // Trigger MouseMove
  30.             this.OnMouseMove(new MouseEventArgs(MouseButtons.None, 0,
  31. containerPoint.X, containerPoint.Y, 0));
  32.         }
  33.         else
  34.         {
  35.             // If the target is not a child and MouseLeaves has not
  36. been
  37. triggered
  38.             // we must trigger MouseLeave
  39.             if (this._isEntered)
  40.             {
  41.                 // Trigger MouseLeave
  42.                 this.OnMouseLeave();
  43.                 this._isEntered = false;
  44.             }
  45.         }
  46.     }
  47.     return false;
  48. }



Oct 28 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Cezar | last post by:
Hello. How can simple emulating in IE this class ? ..example:hover{ border: 1px solid #696969; } Greets, Cezar.
12
by: Sander Tekelenburg | last post by:
Trying to make some images disappear on hover (works), and others appear on hover (works not). In tested browsers, this gives the expected result: IMG.disappear {visibility: visible}...
6
by: Michael Rozdoba | last post by:
I've had some trouble getting IE to behave in respect of applying absolute positioning to a span on an a:hover. I can get it to work, but I don't understand why certain code causes it to fail to...
1
by: See Sharp | last post by:
Hello all, I have a form class that implements the imessagefilter interface public class frmMain : System.Windows.Forms.Form, IMessageFilter I also have this implemented bool...
7
by: Michael Culley | last post by:
I've added an IMessageFilter to my app but I don't get messages or I get only a few and then it stops. My code is very simple. Am I doing something wrong? public class MF : IMessageFilter {...
1
by: Neil Stevens | last post by:
Hi, I am in the process of developing a popup utility for a project i am working on, the basic idea is that when a user presses the control key a popup menu will be displayed listing the shortcut...
4
by: GrandpaB | last post by:
Hi, I recently had a post about how to block Mousewheel events. The answer was to implement an IMessageFilter. Sadly, I must report that after 24 hours of researching my library and online...
4
by: ThunderMusic | last post by:
Hi, I'm developping a form that renders differently when hovered and trigger some processing when not hovered (leaved). The thing is, when I leave my form and another form from my application is...
3
by: Spam Catcher | last post by:
Hi all, I'm having some trouble with the Mouse Hover/Leave events on a user control. Say I have a user control with a panel covering the whole control. In turn, a label + picture box cover...
4
by: Sigilaea | last post by:
My previous post got squashed because m post is too long. Sorry for that: I have an AJAX page with a CSS menu at the top. My problem is the hover functionality stops working after someone clicks...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.