Adding Tooltip to any control in your Dialog (multiline) | CodeGuru

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. Add MFECToolTip.h and MFECToolTip.cpp in your project 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 […]

Written By
CodeGuru Staff
CodeGuru Staff
Aug 12, 1998
1 minute read
CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More

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

           SampleDlg::OnInitDialog()
            {
                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

CodeGuru Logo

CodeGuru covers topics related to Microsoft-related software development, mobile development, database management, and web application programming. In addition to tutorials and how-tos that teach programmers how to code in Microsoft-related languages and frameworks like C# and .Net, we also publish articles on software development tools, the latest in developer news, and advice for project managers. Cloud services such as Microsoft Azure and database options including SQL Server and MSSQL are also frequently covered.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.