Click here to Skip to main content
14,930,487 members
Articles / Programming Languages / C++
Posted 14 Sep 2003


98 bookmarked

Windows balloon tool tip and the taskbar notification area

Rate me:
Please Sign up or sign in to vote.
4.80/5 (33 votes)
14 Sep 20032 min read
Dealing with balloon tool tips and taskbar notification area


I will not call this an article but rather a comment to all projects that are dealing with balloon tool tips and taskbar notification area (system tray).


I want to show the easiest way to use these controls because "everybody" is complaining about the lack of information on this issue. What is true is that MSDN is not excelling in explaining how to use a balloon tool tip or how to load your application into the tray.

Using the code

My "EasyApp" application on run will display its icon into the system tray with a balloon tool tip associated just like "Local Area Connection Status" standard application. On application icon double click the main dialog will be shown and with mouse over the dialog controls we can see balloon tool tips. By clicking on "Minimize" button the application will be "minimized" into the tray where now we have a regular tool tip. The "magic" is happening inside the CEasyAppDlg object. First the _ToolTipCtrl member, which is a simple CToolTipCtrl MFC object, is initialized using Create( . ):

_ToolTipCtrl.Create( this,
           //  the ToolTip control's style
          TTS_NOPREFIX | // prevents the system from 
          // stripping the ampersand (&) 
          // character from a string
          TTS_BALLOON |  // the ToolTip control has the appearance of
          // 0x40        // a cartoon "balloon," with rounded corners
          // and a stem pointing to the item.
          TTS_ALWAYSTIP  // the ToolTip will appear when the
          // cursor is on a tool, regardless of
          // whether the ToolTip control's owner
          // window is active or inactive
(TTS_BALLOON is not part of the CToolTipCtrl::Create MSDN description!)

SetIconAndTitleForBalloonTip( . ) local member is using TTM_SETTITLE message to add a STANDARD ICON and title string to the tool tip:

BOOL CEasyAppDlg::SetIconAndTitleForBalloonTip( 
  CToolTipCtrl *pToolTipCtrl, int tti_ICON, CString title ) 
  return ::SendMessage( (HWND) pToolTipCtrl->m_hWnd,
   (UINT) TTM_SETTITLE, // adds a standard icon and 
                        // title string to a ToolTip
   (WPARAM) tti_ICON, 
   // TTI_NONE     = 0 - no icon
   // TTI_INFO     = 1 - information icon
   // TTI_WARNING  = 2 - warning icon
   // TTI_ERROR    = 3 - error icon 
   (LPARAM) (LPCTSTR) title ); 
The only thing left is to pass the mouse message to the tool tip control for processing using RelayEvent( . ):
BOOL CEasyAppDlg::PreTranslateMessage(MSG* pMsg) 
  if( pMsg->message == WM_MOUSEMOVE )
    _ToolTipCtrl.RelayEvent( pMsg );

It is done with the MS Windows balloon tool tip. Over :-)

To "load" the application into the system tray I have a local member LoadToTray( . ) that is using NOTIFYICONDATA structure, which contains information that the system needs to process taskbar status area messages, Shell_NotifyIcon( . ) to add or delete to the taskbar's status area and WM_TRAY_NOTIFY user defined message used for callback:

void CEasyAppDlg::LoadToTray( CWnd     *pWnd,
  UINT     uCallbackMessage,
  CString  sInfoTitle, // title for a balloon ToolTip.
    // This title appears in boldface above the text
    // It can have a maximum of 63 characters
  CString  sInfo, // the text for a balloon ToolTip, it can have
    // a maximum of 255 characters
  CString  sTip, // the text for a standard ToolTip.
    // It can have a maximum of 128 characters,
    // including the terminating NULL.
  int      uTimeout, // in sec.
  HICON    icon )
            ZeroMemory( &_tnd, sizeof( NOTIFYICONDATA ) );

            _tnd.cbSize = sizeof( NOTIFYICONDATA );
            _tnd.hWnd = pWnd->GetSafeHwnd();
            _tnd.uID = 0;
            _tnd.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP | NIF_INFO;
    // Flag Description:
    // - NIF_ICON       The hIcon member is valid.  
    // - NIF_MESSAGE    The uCallbackMessage member is valid. 
    // - NIF_TIP        The szTip member is valid. 
    // - NIF_STATE      The dwState and dwStateMask members are valid. 
    // - NIF_INFO       Use a balloon ToolTip instead of a standard ToolTip.
    // The szInfo, uTimeout, szInfoTitle, and 
    // dwInfoFlags members are valid. 
    // - NIF_GUID       Reserved 

            _tnd.dwInfoFlags = NIIF_INFO; 
                // add an icon to a balloon ToolTip
    // Flag Description 
    // - NIIF_ERROR     An error icon. 
    // - NIIF_INFO      An information icon. 
    // - NIIF_NONE      No icon. 
    // - NIIF_WARNING   A warning icon. 
    // - NIIF_ICON_MASK Version 6.0. Reserved. 
    // - NIIF_NOSOUND   Version 6.0. Do not play the 
    //       associated sound. Applies only to balloon ToolTips 

            _tnd.uCallbackMessage = uCallbackMessage;  
            _tnd.uTimeout = uTimeout * 1000;
            _tnd.hIcon = icon;

            strcpy( _tnd.szInfoTitle,sInfoTitle );
            strcpy( _tnd.szInfo,     sInfo      );
            strcpy( _tnd.szTip,      sTip       );

            Shell_NotifyIcon( NIM_ADD, &_tnd ); 
