Tutorial - Write Icon in the Taskbar Window


Application Security Testing: An Integral Part of DevOps

Environment: VC6 SP4, W9x, NT 4

This simple program code show how to write or remove an icon from the window taskbar and add a tool tip text. It also show how you can define a user message for trap events generate with mouse action (click on the icon). The sample application is an MFC exe dialog based program.

The routine for write and remove icon:

void CWriteTaskBarDlg::OnWrite() 
  // handle to icon
     HICON hIcon;
  // text for tool tip
     char lpszTip[] = "Mouse is on the Icon !!";

     HINSTANCE hInst =
     hIcon = (HICON)LoadImage( hInst,
  // set NOTIFYCONDATA structure


     tnid.cbSize = sizeof(NOTIFYICONDATA);
     tnid.hWnd = m_hWnd;
     tnid.uID = IDI_ICON1;
     tnid.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP;
     tnid.uCallbackMessage = WM_TASKBAR; // my user message
     tnid.hIcon = hIcon;

     if (lpszTip)
        lstrcpyn(tnid.szTip, lpszTip, sizeof(tnid.szTip));
        tnid.szTip[0] = '\0';

  // call to Shell_NotifyIcon with NIM_ADD parameter

     Shell_NotifyIcon(NIM_ADD, &tnid);
  // free icon 

     if (hIcon) 

For remove icon:

void CWriteTaskBarDlg::OnRemove() 

  // for remove, only provide cbSize, hWnd and uID!


    tnid.cbSize = sizeof(NOTIFYICONDATA); 
    tnid.hWnd = m_hWnd; 
    tnid.uID = IDI_ICON1; 

  // call to Shell_NotifyIcon with NIM_DEL parameter

    Shell_NotifyIcon(NIM_DELETE, &tnid); 

For Mouse Message:

LRESULT  CWriteTaskBarDlg::OnTaskbar(WPARAM wParam, 
                                     LPARAM lParam)
    UINT uMouseMsg = (UINT) lParam;

    switch (uMouseMsg)

     case WM_LBUTTONDOWN: 
               AfxMessageBox("Mouse click on the Icon !");

     default:  break;

  return 0;


Download source - 34 Kb


  • Actually...

    Posted by grahamr (work) on 10/03/2006 04:59am

    ...it's not taskbar or traybar, but SystemTray as most of the literature I've read calls it.

  • Generating a mouse click

    Posted by Legacy on 11/02/2003 12:00am

    Originally posted by: Seth D.


    I'm trying to find a simple code(visual C++)
    that will generate a mouse click in a specific area(like clicking on the Start menu).



  • Nope, it's taskbar and not traybar.

    Posted by Legacy on 05/26/2002 12:00am

    Originally posted by: Zack

    Search for Shell_NotifyIcon in the MSDN docs and check out the following in the remarks sections.

    The taskbar notification area is sometimes erroneously called the "tray."

    I couldn't find a "Tray bar" options in Windows. However, when I hide the taskbar in windows, the so called "tray bar" disappears along with it. I guess that would mean that this "tray bar" is apart of the taskbar?

    However, it seems that "Traybar" is a popular term for the task bar notification area. The term was probably coined by a marketing department at some company that is now out of business.

    Calling someone an idiot for using the proper terminology is well... Do your research first.

  • Dammit it's not the taskbar it's the tray bar!!

    Posted by Legacy on 02/08/2002 12:00am

    Originally posted by: DaaZ

    No wonder I can't find anything about hiding a window from the taskbar! There are countless morons who write stuff about adding/removing an icon from the taskbar but who, like our idiot here,are actually talking about the FUCKING TRAY BAR!!!

    Dammit it's not that complicated!

  • Good One, But..

    Posted by Legacy on 11/06/2001 12:00am

    Originally posted by: Praveen Dandu

    It's a good one..but the exactly same example has been provided in the MSDN itself..

  • reply

    Posted by Legacy on 11/05/2001 12:00am

    Originally posted by: Erwan


  • Someone had wrote a class for this: CTrayIcon

    Posted by Legacy on 11/03/2001 12:00am

    Originally posted by: DaFu Chen

    Someone had wrote a class for this situation, the class is named CTrayIcon.

  • Better tutorial @ http://www.maxcode.com/

    Posted by Legacy on 11/02/2001 12:00am

    Originally posted by: clemens

    check the BETTER tutorial @MAXcode

  • You must have javascript enabled in order to post comments.

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • As all sorts of data becomes available for storage, analysis and retrieval - so called 'Big Data' - there are potentially huge benefits, but equally huge challenges...
  • The agile organization needs knowledge to act on, quickly and effectively. Though many organizations are clamouring for "Big Data", not nearly as many know what to do with it...
  • Cloud-based integration solutions can be confusing. Adding to the confusion are the multiple ways IT departments can deliver such integration...

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date
We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.