Click here to Skip to main content
13,900,869 members
Click here to Skip to main content
Add your own
alternative version


17 bookmarked
Posted 24 Aug 2007
Licenced CPOL

The Ultimate Toolbox Task Bar Icon

, 25 Aug 2007
Rate this:
Please Sign up or sign in to vote.
The Ultimate Toolbox makes it easy to configure and customize a taskbar icon for your application

Visit the Ultimate Toolbox main page for an overview and configuration guide to the Ultimate Toolbox library.

Source code and project files for this sample can be found in the samples\gui\TaskBarIcon directory of the sample projects download.


The COXTaskbarIcon class encapsulates the Win32 API's Shell_NotifyIcon() function to let you easily show, hide, or change icons in Window 95's or Windows NT's taskbar notification area. It is derived from the MFC class CWnd, therefore you can derive a class from it to handle mouse messages (thus hiding codes for taskbar icons from those in your main program). Yet, it doesn't abolish the convenience of handling mouse messages within your CWnd classes, because you can always tell it to route those messages to another CWnd object even at run-time.


  • COXTaskbarIcon is derived from CWnd;
  • easy to show, hide or change a taskbar icon;
  • easy to set or change the tooltip text of a taskbar icon at run-time;
  • easy to handle the mouse messages from taskbar icons, either within a derived class from COXTaskbarIcon, or within your CWnd classes.


You can use the COXTaskBarIcon icon class directly or through a derived class that can handle timer, mouse, etc. notifications directly just by declaring an instance in your application, setting an icon image, and calling the Show method.

This code is from the CTaskBarDlg class's constructor (from the taskbar sample shown):

// When there is only one taskbar icon, you don't need to specify an ID.

// The ID is useful only when implementing two (or more) taskbar icons,

// AND you want to handle mouse messages from both icons within one

// message handler (therefore, you need that ID to tell which icon posted

// the msg). However, it might be a good idea to assign an ID, and check

// the ID in the message handler, especially when you may need

// to derive your classes (somebody else may add another taskbar icon).

// Note: you don't need to destroy a taskbar icon. It's done in its own

// destructor.

m_TaskbarIcon.m_pPopupOwner = this;
// let this dialog handle popup menu's message

// Note: m_pPopupOwner is NOT a member of COXTaskbarIcon. This is for the

// demo's derived taskbar only.

From here, in the sample, the task bar icon is shown or hidden and it's various aspects set at runtime in response to user interaction with the dialog, but could just as easily be setup for the duration of the application in OnInitDialog.

A complete class reference for the COXTaskBarIcon class is available in the compiled HTML help documentation.


Initial CodeProject release August 2007.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

The Ultimate Toolbox
Web Developer
Canada Canada
In January 2005, David Cunningham and Chris Maunder created, a new group dedicated to the continued development, support and growth of Dundas Software’s award winning line of MFC, C++ and ActiveX control products.

Ultimate Grid for MFC, Ultimate Toolbox for MFC, and Ultimate TCP/IP have been stalwarts of C++/MFC development for a decade. Thousands of developers have used these products to speed their time to market, improve the quality of their finished products, and enhance the reliability and flexibility of their software.
Group type: Organisation

459 members

You may also be interested in...

Comments and Discussions

GeneralTitle Seems Wrong Pin
Rick York24-Aug-07 19:47
mveRick York24-Aug-07 19:47 
GeneralRe: Title Seems Wrong Pin
The Ultimate Toolbox25-Aug-07 2:12
groupThe Ultimate Toolbox25-Aug-07 2:12 
GeneralRe: Title Seems Wrong Pin
Rick York26-Aug-07 8:58
mveRick York26-Aug-07 8:58 

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 | Cookies | Terms of Use | Mobile
Web02 | 2.8.190306.1 | Last Updated 25 Aug 2007
Article Copyright 2007 by The Ultimate Toolbox
Everything else Copyright © CodeProject, 1999-2019
Layout: fixed | fluid