Click here to Skip to main content
12,952,186 members (58,613 online)
Click here to Skip to main content
Add your own
alternative version


99 bookmarked
Posted 24 Apr 2005

C2DPushGraph: A Push Graph Control

, 24 Apr 2005
Rate this:
Please Sign up or sign in to vote.
A push graph control similiar to the graph control located in Microsoft's Task Manager.


In past programming experiences, I've often had a desire to display and monitor the rate or performance of some operation on a graph. Whether it be the rate of write operations or the number of content results extracted each second, I always thought a graph similar to the graphs found in Windows XP’s Task Manager (CTRL-Alt-Delete) performance and networking tabs would do the trick well. After a quick search on Google for the graph control clone yielded no relevant results, I decided cloning it myself would be an interesting and beneficial experience.

As time progressed and cloning the control proved itself easy, I decided to add more features and make it completely customizable in nearly every aspect. In the end, as the smoke cleared, I was left face to face with the control this article revolves around. It looked and behaved astonishingly beautiful for being developed with such haste. But who cares about its pastime, let's move on and see how easy it is to implement...

Using the code

If any of you read my last article (CGoogle), you’ll be informed of the fact I’m approaching my articles with a new style. Instead of rambling on and on about a certain feature, I'll attempt to hand you the vital information in a much quicker fashion.

Adding the Control to your Dialog

There are two ways to add the control to your dialog, one being the politically correct way of doing it, and the other being the easy way.

If you're looking for the easy way, first add a static control to your dialog (I typically use the picture control for a frame). Then, give the newly created control the desirable styles and a unique ID. You should then proceed to position and stretch the control to where you want the graph. Now, add a new variable to your dialog class using C2DPushGraph as the type. Finally, call CreateFromStatic from OnInitDialog and pass the control ID as the first parameter, and the parent window as the second (you may use the 'this' pointer if you’re calling CreateFromStatic from the parent dialog class).

The politically correct way involves using the Custom Control item in the resource editor and specifying C2DPushGraph as the class name. From there, you proceed just as you would with any custom control.

Setting the Graph Range

Before continuing, you should set the range of your graph. The range being the minimum and maximum possible magnitudes (for example, a CPU usage graph might have a minimum of 0 and a maximum of 100). To set the range, you can use one or more of the following: SetMaxPeek, SetMinPeek, or SetPeekRange.

Adding a New Line

The two most important parts of C2DPushGraph are obviously being able to add a new line, and updating that line with new data. So we'll start off with adding a line. To add a new line, you call AddLine, which has the following prototype: AddLine( UINT uiLineID, COLORREF crColor ). The first parameter is the unique ID of the line, this is what you'll use later to indicate you're changing a specific line. The second parameter is the color of the line. I strongly suggest using a preprocessor definition or named constant for your line ID, it makes things much easier.

Pushing a New Point to a Line

Unlike a typical graph, to add a new point to a line, you only need to provide the point's magnitude or Y coordinate. Each magnitude should be a number within your graph’s range, though it will be adjusted to the nearest valid number if it is greater or less than the current maximum and minimum range values. To push a new point to a line, you call Push, which has the following prototype: Push( int nMagnitude, UINT uiLineID ).

You'll notice that after pushing a new magnitude to a line, the graph will remain unchanged. This is because you must first push the desired magnitudes to however many lines you wish, then call Update().

Customizing the Graph’s Visual Appearance

Before listing the functions available for setting and retrieving your graph's visual appearance, here is a quick pictorial showing the most basic attributes of the graph control:

Functions Available for Setting Attributes

  • C2DPushGraph::SetBGColor
    void SetBGColor( COLORREF crColor )
    • crColor: The new background color.
  • C2DPushGraph::SetGridColor
    void SetGridColor( COLORREF crColor )
    • crColor: The new grid color.
  • C2DPushGraph::SetGridSize
    void SetGridSize( unsigned short usWidthAndHeight )
    • usWidthAndHeight: The width/height of each grid unit in pixels.
  • C2DPushGraph::SetInterval
    void SetInterval( unsigned short usInterval )
    • usInterval: The distance in pixels between each magnitude point.
  • C2DPushGraph::SetLabelForMax
    void SetLabelForMax( LPCTSTR lpszLabel )
    • lpszLabel: The C-string used to label the graph's maximum magnitude.
  • C2DPushGraph::SetLabelForMin
    void SetLabelForMin( LPCTSTR lpszLabel )
    • lpszLabel: The C-string used to label the graph's minimum magnitude.
  • C2DPushGraph::SetLineColor
    bool SetLineColor( COLORREF crColor, UINT uiLineID )
    • crColor: The line's new color.
    • uiLineID: The line's ID.
  • C2DPushGraph::SetTextColor
    void SetTextColor( COLORREF crColor )
    • crColor: The new color for the minimum and maximum labels.
  • C2DPushGraph::ShowAsBar
    bool ShowAsBar( UINT uiLineID, bool bAsBar )
    • UiLineID: The line’s ID.
    • bAsBar: true if you want the line displayed in bar graph format, false if not.
  • C2DPushGraph::ShowGrid
    void ShowGrid( bool bShow = true)
    • bShow: true if the grid is to be shown, false if not.
  • C2DPushGraph::ShowLabels
    void ShowLabels( bool bShow = true)
    • bShow: true to show the minimum and maximum labels, false to hide them.

