Click here to Skip to main content
Click here to Skip to main content

Windows balloon tool tip and the taskbar notification area

, 14 Sep 2003
Rate this:
Please Sign up or sign in to vote.
Dealing with balloon tool tips and taskbar notification area

Introduction

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

Background

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 );
  }

...//etc
}
/////
It is done with the MS Windows balloon tool tip. Over Smile | :)

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 Smile | :) Good luck! Liviu Birjega

License

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

Share

About the Author

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

Comments and Discussions

 
GeneralMy vote of 5 PinmemberTAKS_898-May-13 20:33 
GeneralThank you! It's useful! Pinmembertimyau20-Jan-11 17:35 
GeneralTTS_BALLON Pinmemberrahulbaisla12-Mar-08 20:17 
GeneralRe: TTS_BALLON Pinmembersashoalm4-Jun-09 5:13 
GeneralGood but.... Pinmemberaligisan19-Jan-07 6:32 
GeneralTTS_BALLOON Pinmemberd34c0n24-Jun-06 14:47 
GeneralRe: TTS_BALLOON PinmemberYogesh P. Dhakad24-Aug-06 2:37 
GeneralRe: TTS_BALLOON Pinmemberbob1697214-Sep-06 11:19 
QuestionHow to get the notification or message when I click any where in balloon tool tip except close button and text with underline Pinmemberwangdaoming22-Jun-06 22:45 
QuestionBalloon ToolTips with CEdit PinmemberCold-Fire4-Dec-05 4:18 
GeneralFunction to Create Tooltip PinsussAnonymous1-Oct-05 14:20 
GeneralThe same thing... but for all platforme Pinmemberdesch19-Jul-05 2:42 
Generalhandling WM_LBUTTONDOWN from the balloon Pinmemberscvarz11-Mar-05 0:54 
Generaluser icon on balloon tooltip PinmemberG.A.26-Jan-05 4:47 
GeneralRe: user icon on balloon tooltip PinsussAnonymous1-Oct-05 14:14 
GeneralRe: user icon on balloon tooltip PinmemberIgnorance25-Oct-05 21:18 
GeneralRe: user icon on balloon tooltip PinmembertHeWiZaRdOfDoS10-Mar-07 12:31 
GeneralBaloon Tips in CStatic PinmemberAntonio Dias23-Dec-04 0:47 
GeneralMore Ballons! Pinmembershady34129-Jan-04 13:29 
GeneralBalloon doesn't exit Pinmemberkrani19-Jan-04 14:26 
QuestionHow can I add a close button? Pinmemberhiroki watanabe25-Sep-03 22:31 
AnswerRe: How can I add a close button? PinsussAnonymous26-Sep-03 6:46 
QuestionRe: How can I add a close button? Pinmembersemanti24-Aug-07 10:48 
AnswerRe: How can I add a close button? PinmemberHGLR22-Apr-04 18:46 
GeneralRe: How can I add a close button? PinsussAnonymous27-May-04 12:55 
GeneralRe: How can I add a close button? PinmemberHGLR27-May-04 16:56 
GeneralRe: How can I add a close button? PinmemberÐerek Wildstar12-Dec-11 2:46 
GeneralTTM_SETTITLE undeclared PinmemberPaddy47821-Sep-03 16:38 
GeneralRe: TTM_SETTITLE undeclared PinsitebuilderMichael Dunn21-Sep-03 17:12 
GeneralToo much easy... PinmemberKochise15-Sep-03 2:59 
GeneralRe: Too much easy... PinmemberLiviu Birjega16-Sep-03 3:31 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.141220.1 | Last Updated 15 Sep 2003
Article Copyright 2003 by Liviu Birjega
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid