Click here to Skip to main content
13,147,689 members (32,300 online)
Click here to Skip to main content
Add your own
alternative version


23 bookmarked
Posted 19 Jul 2004

Limit CRectTracker handles

, 19 Jul 2004
Rate this:
Please Sign up or sign in to vote.
Limit additional resize operations to a single handle.

Sample Image - Tracker_demo.jpg


I had a need to restrict MFC's CRectTracker handles. Once the user selected an object and resized via any one handle of the tracker, I could not let them then grab a different handle. Via an override to CRectTracker and a modification of the handle mask, this was accomplished.

This article discusses how to change the tracker handle mask. As a side issue, the demo may be referenced as an example of how to use the tracker's rubber band feature.


CRectTracker is placed in a mouse function, often, in OnMouseMove().

The tracker rectangle may be displayed with handles either inside or outside of the rectangle. Once the user grabs a handle with a clink and hold, CRectTracker captures all further mouse move messages. No further points are reported to OnMouseMove() until the user releases the tracker handle.

This class is very useful to rubber band a rectangle.

There is a handle mask to define which handles are displayed. It may be obtained via GetHandleMask().

  • 0x00 0000 0000 is translate (no handles).
  • 0x0F 0000 1111 is the 4 corners.
  • 0x50 0101 0000 is the right and left sides.
  • 0xA0 1010 0000 is the top and bottom.

Handle's returns are numbered by the four corners clockwise 0-3, then the four centers from the top center clockwise 4-7.

By manipulating this mask, one can disable handles. Thus to limit a resize in that direction. To access the mask, one must derive a new class from CRectTracker. As my company is named WedgeSoft, I named my class CWS_RectTracker.

CWS_RactTracker is a very simple override, doing only one thing: modifying the handle mask.

The Sample

This sample code can be used to learn a bit about how to use CRectTracker as well as see how to turn off any handle. All contents were researched through MSDN library CDs. To give the user something to resize, I create a poly line via a CWS_PolyLine class. The class is basically useless. But I had fun creating it. Perhaps you can learn something about translation there.

In addition, there is a useful little function to display a bitmask.

What to look for

When you run the program, use tracker's rubber band to create a poly line. Then use tracker's rubber band to select that poly line. Then resize. Note that once resized, only the first handle selected may be used for further resize operations. A click within the bounds of the poly line allows the item to be translated. A double click anywhere turns off the resize tracker. (See under menu Help, HowTo.)

In OnMouseMove(), a tracker rubber band is activated to select an existing poly line or insert a new poly line. In OnLButtonDown(), a tracker hit test is performed to see if a tracker handle is selected. OnSetCursor() sets the proper tracker cursor.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

United States United States
Retired C programmer and Unix Sys Admin, then VC6 C++ MFC programmer. I moved to VC7 C++ 2003 in Oct of 04, and VC8 C++/CLI early in 06. I resisted C# for a long time. But now C# is my preferred language. I'm through with upgrading. I'll stay at VC2008 and C# as I only program for fun anymore.

You may also be interested in...


Comments and Discussions

QuestionMy vote of 5 Pin
kanalbrummer4-Jul-14 19:24
memberkanalbrummer4-Jul-14 19:24 
GeneralBug Pin
jjorsett7-Jul-05 10:41
memberjjorsett7-Jul-05 10:41 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170915.1 | Last Updated 20 Jul 2004
Article Copyright 2004 by Gammill
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid