title | description | ms.date | f1_keywords | helpviewer_keywords | ||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
CMFCToolTipCtrl Class |
Learn more about: CMFCToolTipCtrl Class |
11/04/2016 |
|
|
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.
class CMFCToolTipCtrl : public CToolTipCtrl
Name | Description |
---|---|
CMFCToolTipCtrl::CMFCToolTipCtrl |
Default constructor. |
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. |
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:
-
Use the CWinAppEx Class method to initialize the tooltip manager in your application.
-
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); }
-
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), ¶ms);
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);
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.
[!code-cppNVC_MFC_RibbonApp#41]
Header: afxtooltipctrl.h
CMFCToolTipCtrl(CMFCToolTipInfo* pParams = NULL);
[in] pParams
Returns the size of an icon in a tooltip.
virtual CSize GetIconSize();
The size of the icon, in pixels.
Returns the display settings of a tooltip.
const CMFCToolTipInfo& GetParams() const;
The current tooltip display settings, which are stored in a CMFCToolTipInfo Class object.
Draws the border of a tooltip.
virtual void OnDrawBorder(
CDC* pDC,
CRect rect,
COLORREF clrLine);
pDC
[in] Pointer to a device context.
rect
[in] The bounding rectangle of the tooltip.
clrLine
[in] Border color.
Override this method in a derived class to customize the appearance of the tooltip border.
virtual CSize OnDrawDescription(
CDC* pDC,
CRect rect,
BOOL bCalcOnly);
[in] pDC
[in] rect
[in] bCalcOnly
Displays an icon in a tooltip.
virtual BOOL OnDrawIcon(
CDC* pDC,
CRect rectImage);
pDC
[in] A pointer to a device context.
rectImage
[in] Coordinates of the icon.
TRUE if the icon was drawn. Otherwise FALSE.
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.
Draws the label of a tooltip, or calculates the size of the label.
virtual CSize OnDrawLabel(
CDC* pDC,
CRect rect,
BOOL bCalcOnly);
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.
Size of the label, in pixels.
Override this method in a derived class if you want to customize the appearance of the tooltip label.
Draws the separator between the label and the description in a tooltip.
virtual void OnDrawSeparator(
CDC* pDC,
int x1,
int x2,
int y);
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.
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.
Fills the tooltip background.
virtual void OnFillBackground(
CDC* pDC,
CRect rect,
COLORREF& clrText,
COLORREF& clrLine);
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.
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.
Sets the description to be displayed by the tooltip.
virtual void SetDescription(const CString strDesrciption);
strDesrciption
[in] Description text.
The description text is displayed on the tooltip under the separator.
void SetFixedWidth(
int nWidthRegular,
int nWidthLargeImage);
[in] nWidthRegular
[in] nWidthLargeImage
void SetHotRibbonButton(CMFCRibbonButton* pRibbonButton);
[in] pRibbonButton
void SetLocation(CPoint pt);
[in] pt
Specifies the visual appearance of a tooltip by using a CMFCToolTipInfo Class object.
void SetParams(CMFCToolTipInfo* pParams);
pParams
[in] Pointer to a CMFCToolTipInfo Class object that contains the display parameters.
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.
Hierarchy Chart
Classes
CToolTipCtrl Class
CTooltipManager Class
CMFCToolTipInfo Class
CWinAppEx Class