MFC对话框运用程序,对话框上有多个按钮和静态文本框,鼠标移动到不同按钮上时静态文本框输出不同字符串,这个功能怎么实现?我刚学MFC,是个小白,希望各位大神不嫌麻烦,讲详细一点。谢谢!
4条回答 默认 最新
- 宇文仲竹 2015-09-11 08:06关注
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);
}本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报