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.
Overview


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.
Features
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.
Usage
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):
m_TaskbarIcon.Create();
m_TaskbarIcon.m_pPopupOwner = this;
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.