Animate an Icon on the Taskbar when the Application Is Minimized


This article will show the technique to animate an application’s icon on the Taskbar when the application is minimized. The main usage of this implementation is to inform the user about some background tasks that are still active in the application when it is minimized.

Integrate to an Existing Project

Some Information about Windows Icons

Before the integration, it’s good to understand how Windows make use of the icon attached to a specific application. Normally, there will be more than one icon (with a difference in sizes) associated in a single icon file (.ico). At run time, Windows will determine the correct icon size to use based on the different interfaces.

Icon sizes:

  • 16×16: Displayed in Taskbar, Windows upper-left corner, detailed lists
  • 24×24: Displayed in Windows XP start menu
  • 32×32: Displayed on desktop, by Windows Explorer
  • 48×48: Displayed in Windows XP Explorer and system lists

Color depths:

  • Monochrome: Not used anymore
  • 16 colors: Displayed by Windows if the screen is 16 or 256 colors
  • 256 colors: Displayed by Windows if the screen is 64K or 16M colors
  • 16M colors (XP): Displayed by Windows XP if screen is 16M or more

First, additional icons are needed in the application; these icons will act as the “animation frames.” Because the animated icons will appear only on the Taskbar, you will create 16×16 icons. One way is to use Application Studio to create them. Or, there are also many free icon tools you can download from the Internet. If you are using an external icon tool, you need to import your newly created icons back to your project’s resource. Once the new icons are added to the resource, any one of them can be chosen to replace the current one at run time.

In this demo project, a timer event will be fired twice a second to inform the application when it’s time to change the icon. To achieve this, you add two message-handling functions:

Object ID Function Message
CMainFrame OnTimer WM_TIMER
CMainFrame OnDestroy WM_DESTROY

#define _totalArrayItem(array) (sizeof(array) / sizeof(array[0]) )
void CMainFrame::OnTimer(UINT nIDEvent)
static int icons[] = {

static long nIndex = 0;

if (IsIconic()) {
ChangeIcon(icons[nIndex ++ % _totalArrayItem(icons)]);
else {
nIndex = 0;
SetWindowText(“My Icon Will Animate On Taskbar When I am


To ease the arrangement of the animation sequence, an icon array is used to keep a pool of icons.

Don’t forget to destroy the timer on exit.

void CMainFrame::OnDestroy()


A new method called ChangeIcon will be created. You can call this method at ru time to change the icon. This method loads the requested icon and replaces the current window icon. The old icon is then removed.

void ChangeIcon(UINT nNewIconID);

void CMainFrame::ChangeIcon(UINT nNewIconID)
//get new icon handle
HICON hIconNew = AfxGetApp()->LoadIcon(nNewIconID);
//get current showing icon handle
HICON hIconCurr = (HICON) GetClassLong(m_hWnd, GCL_HICON);


// replace current icon with new one and redraw the window
if (hIconNew != hIconCurr) {
SetClassLong(m_hWnd, GCL_HICON, (long) hIconNew);

The Window Class Word

The window class word holds information about the windows’s icon, windows style, cursor, menu, and brush. ChangeIcon uses GetClassLong and SetClassLong to change the icon.

GetClassLong Function

The GetClassLong function retrieves the specified 32-bit (long) value from the WNDCLASSEX structure associated with the specified window.

DWORD GetClassLong(
HWND hWnd, // handle to window
int nIndex // offset of value to retrieve

SetClassLong Function

The SetClassLong function replaces the specified 32-bit (long) value at the specified offset into the extra class memory or the WNDCLASSEX structure for the class to which the specified window belongs.

DWORD SetClassLong(
HWND hWnd, // handle to window
int nIndex, // index of value to change
LONG dwNewLong // new value

Passing nIndex with GCL_HICON will retrieve a handle to the icon associated with the class.

More by Author

Must Read