Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

mouse enter and leave

Status
Not open for further replies.

ceodav

Programmer
Feb 21, 2003
106
IT
Hi all

i have two picture controls in my application and i want to know when the mouse pass over one or
the other,

using the mouse move function?

any suggestion will be very appreciated

thanks

Davide
 
If you're using plain C/C++, you need to process the WM_MOUSEMOVE message.

If you're using MFC, you need to use an "OnMouseMove" (or whatever the name is) handler.

In either case, I suspect you'll need to convert the coordinates to Client coordinates.
 
You can use WM_MOUSELEAVE to tell when the mouse leaves the window. To use this you must create a trackmouseevent.

define a MOUSETRACKEVENT structure member in your application.

Code:
TRACKMOUSEEVENT m_sTME;

Then in you initialisation set it up.
Code:
m_sTME.cbSize = sizeof(TRACKMOUSEEVENT);
m_sTME.dwFlags = TME_LEAVE; // leave event only
m_sTME.hwndTrack = GetSafeHwnd(); //window handle to track
m_sTME.dwHoverTime = 0;

Then you just need to start the tracking.
Code:
_TrackMouseEvent(&m_sTME);

remember, depending on your application you may have to restart the tracking each time the WM_MOUSELEAVE is handled.
 
Why WM_MOUSELEAVE and not WM_MOUSEENTER ? The guy wants to catch the moment, the mount moves over the controls.
Btw, you will need the tracker for the picture controls, not parent window.

------------------
When you do it, do it right.
 
I found the solution...

in mouse move event i check if the mouse is inside my picture control with PtInRect function

something like this

RECT rcL;
CWnd *wL=GetDlgItem(IDC_PICTURE_LEFT);

::GetWindowRect(wL->m_hWnd, &rcL);
if(PtInRect(&rcL,pt))
{
PostMessage(WM_MOUSEHOVER,0,0L);
}

then it is just a matter of WM_MOUSEHOVER message...
for the same reason you can manage WM_MOUSELEAVE message.
bye

Davide
 
in regards how MouseHover works, you probably would like to implement time control, unless you want something happening even when the user quick-moves the mouse in and out of the control.

------------------
When you do it, do it right.
 
Subclassing the picture control "CStatic" would work but you would have to create it using the SS_NOTIFY style. The mousemove and trackmouseevent (mouseleave) can then be used to monitor entry and exit from the control. However the mouseleave will be called every time the mouse moves on the parent window. A small boolean flag set in mouse move and reset in the leave would sort this problem.

Alternately using the mousemove and trackmouseevent on the parent window in conjunction with creating the picture control using the SS_NOTIFY style would allow the entry/exit to be monitored via reverse order i.e. mouse leave would be entering the picture control and mousemove leaving it.
This was my initial thought.

Either of these will work as will the solution of checking the point passed into the parent windows mousemove.

No where did I state that the code I posted would be a complete solution to the problem, 'twas merely an indication on how to utilise the trackmouseevent.

OB
 
Btw, there is no such thing as WM_MOUSEENTER.

------------------
When you do it, do it right.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top