Solved

How to use Class CRectTracker in ON_WM_MBUTTONDOWN?

Posted on 2002-03-28
5
682 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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
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…
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.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

705 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