MFC中静态文本框获取鼠标移动到按钮上的消息
MFC对话框运用程序,对话框上有多个按钮和静态文本框,鼠标移动到不同按钮上时静态文本框输出不同字符串,这个功能怎么实现?我刚学MFC,是个小白,希望各位大神不嫌麻烦,讲详...
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);
}
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);
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询