Compartilhar via


CMFCToolTipCtrl Class

An extended tooltip implementation based on the CToolTipCtrl Class. A tooltip based on the CMFCToolTipCtrl class can display an icon, a label, and a description. You can customize its visual appearance by using a gradient fill, custom text and border colors, bold text, rounded corners, or a balloon style.

class CMFCToolTipCtrl : public CToolTipCtrl

Members

Public Constructors

Name

Description

CMFCToolTipCtrl::CMFCToolTipCtrl

Default constructor.

Public Methods

Name

Description

CMFCToolTipCtrl::GetIconSize

Returns the size of an icon in a tooltip.

CMFCToolTipCtrl::GetParams

Returns the display settings of a tooltip.

CMFCToolTipCtrl::OnDrawBorder

Draws the border of a tooltip.

CMFCToolTipCtrl::OnDrawDescription

 

CMFCToolTipCtrl::OnDrawIcon

Displays an icon in a tooltip.

CMFCToolTipCtrl::OnDrawLabel

Draws the label of a tooltip, or calculates the size of the label.

CMFCToolTipCtrl::OnDrawSeparator

Draws the separator between the label and the description in a tooltip.

CMFCToolTipCtrl::OnFillBackground

Fills the tooltip background.

CMFCToolTipCtrl::SetDescription

Sets the description to be displayed by the tooltip.

CMFCToolTipCtrl::SetFixedWidth

 

CMFCToolTipCtrl::SetHotRibbonButton

 

CMFCToolTipCtrl::SetLocation

 

CMFCToolTipCtrl::SetParams

Specifies the visual appearance of a tooltip by using a CMFCToolTipInfo object.

Remarks

Use CMFCToolTipCtrl, CMFCToolTipInfo, and CTooltipManager Class objects together to implement customized tooltips in your application.

For example, to use balloon-style tooltips, follow these steps:

1. Use the CWinAppEx Class method to initialize the tooltip manager in your application.

2. Create a CMFCToolTipInfo structure to specify the visual style that you want:

CMFCToolTipInfo params;
 params.m_bBoldLabel = FALSE;
 params.m_bDrawDescription = FALSE;
 params.m_bDrawIcon = FALSE;
 params.m_bRoundedCorners = TRUE;
 params.m_bDrawSeparator = FALSE;
 if (m_bCustomColors)
 {
  params.m_clrFill = RGB (255, 255, 255);
  params.m_clrFillGradient = RGB (228, 228, 240);
  params.m_clrText = RGB (61, 83, 80);
  params.m_clrBorder = RGB (144, 149, 168);
 }

3. Use the CTooltipManager::SetTooltipParams method to set the visual style for all tooltips in the application by using the styles defined in the CMFCToolTipInfo object:

theApp.GetTooltipManager ()->SetTooltipParams (AFX_TOOLTIP_TYPE_ALL,
    RUNTIME_CLASS (CMFCToolTipCtrl), &params);

You can also derive a new class from CMFCToolTipCtrl to control tooltip behavior and rendering. To specify a new tooltip control class, use the CTooltipManager::SetTooltipParams method:

myApp.GetTooltipManager ()->SetTooltipParams (AFX_TOOLTIP_TYPE_ALL,
    RUNTIME_CLASS (CMyToolTipCtrl))

To restore the default tooltip control class and reset the tooltip appearance to its default state, specify NULL in the runtime class and tooltip info parameters of SetTooltipParams:

theApp.GetTooltipManager ()->SetTooltipParams (AFX_TOOLTIP_TYPE_ALL,
    NULL, NULL);

Example

The following example demonstrates how to construct a CMFCToolTipCtrl object, set the description that the tooltip displays, and set the width of the tooltip control.

    CMFCToolTipInfo* params = new CMFCToolTipInfo();
    
    params->m_bBoldLabel = FALSE;
    params->m_bDrawDescription = FALSE;
    params->m_bDrawIcon = FALSE;
    params->m_bRoundedCorners = TRUE;
    params->m_bDrawSeparator = FALSE;
    params->m_clrFill = RGB (255, 255, 255);
    params->m_clrFillGradient = RGB (228, 228, 240);
    params->m_clrText = RGB (61, 83, 80);
    params->m_clrBorder = RGB (144, 149, 168);

    CMFCToolTipCtrl* tipCtrl = new CMFCToolTipCtrl(params);
    tipCtrl->SetDescription(_T("tool tip control"));
    tipCtrl->SetFixedWidth(100,150);

Inheritance Hierarchy

CObject

   CCmdTarget

      CWnd

         CToolTipCtrl

            CMFCToolTipCtrl

Requirements

Header: afxtooltipctrl.h

See Also

Reference

Hierarchy Chart

CToolTipCtrl Class

CTooltipManager Class

CMFCToolTipInfo Class

CWinAppEx Class

Other Resources

MFC Classes