MFC添加鼠标移动到控件上时的提示信息

首先在对话框的头文件中加入初始化语句: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)
{
   if(pMsg->message==WM_MOUSEMOVE )
   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" )


转:https://blog.csdn.net/smtrobot/article/details/51205642

猜你喜欢

转载自blog.csdn.net/eric_e/article/details/80650088