在使用MFC时,想要在鼠标停在按钮上时,显示文字提示信息,这篇博客主要给出实现这部分功能的代码。
首先在头文件中添加CToolTipCtrl类型的控件变量:
CToolTipCtrl m_toolTip;
在对话框初始化时候添加信息显示的初始化代码:
EnableToolTips();
m_toolTip.Create(this);
m_toolTip.Activate(true);
m_toolTip.SetDelayTime(150);
m_toolTip.SetTipTextColor(RGB(0, 0, 255));
m_toolTip.SetTipBkColor(RGB(255, 255, 255));
m_toolTip.AddTool(GetDlgItem(IDC_BUTTON3), _T("Start Algorithm"));
m_toolTip.AddTool(GetDlgItem(IDC_BUTTON4), _T("Pause Algorithm"));
然后再添加PreTranslateMessage消息,然后添加如下代码:
BOOL CRVAFGUIDlg::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
if (pMsg->message == WM_MOUSEMOVE){
m_toolTip.RelayEvent(pMsg);
}
return CDialogEx::PreTranslateMessage(pMsg);
}