MFC Quick Start Guide (Part 6): ToolTip

  1. Add a member variable in MFC101Dlg.h

    CToolTipCtrl  m_ToolTip;
    


    (Fig. 6.1: Member variable)
  2. Add a member function:

    virtual  BOOL  PreTranslateMessage(MSG* pMsg);
    


    (Fig. 6.2: Member function declaration)
  3. Inside MFC101Dlg.cpp, add the function code:

    BOOL  CMFC101Dlg::PreTranslateMessage(MSG* pMsg)
    {
         m_ToolTip.RelayEvent(pMsg);
    
         return CDialog::PreTranslateLessaage(pMsg);
    }
    


    (Fig. 6.3: Code)
  4. Go back to OnInitDialog(), and initialize the tooltip:

    if (!m_ToolTip.Create(this))
    {
         TRACE("Unable to create the ToolTip!");
    }
    else
    {
         m_ToolTip.AddTool((CButton *) GetDlgItem (IDC_BUTTON1);
              _T("Adjust the three bars to control th text background color."));
    
         m_ToolTip.Activate(TRUE);
    }
    



    (Fig. 6.4: Initialization)


Build & Run

  1. Press Ctrl+shift+B to build the solution
  2. Press Ctrl+F5 to run (without debugging).
  3. Move your mouse cursor over the button and see what happen.

    (Fig. 6.5: Sample Output)

MFC Quick Start Guide (Part 6): ToolTip MFC Quick Start Guide (Part 6): ToolTip Reviewed by Kevin Lai on 12:43:00 AM Rating: 5

No comments:

Powered by Blogger.