有效方法:
BOOL CButtontestDlg::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
if (pMsg->message==WM_LBUTTONDOWN)
{
if (pMsg->hwnd == GetDlgItem(IDC_BUTTON1)->m_hWnd)
{
SetDlgItemText(IDC_STATIC_SHOW1,"BUN1 DOWN");
}
}
if (pMsg->message==WM_LBUTTONUP)
{
if (pMsg->hwnd == GetDlgItem(IDC_BUTTON1)->m_hWnd)
{
SetDlgItemText(IDC_STATIC_SHOW1,"BUN1 UP");
}
}
return CDialog::PreTranslateMessage(pMsg);
}
补充:设置BUTTON控件按下 抬起效果
(CButton*)GetDlgItem(IDC_BUTTON_UP) ->SetState(TRUE)
(CButton*)GetDlgItem(IDC_BUTTON_UP) ->SetState(FALSE)
还有以下办法,但是尝试后无法实现,目前还不知道原因
===================================================
获得按钮区域:
CButton m_Button1;
CRect rc;
m_Button1.GetWindowRect(rc);