1. 对话框所属类C**Dlg类中添加CToolTipCtrl变量: CToolTipCtrl m_CtrlInfo;
2. 初始化 BOOL C**Dlg::OnInitDialog()中绑定要提示信息的控件,以及设定提示信息的延时时间和背景颜色等; m_CtrlInfo.Create(this); m_CtrlInfo.AddTool(((CButton*) GetDlgItem(IDC_BUTTON_MOVEMOUSE)), _T("提示信息!")); m_CtrlInfo.SetDelayTime(100); m_CtrlInfo.SetTipTextColor(RGB(255, 0, 0)); m_CtrlInfo.SetTipBkColor(RGB(255, 255, 255)); m_CtrlInfo.Activate(TRUE);
3. C**Dlg类中添加函数 BOOL C**Dlg::PreTranslateMessage(MSG* pMSG) { // TODO: Add your specialized code here and/or call the base class if (pMSG->message == WM_MOUSEMOVE) m_CtrlInfo.RelayEvent(pMSG); return CDialog::PreTranslateMessage(pMSG); }
编译运行,结果如下图所示。