Functions Available for Retrieving Attributes

  • C2DPushGraph::GetBGColor
    COLORREF GetBGColor() const
  • C2DPushGraph::GetGridColor
    COLORREF GetGridColor() const
  • C2DPushGraph::GetGridSize
    int GetGridSize() const
  • C2DPushGraph::GetInterval
    unsigned short GetInterval() const
  • C2DPushGraph::GetLabelForMax
    LPCTSTR GetLabelForMax() const
  • C2DPushGraph::GetLabelForMin
    LPCTSTR GetLabelForMin() const
  • C2DPushGraph::GetLineColor
    COLORREF GetLineColor( UINT uiLineID )
    • UiLineID: The line’s ID.
  • C2DPushGraph::GetMaxPeek
    int GetMaxPeek() const
  • C2DPushGraph::GetMinPeek
    int GetMinPeek() const
  • C2DPushGraph::GetTextColor
    COLORREF GetTextColor() const

Contacting the Author

Stuart Konen E-mail address:

Quick shout out: I'm currently looking for employment and am open to contracts.


  • April 14, 2005 - Began work on C2DPushGraph.
  • April 20, 2005 - Submitted C2DPushGraph to The Code Project.


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

Stuart Konen
United States United States
Well first of all, it is fairly obvious my name is Stuart Konen (I'm sure 50% of you just took notice), all of my life I've lived on a farm located in Northern Idaho. What shatters the stereotype of rural residence however, is the fact that I'm very active in the technology and programming worlds. I took up the hobby of programming at age 9, at that point it was little language known as Quick Basic *sigh*. Fast forward another 9 years... (Woah... I just realized that's half of my existence. But that's something I'll have to contemplate later, as I have an autobiography to tell).

Now my experience in programming has improved vastly, I've released various technologies and programs and I'm continuing to pump out concepts and systems that are getting glances from all over the world. My weapon of choice is C++, the core language of the majority of freshly released software, it's sleak, mean, and incrediably powerful. On the side I venture into web application development and site design, where my interest lies in PHP. Over the years my project have included everything from Artificial Intelligence to Web Statistic Tracking systems, but that's the past. What matters is the future... Remember that question we were always asked in grade school? Where did we see ourselves in 10 years. Well that question was asked about 8 years ago in my life, so it looks as though I only have two more for planning stages. In two years I see myself plunging into the world of research, creating my own Research and Development firm, aiming to meet the never-ending need for new and superior software and technology. Soon after becoming a multi-billionare I'll pursue my dream of world domination. Nobody is perfect...

Actually when it comes down to things, the money has no meaning. But there you have it, a 5 minute slice of my thoughts and time... If you have any job opportunities or have the slight urge to initiate a conversation with me, it can be done via email: skonen [at] gmail [dot] com

You may also be interested in...


Comments and Discussions

QuestionHow to print ? Pin
Surej9-Mar-11 19:58
memberSurej9-Mar-11 19:58 
Generalkudos to the author Pin
cupcake.2714-Jul-10 5:19
membercupcake.2714-Jul-10 5:19 
GeneralCopyright Pin
JazzMaTazz6-Sep-07 11:09
memberJazzMaTazz6-Sep-07 11:09 
QuestionSave to image ...? Pin
eldran24-Jul-06 19:06
membereldran24-Jul-06 19:06 
GeneralSome error in debug mode on my side.What is wrong??? :( :( Pin
chaochao_cz6-Sep-05 15:55
memberchaochao_cz6-Sep-05 15:55 
GeneralRe: Some error in debug mode on my side.What is wrong??? :( :( Pin
ichiru12-Aug-06 14:15
memberichiru12-Aug-06 14:15 
GeneralRe: Several Errors fixed Pin
nuray9-Aug-05 4:23
membernuray9-Aug-05 4:23 
GeneralRe: Several Errors fixed Pin
Harald Krause9-Aug-05 4:50
memberHarald Krause9-Aug-05 4:50 
GeneralSeveral Errors fixed Pin
Harald Krause24-Jul-05 8:51
memberHarald Krause24-Jul-05 8:51 
GeneralRe: Several Errors fixed Pin
Moak4-Aug-05 22:07
memberMoak4-Aug-05 22:07 
GeneralShowLine Pin
varandas7914-Jul-05 0:58
membervarandas7914-Jul-05 0:58 
Generalmemory problem on windows ce Pin
marte00115-Jun-05 23:01
membermarte00115-Jun-05 23:01 
GeneralRe: memory problem on windows ce Pin
Hadrielk12-Jul-05 4:32
memberHadrielk12-Jul-05 4:32 
GeneralRe: memory problem on windows ce Pin
markhaarindewar11-Jan-07 3:19
membermarkhaarindewar11-Jan-07 3:19 
GeneralComes very handy Pin
Moak1-Jun-05 22:00
memberMoak1-Jun-05 22:00 
GeneralNo grid lines on Release Build Pin
June Hee Lee12-May-05 14:22
memberJune Hee Lee12-May-05 14:22 
GeneralRelease build is fine. Your code. Pin
Stuart Konen13-May-05 12:31
memberStuart Konen13-May-05 12:31 
GeneralRe: Release build is fine. Your code. Pin
varandas7917-Jun-05 0:09
membervarandas7917-Jun-05 0:09 
GeneralRe: Release build is fine. Your code. Pin
phil3502-Jul-05 21:32
memberphil3502-Jul-05 21:32 
GeneralRe: Release build is fine. Your code. Pin
Michael Pearce18-Oct-05 18:45
memberMichael Pearce18-Oct-05 18:45 
GeneralLine Thickness Pin
Joseph Dempsey25-Apr-05 10:49
memberJoseph Dempsey25-Apr-05 10:49 
GeneralRe: Line Thickness Pin
Stuart Konen26-Apr-05 10:01
memberStuart Konen26-Apr-05 10:01 

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.170525.1 | Last Updated 25 Apr 2005
Article Copyright 2005 by Stuart Konen
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid