给对话框添加一个CToolTipCtrl类型的变量tip,然后在做下面修改: BOOL CAboutDlg::OnInitDialog() { CDialog::OnInitDialog(); tip.Create(this); tip.AddTool(GetDlgItem(IDC_xxx),"tip_text"); //IDC_xxx是你想加tip的控件ID tip.AddTool(GetDlgItem(IDC_yyy),"tip_text"); return TRUE; }BOOL CAboutDlg::PreTranslateMessage(MSG* pMsg) { // TODO: Add your specialized code here and/or call the base class tip.RelayEvent(pMsg); return CDialog::PreTranslateMessage(pMsg); } 如果要给静态文本加tip,要在编辑的时候选中static控件的notify属性,并修改它的默认ID。
定义一个全局变量 CToolTipCtrl m_tooltip; 在程序初始化中加入: m_tooltip.Create(this); m_tooltip.AddTool((CButton *)GetDlgItem(IDC_BUTTON2),"this is a tooltip");响应BOOL CYourDlg::PreTranslateMessage(MSG* pMsg) { // TODO: Add your specialized code here and/or call the base class
switch(pMsg->message) { case WM_MOUSEMOVE: m_tooltip.RelayEvent(pMsg); } return CDialog::PreTranslateMessage(pMsg); } 这样就可以了
AddToolTip()
Active()
Relay
AddToolTip的时候设置对了就行
TOOLINFO
.uFlag = TTF_IDISHWND
.uid = (INT_PTR)GetDlgItem(...)->m_hWnd
BOOL CAboutDlg::OnInitDialog()
{
CDialog::OnInitDialog();
tip.Create(this);
tip.AddTool(GetDlgItem(IDC_xxx),"tip_text"); //IDC_xxx是你想加tip的控件ID
tip.AddTool(GetDlgItem(IDC_yyy),"tip_text");
return TRUE;
}BOOL CAboutDlg::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
tip.RelayEvent(pMsg);
return CDialog::PreTranslateMessage(pMsg);
}
如果要给静态文本加tip,要在编辑的时候选中static控件的notify属性,并修改它的默认ID。
在程序初始化中加入:
m_tooltip.Create(this);
m_tooltip.AddTool((CButton *)GetDlgItem(IDC_BUTTON2),"this is a tooltip");响应BOOL CYourDlg::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
switch(pMsg->message)
{
case WM_MOUSEMOVE:
m_tooltip.RelayEvent(pMsg); }
return CDialog::PreTranslateMessage(pMsg);
}
这样就可以了