建议使用CToolTipCtrl对象

例如:

 

1.在对画框类(CTooltipDlg.cpp)中声明:

CToolTipCtrl m_ToolTipCtrl;

 

2.在对画框类(CTooltipDlg.cpp)初始化方法OnInitDialog()中初始化:

m_ToolTipCtrl.Create(this);
m_ToolTipCtrl.AddTool(GetDlgItem(IDC_BUTTON_CLOSE), _T("This is a test tooltip"));
m_ToolTipCtrl.SetMaxTipWidth(300);
m_ToolTipCtrl.Activate(TRUE);

 

3.在头文件(CTooltipDlg.h)的构造函数中声明方法:

BOOL PreTranslateMessage(MSG* pMsg);

 

4. 在对画框类(CTooltipDlg.cpp)中添加virtual BOOL PreTranslateMessage(MSG* pMsg)方法并实现如下:

BOOL CTooltipDlg::PreTranslateMessage(MSG* pMsg)
{
    ASSERT(pMsg != NULL);
    if (pMsg->message == WM_MOUSEMOVE || pMsg->message == WM_LBUTTONDOWN || pMsg->message == WM_LBUTTONUP)
    m_ToolTipCtrl.RelayEvent(pMsg);
    return CDialogEx::PreTranslateMessage(pMsg);
}

 

运行后,鼠标移动到按钮上,即显示出ToolTip了,如下图所示结果。

 

Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