Adding Tooltip to any control in your Dialog (multiline)

Wednesday Aug 12th 1998 by Ferdinand V. Abne

Adding Tooltip to any control in your Dialog (multiline)

This class helps the user in adding tooltip to any control in the dialog. Tooltip information can be more than one line.
  1. Add MFECToolTip.h and MFECToolTip.cpp in your project
  2. In OnInitDialog, call the Create function and add the tooltip information to any control you would like to have.

    For example:
    In SampleDlg.h add a variable

               MFECToolTip m_toolTip;

    In SampleDlg.cpp
                m_toolTip.Create( this );    // after creating, add the information
                m_toolTip.AddControlInfo( contol_ID, information, background_color, text_color );
                // control ID is of type UINT
                // information is of type CStringArray.
                // background_color and text_color are optional
  3. Override the dialog's PreTranslateMessage to handle mouse movement.
    BOOL CToolTipExDlg::PreTranslateMessage( MSG *pMsg )
            if( pMsg->message == WM_MOUSEMOVE )
                    POINT pt = pMsg->pt;    
                    ScreenToClient( &pt );
                    // this is the only function to call
                    m_toolTip.ShowToolTip( (CPoint)pt );
            return CDialog::PreTranslateMessage(pMsg);
  4. explicitly show the tooltip in a particular control, call ShowToolTip( controlID ) with control ID as parameter. Make sure you call AddControlInfo() to add information for this control, otherwise no tooltip is displayed.
  5. Delete or remove the existing tooltip information, call RemoveControlInfo( controlID ) and pass the control ID. If not found nothing happens.
  6. So, you can add and remove tooltip at runtime. Try!

Download demo project - 58 KB

Download source - 3.4 KB

Mobile Site | Full Site