CToolTipCtrl - Showing Tool Tips on controls

   CToolTipCtrl can be used to attach tool tips for controls. The tool tips can be placed on any controls using AddTool(), a member function of CToolTipCtrl. This article explains how to show Tool Tips for a command button which is placed on a dialog box.

   Tool tips are shown in a round rectangle adjacent to the controls. They are shown when the Mouse cursor is placed on the control.

Tool tips on a dialog - CToolTipCtrl:

  • Create a new Dialog based MFC Application. The article assumes the application name as  MFCSample.
  • In the MFCSampleDlg.h file, add a member variable for CToolTipCtrl inside CMFCSampleDlg class as follows.

CToolTipCtrl *m_ToolTip;

  • Add a Command Button to the dialog box. Create a member variable for the button as m_TESTBUTTON.
  • In the OnInitDialog function of the CMFCSampleDlg class ( MFCSampleDlg.cpp) add the following code.

m_ToolTip= new CToolTipCtrl();
m_ToolTip->Create(this);

m_ToolTip->AddTool(&
m_TESTBUTTON,"Test Button");

m_ToolTip->Activate(TRUE);


  • The above code adds a tool tip for the command button. If the mouse cursor is placed on the button, it shows a tool tip as "Test Button".
  • More controls can be added with the tool tip as above.
  • The following version of PreTranslateMessage should be placed in MFCSampleDlg.cpp, to override the default one.

BOOL CMFCSampleDlg::PreTranslateMessage(MSG* pMsg)
{
    // TODO: Add your specialized code here and/or call the base class

    if(m_ToolTip != NULL)
       m_ToolTip->RelayEvent(pMsg);

    return CDialog::PreTranslateMessage(pMsg);
}


   The above pretranslatemessage version, ensures that Windows gets the notifications required for the Tool tips.

   The above program creates the CToolTipCtrl variable using the new operator. So the memory should be freed at the end of the program by using the delete operator. 

Close    To Top
  • Prev Article-Programming:
  • Next Article-Programming:
  • Now: Tutorial for Web and Software Design > Programming > c > Programming Content
    Photoshop Tutorial
     

    Special Effect

      3D Effect
      Photoshop Articles
    Programming Tutorial
     

    C/C++ Tutorial

      Visual Basic
      C# Tutorial
    Database Tutorial
     

    MySQL Tutorial

      MS SQL Tutorial
      Oracle Tutorial
    Geek Tutorial
     

    Blogging Tutorial

      RSS Tutorial
      Podcasting Tutorial
    Graphic Design Tutorial
      Coreldraw Tutorial
      Illustrator Tutorial
      3D Tutorials
    Webmaster Articles
     

    Domain Service

      Web Hosting
      Site Promotion
    Java Tutorial/ Articles
     

    Java Servlets

      JavaEE Tutorial
     

    JavaBeans Tutorial

    XML Tutorial/ Articles
     

    XML Style

      AJAX Tutorial
      XML Mobile
    Flash Tutorial/ Articles
     

    Flash Video

      Action Script
      Flash Articles
    OS Tutorial/ Articles
      Linux Tutorial
      Symbian Tutorial
      MacOS Tutorial
    Personal Tech
      Hardware Tutorial
      Software Tutorial
      Online Auction