Dynamic Icon Meters

Environment: VC6 SP4, W2K SP1

Over the past couple years I have needed to create an informative bar graph of information that is in the form of an icon in the System Tray. I initially made several icons at different levels and then combined the levels that corresponded with the information that I wanted to display. This method worked, but became cumbersome to change the colors of the bars, and would cause small applications unnecessary bloat. After sitting on it for a while I decided to make a method to create a flexible dynamic meter system for an icon, so CMeterIcon was created.

It is not so simple to use, but it makes this up in flexibility. Here is how to use it.

// initilize the meter
CMeterIcon mi32;
const int nNumBars32 = 3;
const int nLevels32 = 4;

// set the limits of where the bar color changes (low-high)
int pLimits32[nLevels32] = {25,35,87,100};

// set the corresponding color for each level
COLORREF pColors32[nLevels32] = 
 {RGB(255,0,0),RGB(255,255,0),RGB(0,255,0),RGB(0,255,255)};

// start it up
mi32.Init(hFrame32,nMaxVal,nNumBars32,nSpacing,32,32,RGB(0,0,0));

// load our limit and color info
mi32.SetColorLevels(pLimits32,pColors32,nLevels32);

// create an array of values for the bars
int pVals32[nNumBars32] = {nVal1,nVal2,nVal3};

// generate the icon (destroy this icon using DestroyIcon())
HICON hIcon32 = mi32.Create(pVals32);

Downloads

Download demo project and source - 14 Kb


Comments

  • Pb when changing windows session

    Posted by Joccy on 11/16/2010 10:16am

    Hi, I used CMeterIcon in a service programm (VStudio C++ 6.0), but when i change session, the icon disappear. Why ? Is it due to CreateIconIndirect() function ? In an other function, i used DuplicateIcon() from Windows and the icon disapear too. I avoid duplicateIcon() and then it's OK (except for CMeterIcon). Is someone can help me, please ? Thanks.

    Reply
  • Adding a background icon

    Posted by Legacy on 04/06/2001 12:00am

    Originally posted by: Martin Evans

    Nice idea!

    Does anyone know how to change things to allow a 'starting' background icon to be specified so the graph is drawn on top? I have a number of HICONs that I would like to start with before drawing things.

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Live Event Date: November 20, 2014 @ 2:00 p.m. ET / 11:00 a.m. PT Are you wanting to target two or more platforms such as iOS, Android, and/or Windows? You are not alone. 90% of enterprises today are targeting two or more platforms. Attend this eSeminar to discover how mobile app developers can rely on one IDE to create applications across platforms and approaches (web, native, and/or hybrid), saving time, money, and effort and introducing apps to market faster. You'll learn the trade-offs for gaining long …

  • Live Event Date: October 29, 2014 @ 11:00 a.m. ET / 8:00 a.m. PT Are you interested in building a cognitive application using the power of IBM Watson? Need a platform that provides speed and ease for rapidly deploying this application? Join Chris Madison, Watson Solution Architect, as he walks through the process of building a Watson powered application on IBM Bluemix. Chris will talk about the new Watson Services just released on IBM bluemix, but more importantly he will do a step by step cognitive …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds