代码改变世界

Combo box添加tooltip

2012-11-01 09:44  龙成  阅读(244)  评论(0编辑  收藏  举报

首先在对话框的头文件中加入初始化语句:private:下,加入:CToolTipCtrl    

m_Mytip;
然后在初始化对话框函数(OnInitDialog)中加入:
m_Mytip.Create(this); 
m_Mytip.AddTool( GetDlgItem(IDC_LIST), "你想要添加的提示信息" );

//IDC_BUTTON为你要添加提示信息的LISTBOX的ID
m_Mytip.SetDelayTime(200); //设置延迟
m_Mytip.SetTipTextColor( RGB(0,0,255) ); //设置提示文本的颜色
m_Mytip.SetTipBkColor( RGB(255,255,255)); //设置提示框的背景颜色
m_Mytip.Activate(TRUE); //设置是否启用提示

然后在类向导中添加PreTranslateMessage消息响应函数
BOOL CXXXDlg::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
   if(pMsg->message==WM_MOUSEMOVE /*&& pMsg->hwnd == GetDlgItem

(IDC_BUTTON1)->GetSafeHwnd())*/)
   m_Mytip.RelayEvent(pMsg);
return CDialog::PreTranslateMessage(pMsg);
}
注:如果要为多个按钮添加功能提示只需在
m_Mytip.AddTool( GetDlgItem(IDC_LIST), "你想要添加的提示信息" );
的下面再加上类似语句,如
m_Mytip.AddTool( GetDlgItem(IDC_LIST1), "你想要添加的提示信息1" );
m_Mytip.AddTool( GetDlgItem(IDC_LIST2), "你想要添加的提示信息2" );