Solved

How to use Class CRectTracker in ON_WM_MBUTTONDOWN?

Posted on 2002-03-28
5
690 Views
Last Modified: 2013-11-20
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.
0
Comment
Question by:Gempin
  • 3
  • 2
5 Comments
 
LVL 1

Expert Comment

by:jemax
ID: 6907781
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


0
 

Author Comment

by:Gempin
ID: 6911758
Any other comments?
0
 
LVL 1

Accepted Solution

by:
jemax earned 100 total points
ID: 6912896
Hi,

I can propose two options:
1)
Derive your own class from CRectTracker override TrackHandle() and add handling for WM_MBUTTONUP
2)
void CTrackerView::OnMButtonUp(UINT nFlags, CPoint point)
{
    PostMessage (WM_LBUTTONUP,0,0);
}
CRectTracker's internal message loop will get & handle it, so no side effects. The only issue could be, if you have already some code in your CTrackerView::OnMButtonUp, you will need to add a flag to determine to send WM_LBUTTONUP or not.

HTH,
jemax
0
 
LVL 1

Expert Comment

by:jemax
ID: 6912930
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.
0
 

Author Comment

by:Gempin
ID: 6914739
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.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Is it possible to combine several text files into one big one? (redhat v5 enterprise) 4 81
Tab names are off by one 5 53
matchUp  challenge 6 53
mapAB Challlenge 35 126
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now