实现如下:当鼠标放到一个控件上,就显示一个提示。
关键代码:
在头文件TipDlg.h中添加成员变量: CToolTipCtrl m_tip; 在对话框初始化中 BOOL CTipDlg::OnInitDialog() { CDialogEx::OnInitDialog(); ... // TODO: 在此添加额外的初始化代码 m_tip.Create(this); m_tip.AddTool(GetDlgItem(IDC_NUM), _T("Please add number in here.")); m_tip.AddTool(GetDlgItem(IDC_NAME), _T("Please input name in here.")); m_tip.AddTool(GetDlgItem(IDC_DEPT), _T("Please select department in here.")); m_tip.AddTool(GetDlgItem(IDC_ADD), _T("ADD")); m_tip.AddTool(GetDlgItem(IDC_DEL), _T("DELETE")); m_tip.AddTool(GetDlgItem(IDC_MOD), _T("MODIFY")); m_tip.AddTool(GetDlgItem(IDC_LIST), _T("The information of employee.")); m_tip.Activate(TRUE); m_list.InsertColumn(0, _T("Number"), 0, 100); m_list.InsertColumn(1, _T("Name"), 0, 120); m_list.InsertColumn(2, _T("Department"), 0, 120); m_list.SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES); LPCTSTR szDept[] = { _T("Human Resource"), _T("Reserch & Development"), _T("Finance"), _T("Testing") }; int n = sizeof(szDept) / sizeof(szDept[0]); CComboBox* pComb = (CComboBox*)GetDlgItem(IDC_DEPT); for (int i = 0; i < n; ++i) pComb->AddString(szDept[i]); return TRUE; // 除非将焦点设置到控件,否则返回 TRUE } 3. 添加一个虚函数 PreTranslateMessage BOOL CTipDlg::PreTranslateMessage(MSG* pMsg) { // TODO: 在此添加专用代码和/或调用基类 m_tip.RelayEvent(pMsg);//将鼠标消息传递给ToolTip控件进行处理。 return CDialogEx::PreTranslateMessage(pMsg); }