Click here to Skip to main content
Click here to Skip to main content
Go to top

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

Summary

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.

Background

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.

License

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

Share

About the Author

Gammill
Retired
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.

Comments and Discussions

 
QuestionMy vote of 5 Pinmemberkanalbrummer4-Jul-14 19:24 
GeneralBug Pinmemberjjorsett7-Jul-05 10:41 

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

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

| Advertise | Privacy | Mobile
Web04 | 2.8.140916.1 | Last Updated 20 Jul 2004
Article Copyright 2004 by Gammill
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid