Click here to Skip to main content
13,148,378 members (57,483 online)
Click here to Skip to main content
Add your own
alternative version


26 bookmarked
Posted 15 Mar 2004

24 Bit Color Icon in System Tray

, 15 Mar 2004
Rate this:
Please Sign up or sign in to vote.
An article on displaying icons with more than 256 colors in system tray


I have found a lot of articles on CodeProject on displaying a system tray icon, but none of them allowed me to display an icon with more than 256 colors (at least I did not find any one). I was in need to display icons having more than 256 colors. A little bit of effort with MSDN put me on the right deck. Since a lot has been done for system tray icons, I did not go for re-inventing the wheel, and used the Chris Maunder class of CSystemTray with very little modification (not relating to icon display, instead enabling menu update handlers to work out. You can insert the code below in Chris's class to provide an overloaded function for this). All the credits for that class goes to Chris Maunder.

By default Visual studio does not load an icon in its editor, if it contains more than 256 colors. If you import an icon with more than 256 colors, it loads it as bitmap resource. What you need to do is to extract icon from that bitmap resource. See the section "Using the code" to see detail, how it has been done.


I had benefited a lot from CodeProject. I wished, I could have a contribution too. A very small opportunity came in my way, I cashed it on. I will try to put some more useful articles as soon as its possible for me.

Using the code

There is nothing tricky in this article. Create two member variable of type CBitmap and HICON in your class (here CSysTray24Dlg) along with an object of CSystemTray below:

CSystemTray m_TrayIcon;
HICON m_hTrayIcon;
CBitmap m_24bitBMP;

Now in OnInitDialog function extract the icon from the bitmap resource as follows:

    ICONINFO icInfo;
    icInfo.fIcon = TRUE;
    icInfo.hbmMask = (HBITMAP) m_24bitBMP;
    icInfo.xHotspot = 0;
    icInfo.yHotspot = 0;
    icInfo.hbmColor = (HBITMAP) m_24bitBMP;
    m_hTrayIcon = CreateIconIndirect(&icInfo);

Now display the icon as below:

if (!m_TrayIcon.Create(NULL,// Parent window
    WM_ICON_NOTIFY, // Icon notify message to use
    "24 bit Icon", // tooltip
    m_hTrayIcon, // Icon to use
    IDR_POPUP_MENU)) // ID of tray icon
    return FALSE;

Remember to destroy the icon handle in destructor or when you don't need it as:


That's it.


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

Muhammad Asif Khan
Web Developer
Pakistan Pakistan
Masters of Computer Sciences from International Islamic University Islamabad, Pakistan
Love programming in C++ and VC.

You may also be interested in...


Comments and Discussions

GeneralRe: why. Pin
l a u r e n16-Mar-04 7:41
memberl a u r e n16-Mar-04 7:41 
GeneralRe: why. Pin
l a u r e n16-Mar-04 8:02
memberl a u r e n16-Mar-04 8:02 
GeneralRe: why. Pin
James Raine16-Mar-04 22:17
memberJames Raine16-Mar-04 22:17 
GeneralRe: why. Pin
l a u r e n16-Mar-04 8:25
memberl a u r e n16-Mar-04 8:25 
GeneralRe: why. Pin
Neville Franks16-Mar-04 10:04
memberNeville Franks16-Mar-04 10:04 
GeneralRe: why. Pin
l a u r e n16-Mar-04 10:05
memberl a u r e n16-Mar-04 10:05 
GeneralRe: why. - It seems to be redundant Pin
semmel7116-Mar-04 7:54
membersemmel7116-Mar-04 7:54 
GeneralRe: why. - It seems to be redundant Pin
l a u r e n16-Mar-04 7:56
memberl a u r e n16-Mar-04 7:56 
GeneralRe: why. - It seems to be redundant Pin
semmel7116-Mar-04 8:09
membersemmel7116-Mar-04 8:09 
Generalyou just don't get it? Pin
gaamoa16-Mar-04 9:55
membergaamoa16-Mar-04 9:55 
GeneralRe: you just don't get it? Pin
l a u r e n16-Mar-04 9:58
memberl a u r e n16-Mar-04 9:58 
GeneralRe: why. - It seems to be redundant Pin
Muhammad Asif Khan16-Mar-04 19:07
memberMuhammad Asif Khan16-Mar-04 19:07 
GeneralRe: why. - It seems to be redundant Pin
Anonymous28-Jan-05 0:25
sussAnonymous28-Jan-05 0:25 
semmel71 wrote:
Whats more frustrating is the 16-color VGA palette used for tray icons in Win 2000 and before!!

That is not true.
Under windows 98, you can switch the option "Display icons using all possible colors" in Control panel/desktop properties/Effects.

But directories icons are less beautiful with 256 colors, i think. Laugh | :laugh:

And with that, icons can be 24 bits !
I programmed a viewer for .jpg files that display a 32x32 24 bits icon, and counted the colors entries for an icon, after printing screen, and found 589 different colors !

I think that for Windows 95, you need microsoft plus to do that.

It is fun to see that a 16x16 24 bits icon is smaller in memory than a 16x16 256 colors (with optimized palette).
GeneralRe: why. Pin
Muhammad Asif Khan16-Mar-04 18:55
memberMuhammad Asif Khan16-Mar-04 18:55 
GeneralRe: why. Pin
noshbar18-Mar-04 3:49
membernoshbar18-Mar-04 3:49 

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
Web01 | 2.8.170924.2 | Last Updated 16 Mar 2004
Article Copyright 2004 by Muhammad Asif Khan
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid