在VC中,也常常爲一些圖片按鈕添加一些功能提示。
下面講解實現過程:
該功能的實現主要是用CToolTipCtrl類。該類在VC msdn中有詳細說明。
首先在對話框的頭文件中加入初始化語句:public:下,加入:CToolTipCtrl m_Mytip;
然後在初始化對話框函數中加入:
m_Mytip.Create(this);
m_Mytip.AddTool( GetDlgItem(IDC_BUTTON), "你想要添加的提示信息" ); //IDC_BUTTON爲你要添加提示信息的按鈕的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)
m_Mytip.RelayEvent(pMsg);
return CDialog::PreTranslateMessage(pMsg);
}
注:如果要爲多個按鈕添加功能提示只需在
m_Mytip.AddTool( GetDlgItem(IDC_BUTTON), "你想要添加的提示信息" );
的下面再加上類似語句,如
m_Mytip.AddTool( GetDlgItem(IDC_BUTTON1), "你想要添加的提示信息1" );
m_Mytip.AddTool( GetDlgItem(IDC_BUTTON2), "你想要添加的提示信息2" );
。。。。。。。。