Link to home
Start Free TrialLog in
Avatar of Mindo
Mindo

asked on

WM_MOUSELEAVE message

I'm writing an ActiveX control. I must know when the mouse leaves the area of my control. I wrote the following function to track this event:

void CNMButtonCtrl::SetMouseTrackEvent()
{
      TRACKMOUSEEVENT tme;
      tme.cbSize = sizeof(tme);
      tme.dwFlags = TME_LEAVE;
      tme.hwndTrack = m_hWnd;
      _TrackMouseEvent(&tme);
}

I get the WM_MOUSELEAVE event in the following function:

LRESULT CNMButtonCtrl::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
      if(message == WM_MOUSELEAVE)
      {
            AfxMessageBox ("WM_MOUSELEAVE", MB_OK, 0);
      }
      
      return COleControl::WindowProc(message, wParam, lParam);
}

Also, i have the following function using which i tell Windows that i want to listen to this event:

void CNMButtonCtrl::OnMouseMove(UINT nFlags, CPoint point)
{
      SetMouseTrackEvent();
      
      COleControl::OnMouseMove(nFlags, point);
}

So i'm notified when i receive the WM_MOUSELEAVE event.

My problem is:
I do not receive this event when the user moves the mouse with the LEFT BUTTON PRESSED.

How to solve this problem?
ASKER CERTIFIED SOLUTION
Avatar of MichaelS
MichaelS

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Mindo
Mindo

ASKER

So you suggest me not to use the _TrackMouseEvent() API and use the timer?
I see two ways here, one is trying to figure out why your approach doesn't works and another is to use different way. It'a up to you what to use.
I have not seen this behaviour with my own controls (although they are not ActiveX controls).  _TrackMouseEvent works fine regardless of mouse buttons

It could be that someone else is getting hold of these messages and treating it as a drag.

What happens when you get a left-button down event?  Does it do something like capture the mouse and do a message loop?


Avatar of Mindo

ASKER

When i get the WM_LBUTTONDOWN, i don't havea message loop nor do i capture the mouse. I don't know why don't i get the WM_MOUSELEAVE event.
Does it fail when
1) you already have the mouse button down when OUTSIDE the control, keeping the mouse button down move over the control and out again

2) you are inside the control with mouse button up, then press and hold the mouse button and move out (ie. a bit like you are trying to drag the control).

If 2) only, then I think some bit of code is thinking you are trying to drag the window (noone called DragDetect are they?).  If both, then ... buggered if I know.
Avatar of Mindo

ASKER

Yes, my case is the 2). I think i'll use the timer to detect MouseLeave and MouseEnter events. I've found an example of how to do this.