Click here to Skip to main content
15,885,141 members
Articles / Programming Languages / C++
Article

Limit CRectTracker handles

Rate me:
Please Sign up or sign in to vote.
4.72/5 (8 votes)
19 Jul 20042 min read 46.9K   2K   25   2
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


Written By
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#; but now it is my preferred language. I'm through with upgrading. I'll stay at VC2008 and C#, as I only program for fun anymore.

Update 2019: I have moved back to Unix: Linux Cinnamon Mint. I got aggravated with Windows and VC. I've returned to my roots. Now, my preferred language is Java. I use IntelliJ as my IDE; but write my code with Emacs. I thoroughly enjoy Linux and being back on Unix! I've published a little game on the Kindle Fire and a little apt for Android phones. I hope you still love to code as much as I do when you reach my age... advanced 70's.

Comments and Discussions

 
QuestionMy vote of 5 Pin
kanalbrummer4-Jul-14 19:24
kanalbrummer4-Jul-14 19:24 
Exactly what I searched for.
GeneralBug Pin
jjorsett7-Jul-05 10:41
jjorsett7-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.