5,693,062 members and growing! (17,203 online)
Email Password   helpLost your password?
Desktop Development » Miscellaneous » General     Intermediate

Drawing trackers, moving and resizing the objects using double buffering.

By khurram7t8

Drawing, Positioning and resizing the Boxes with double buffering
C++, C#.NET 1.0, Win2K, WinXP, Windows, .NET, MFC, Visual Studio, VS.NET2002, Dev

Posted: 5 Jun 2003
Updated: 5 Jun 2003
Views: 75,813
Bookmarked: 50 times
Announcements
Loading...



Search    
Advanced Search
Sitemap
18 votes for this Article.
Popularity: 4.81 Rating: 3.83 out of 5
3 votes, 16.7%
1
0 votes, 0.0%
2
1 vote, 5.6%
3
2 votes, 11.1%
4
12 votes, 66.7%
5

Introduction

In VC++ we have a class CRectTracker which helps drawing the trackers and also there is function a DrawFocusRect() with which tracker behavior can be achieved. In C# I did not find any kind of such functionality (if there is then I am unaware at the moment.). So I decided to make program which draw box with tracker and allows manipulation with the box with the help of trackers.

Key features

  • Drawing trackers
  • Moving the boxes having trackers attached to it.
  • Resizing the box with the help of trackers.
  • Selection is made in Z Order.

I tried to avoid Form’s Invalidate() function as it generates flickering effects and drawing is not smooth. I designed the program in a way to maximize the usage of double buffering to avoid flickering effect.

Using the code

Class CRectTracker

Methods Functionality
DrawSelectionGhostRect() Draws the given ghost rectangle on the specified bitmap
InitTrackerRects() Initializes the eight rectangle of the tracker.
DrawSelectionTrackers() Draws the already initialized tracker rectangles
CursorCheck() Checks the position of the cursor and changes the form cursor with appropriate cursor and returns the border of the rectangle for the resizing purpose.

In the main program there are three modes of the program. First is the “None mode” which indicates that user is not drawing, second mode is the “Drawing mode” and it is invoked when user selects the Box icon from the toolbar and third is the “selection mode” it is invoked when user selects a box for changing the positioning or size.  

There is main bitmap which holds the current drawing. Whenever a change is required like drawing rubber band selection or drawing tracker a copy of the main bitmap is made and saved in TrackerImage bitmap and all the changes are made in it and in the end it is assigned to the main bitmap. Even when repaint is required then RePaintForm() function is called instead of calling paint() function of the form to avoid the flickering effect.

Conclusion

A simple program that demonstrates double buffering & tracker drawing is included. OnPaint() generates flickering effects so it is recommended to draw first on the bitmap and then on the form.

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

About the Author

khurram7t8



Location: Sweden Sweden

Other popular Miscellaneous articles:

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
 Msgs 1 to 20 of 20 (Total in Forum: 20) (Refresh)FirstPrevNext
Generalhow to add a tracker for a bit mapmembersandun neelanga0:09 31 Oct '07  
AnswerRe: how to add a tracker for a bit mapmember00thilani7:41 2 Jan '08  
Generalsource codememberRaja Sekhar Bandaru15:31 25 Apr '07  
GeneralRe: source codememberkhurram7t822:27 25 Apr '07  
Questionhow to delete a selected object?memberyuxuant20:28 31 Oct '05  
AnswerRe: how to delete a selected object?memberkhurram7t87:31 5 Nov '05  
Generalthanks! I have a questionsussxu xiaodong4:24 7 Jun '04  
GeneralRe: thanks! I have a questionmemberkhurram7t819:49 8 Jun '04  
GeneralExcellentsusscql6010:06 21 Nov '03  
GeneralRe: ExcellentmemberNickle11:19 18 Jan '04  
GeneralThanksmemberXboss21:22 30 Sep '03  
GeneralDrawing a TrackermemberJay Giganti6:23 12 Sep '03  
Generalthanksmemberbirol.bellikan@kibarholding.com2:22 27 Jun '03  
GeneralThanks!memberJoost Huizinga4:31 11 Jun '03  
Generalmultiple selection & group movememberDan Colasanti9:05 6 Jun '03  
Generalcorner resizers & Z-order selection problemsmemberDan Colasanti8:58 6 Jun '03  
GeneralRe: corner resizers & Z-order selection problemsmemberkhurram_manglian@yahoo.com17:48 6 Jun '03  
GeneralRe: corner resizers & Z-order selection problemsmemberNickle11:18 18 Jan '04  
GeneralAny chance doing this in C++?memberWREY3:28 6 Jun '03  
GeneralRe: Any chance doing this in C++?memberSledgeHammer6:18 6 Jun '03  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 5 Jun 2003
Editor: Nishant Sivakumar
Copyright 2003 by khurram7t8
Everything else Copyright © CodeProject, 1999-2008
Web20 | Advertise on the Code Project