Dynamic Icon Meters | CodeGuru

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 […]

Written By
CodeGuru Staff
CodeGuru Staff
Apr 4, 2001
1 minute read
CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More

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

CodeGuru Logo

CodeGuru covers topics related to Microsoft-related software development, mobile development, database management, and web application programming. In addition to tutorials and how-tos that teach programmers how to code in Microsoft-related languages and frameworks like C# and .Net, we also publish articles on software development tools, the latest in developer news, and advice for project managers. Cloud services such as Microsoft Azure and database options including SQL Server and MSSQL are also frequently covered.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.