Click here to Skip to main content
13,550,059 members
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

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 
Each bitmap pixel contains color ranging from 0 to 2^NoOfBits. i.e an 24 bit bitmap pixels contain color range from 0 to 2^24 but what to say about icons. Do u anticipate the same behaviour from icons having more than 256 colors?
GeneralRe: why. - It seems to be redundant Pin
Anonymous28-Jan-05 0:25
sussAnonymous28-Jan-05 0:25 
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
Web02 | 2.8.180515.1 | Last Updated 16 Mar 2004
Article Copyright 2004 by Muhammad Asif Khan
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid