MFC對話框運用程序,對話框上有多個按鈕和靜態文本框,鼠標移動到不同按鈕上時靜態文本框輸出不同字符串,這個功能怎麼實現?我剛學MFC,是個小白,希望各位大神不嫌麻煩,講詳細一點。謝謝!
1.重載PreTranslateMessage函數
2.實現如下代碼
BOOL CMouseDlg::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
if(pMsg->hwnd == GetDlgItem(IDC_BUTTON1)->GetSafeHwnd() && pMsg->message == WM_MOUSEMOVE)
{
CString windowText;
GetDlgItem(IDC_BUTTON1)->GetWindowText(windowText); //得到按鈕文本
GetDlgItem(IDC_STATIC1)->SetWindowText(windowText); //顯示到靜態文本框
}else if(pMsg->hwnd == GetDlgItem(IDC_BUTTON2)->GetSafeHwnd() && pMsg->message == WM_MOUSEMOVE)
{
CString windowText;
GetDlgItem(IDC_BUTTON2)->GetWindowText(windowText);
GetDlgItem(IDC_STATIC1)->SetWindowText(windowText);
}
return CDialog::PreTranslateMessage(pMsg);
}