Solved

How to use Class CRectTracker in ON_WM_MBUTTONDOWN?

Posted on 2002-03-28
5
712 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Expand to include initial dialog with two choices. 9 94
Define unique primary key 9 99
unable to delete all specified values regedit 38 890
either24  challenge 19 110
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

739 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