Muokkaa

Jaa


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.

For more detail see the source code located in the VC\atlmfc\src\mfc folder of your Visual Studio installation.

Syntax

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

CMFCToolTipCtrl::CMFCToolTipCtrl

CMFCToolTipCtrl(CMFCToolTipInfo* pParams = NULL);

Parameters

[in] pParams

Remarks

CMFCToolTipCtrl::GetIconSize

Returns the size of an icon in a tooltip.

virtual CSize GetIconSize();

Return Value

The size of the icon, in pixels.

CMFCToolTipCtrl::GetParams

Returns the display settings of a tooltip.

const CMFCToolTipInfo& GetParams() const;

Return Value

The current tooltip display settings, which are stored in a CMFCToolTipInfo Class object.

CMFCToolTipCtrl::OnDrawBorder

Draws the border of a tooltip.

virtual void OnDrawBorder(
    CDC* pDC,
    CRect rect,
    COLORREF clrLine);

Parameters

pDC
[in] Pointer to a device context.

rect
[in] The bounding rectangle of the tooltip.

clrLine
[in] Border color.

Remarks

Override this method in a derived class to customize the appearance of the tooltip border.

CMFCToolTipCtrl::OnDrawDescription

virtual CSize OnDrawDescription(
    CDC* pDC,
    CRect rect,
    BOOL bCalcOnly);

Parameters

[in] pDC
[in] rect
[in] bCalcOnly

Return Value

Remarks

CMFCToolTipCtrl::OnDrawIcon

Displays an icon in a tooltip.

virtual BOOL OnDrawIcon(
    CDC* pDC,
    CRect rectImage);

Parameters

pDC
[in] A pointer to a device context.

rectImage
[in] Coordinates of the icon.

Return Value

TRUE if the icon was drawn. Otherwise FALSE.

Remarks

Override this method in a derived class to display a custom icon. You must also override CMFCToolTipCtrl::GetIconSize to enable the tooltip to correctly calculate the layout of text and description.

CMFCToolTipCtrl::OnDrawLabel

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

virtual CSize OnDrawLabel(
    CDC* pDC,
    CRect rect,
    BOOL bCalcOnly);

Parameters

pDC
[in] A pointer to a device context.

rect
[in] Bounding rectangle of the label area.

bCalcOnly
[in] If TRUE, the label will not be drawn.

Return Value

Size of the label, in pixels.

Remarks

Override this method in a derived class if you want to customize the appearance of the tooltip label.

CMFCToolTipCtrl::OnDrawSeparator

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

virtual void OnDrawSeparator(
    CDC* pDC,
    int x1,
    int x2,
    int y);

Parameters

pDC
[in] A pointer to a device context.

x1
[in] Horizontal coordinate of the left end of the separator.

x2
[in] Horizontal coordinate of the right end of the separator.

Y
[in] Vertical coordinate of the separator.

Remarks

The default implementation draws a line from the point (x1, y) to the point (x2, y).

Override this method in a derived class to customize the appearance of the separator.

CMFCToolTipCtrl::OnFillBackground

Fills the tooltip background.

virtual void OnFillBackground(
    CDC* pDC,
    CRect rect,
    COLORREF& clrText,
    COLORREF& clrLine);

Parameters

pDC
[in] A pointer to a device context.

rect
[in] Specifies the bounding rectangle of the area to fill.

clrText
[in] Tooltip foreground color.

clrLine
[in] Color of borders and the delimiter line between label and description.

Remarks

The default implementation fills the rectangle that is specified by rect with the color or pattern specified by the most recent call to CMFCToolTipCtrl::SetParams.

Override this method in a derived class if you want to customize the appearance of the tooltip.

CMFCToolTipCtrl::SetDescription

Sets the description to be displayed by the tooltip.

virtual void SetDescription(const CString strDesrciption);

Parameters

strDesrciption
[in] Description text.

Remarks

The description text is displayed on the tooltip under the separator.

CMFCToolTipCtrl::SetFixedWidth

void SetFixedWidth(
    int nWidthRegular,
    int nWidthLargeImage);

Parameters

[in] nWidthRegular
[in] nWidthLargeImage

Remarks

CMFCToolTipCtrl::SetHotRibbonButton

void SetHotRibbonButton(CMFCRibbonButton* pRibbonButton);

Parameters

[in] pRibbonButton

Remarks

CMFCToolTipCtrl::SetLocation

void SetLocation(CPoint pt);

Parameters

[in] pt

Remarks

CMFCToolTipCtrl::SetParams

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

void SetParams(CMFCToolTipInfo* pParams);

Parameters

pParams
[in] Pointer to a CMFCToolTipInfo Class object that contains the display parameters.

Remarks

Whenever the tooltip is displayed, it is drawn by using the colors and visual styles that pParams specifies. The value of pParams is stored in the protected member m_Params, which can be accessed by a derived class that overrides CMFCToolTipCtrl::OnDrawBorder, CMFCToolTipCtrl::OnDrawIcon, CMFCToolTipCtrl::OnDrawLabel, CMFCToolTipCtrl::OnDrawSeparator, or CMFCToolTipCtrl::OnFillBackground to maintain the specified appearance.

See also

Hierarchy Chart
Classes
CToolTipCtrl Class
CTooltipManager Class
CMFCToolTipInfo Class
CWinAppEx Class