We just call this into OnInitDialog(). On callback function the main dialog is "restored" to the screen. Into the destructor (or on exit) we have to use Shell_NotifyIcon( NIM_DELETE, &_tnd ) to delete from the status area. That’s it. Was not that bad wasn’t it? I know that I plagiarize MSDN and I apologize :-) Good luck! Liviu Birjega


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

Liviu Birjega
Software Developer (Senior) IBI Group
Canada Canada
No Biography provided

Comments and Discussions

QuestionGetting error while compiling in VS 6.0 Pin
Member 121800432-Dec-15 20:07
MemberMember 121800432-Dec-15 20:07 
GeneralMy vote of 5 Pin
T. K. Sahoo8-May-13 19:33
MemberT. K. Sahoo8-May-13 19:33 
GeneralThank you! It's useful! Pin
timyau20-Jan-11 16:35
Membertimyau20-Jan-11 16:35 
rahulbaisla12-Mar-08 19:17
Memberrahulbaisla12-Mar-08 19:17 
GeneralRe: TTS_BALLON Pin
sashoalm4-Jun-09 4:13
Membersashoalm4-Jun-09 4:13 
GeneralGood but.... Pin
aligisan19-Jan-07 5:32
Memberaligisan19-Jan-07 5:32 
d34c0n24-Jun-06 13:47
Memberd34c0n24-Jun-06 13:47 
hi.. umm well this will only work on Window 2k and Window ME, correct me if i'm wrong Smile | :)

What are you gonna learn today?
GeneralRe: TTS_BALLOON Pin
Yogesh Dhakad24-Aug-06 1:37
MemberYogesh Dhakad24-Aug-06 1:37 
GeneralRe: TTS_BALLOON Pin
bob1697214-Sep-06 10:19
Memberbob1697214-Sep-06 10:19 
QuestionHow to get the notification or message when I click any where in balloon tool tip except close button and text with underline Pin
wangdaoming22-Jun-06 21:45
Memberwangdaoming22-Jun-06 21:45 
QuestionBalloon ToolTips with CEdit Pin
Cold-Fire4-Dec-05 3:18
MemberCold-Fire4-Dec-05 3:18 
GeneralFunction to Create Tooltip Pin
Anonymous1-Oct-05 13:20
MemberAnonymous1-Oct-05 13:20 
GeneralThe same thing... but for all platforme Pin
desch19-Jul-05 1:42
Memberdesch19-Jul-05 1:42 
Generalhandling WM_LBUTTONDOWN from the balloon Pin
scvarz10-Mar-05 23:54
Memberscvarz10-Mar-05 23:54 
Generaluser icon on balloon tooltip Pin
G.A.26-Jan-05 3:47
MemberG.A.26-Jan-05 3:47 
GeneralRe: user icon on balloon tooltip Pin
Anonymous1-Oct-05 13:14
MemberAnonymous1-Oct-05 13:14 
GeneralRe: user icon on balloon tooltip Pin
Atony Chen25-Oct-05 20:18
MemberAtony Chen25-Oct-05 20:18 
GeneralRe: user icon on balloon tooltip Pin
tHeWiZaRdOfDoS10-Mar-07 11:31
MembertHeWiZaRdOfDoS10-Mar-07 11:31 
GeneralBaloon Tips in CStatic Pin
Antonio Dias22-Dec-04 23:47
MemberAntonio Dias22-Dec-04 23:47 
GeneralMore Ballons! Pin
Member 37730629-Jan-04 12:29
MemberMember 37730629-Jan-04 12:29 
GeneralBalloon doesn't exit Pin
krani19-Jan-04 13:26
Memberkrani19-Jan-04 13:26 
QuestionHow can I add a close button? Pin
Hiroki Watanabe25-Sep-03 21:31
MemberHiroki Watanabe25-Sep-03 21:31 
AnswerRe: How can I add a close button? Pin
Anonymous26-Sep-03 5:46
MemberAnonymous26-Sep-03 5:46 
QuestionRe: How can I add a close button? Pin
semanti24-Aug-07 9:48
Membersemanti24-Aug-07 9:48 
AnswerRe: How can I add a close button? Pin
HGLR22-Apr-04 17:46
MemberHGLR22-Apr-04 17:46 

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.