CodeGuru
Earthweb Search
Forums Wireless Jars Gamelan Developer.com
CodeGuru Navigation
RSS Feeds

RSSAll

RSSVC++/C++

RSS.NET/C#

RSSVB

See more EarthWeb Network feeds

follow us on Twitter

Member Sign In
User ID:
Password:
Remember Me:
Forgot Password?
Not a member?
Click here for more information and to register.

Become a Marketplace Partner

jobs.internet.com

internet.commerce
Partners & Affiliates
















Home >> Visual C++ / C++ >> Controls >> Other Controls >> Tooltip controls


Adding Tooltip to any control in your Dialog (multiline)
Rating:

Ferdinand V. Abne (view profile)
August 12, 1998

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!

(continued)




Download demo project - 58 KB

Download source - 3.4 KB

Tools:
Add www.codeguru.com to your favorites
Add www.codeguru.com to your browser search box
IE 7 | Firefox 2.0 | Firefox 1.5.x
Receive news via our XML/RSS feed







RATE THIS ARTICLE:   Excellent  Very Good  Average  Below Average  Poor  

(You must be signed in to rank an article. Not a member? Click here to register)

Latest Comments:
How we can Add MFECToolTip.h and MFECToolTip.cpp in our project ? - Legacy CodeGuru (01/02/2003)
Use the MFC Tooltip Control, it works much simpler. - Legacy CodeGuru (09/18/2002)
it swallows resources - Legacy CodeGuru (08/05/2002)
Well - Legacy CodeGuru (10/19/2001)
How about propertypages - Legacy CodeGuru (07/27/2000)

View All Comments
Add a Comment:
Title:
Comment:
Pre-Formatted: Check this if you want the text to display with the formatting as typed (good for source code)



(You must be signed in to comment on an article. Not a member? Click here to register)