Link to home
Start Free TrialLog in
Avatar of Gempin
Gempin

asked on

How to use Class CRectTracker in ON_WM_MBUTTONDOWN?

At first look at the code:
void CTrackerView::OnMButtonDown(UINT nFlags, CPoint point)
{
        ...
        CRectTracker tracker;
     if (tracker.TrackRubberBand(this, point)
        {
        A(); // To do ON_WM_MBUTTONUP event while after the mouse midbutton is released
        }
        ...
}

if these code is in OnLButtonDown, All is OK, but it's no way if it is moved into OnMButtonDown, CRectTracker can redraw the rectangle dynamically and perfectly when mouse pointer is moving on the view, but it can not know release event while the mouse midbutton is released.
How to get to the fuction A in codes? experts, help me! thanx.
Avatar of jemax
jemax

Hi,

you have the CRectTracker source in your "Program Files\Microsoft Visual Studio\VC98\MFC\SRC\TRCKRECT.CPP"

TrackRubberBand() calls TrackHandle (), that has its own message loop, and there is no handling for WM_MBUTTONUP :(

HTH,
jemax


Avatar of Gempin

ASKER

Any other comments?
ASKER CERTIFIED SOLUTION
Avatar of jemax
jemax

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
Hi,

void CTrackerView::OnMButtonUp(UINT nFlags, CPoint point)
{
   PostMessage (WM_LBUTTONUP, nFlags, MAKELONG(point.x, point.y));
}

will be much better, TrackHandle() use the coords.
Avatar of Gempin

ASKER

O, jemax, thanks for your comments, your options is right, but I have solved this problem with own idea. My idea is following:
1)Modify MFC source in "Program Files\Microsoft Visual Studio\VC98\MFC\SRC\TRCKRECT.CPP", add a WM_MButtonDown message in CRectTracker's internal message loop.(Maybe it's not necessary)
2)Add one line code in CTrackerView::OnMButtonUp:

void CTrackerView::OnMButtonUp(UINT nFlags, CPoint point)
{
  ReleaseCapture();
}
I have inspected MFC class CRectTracker source, Because CRectTracker's internal message loop can not escape from SetCapture(), so add the line to release the capture,
It'll be OK. you can have a try.
Thanks for your comments again.