标签:
…… ……
BOOL CTestButtonDlg::PreTranslateMessage(MSG* pMsg)
{
if(pMsg->message == WM_LBUTTONDOWN)
{
if(pMsg->hwnd == GetDlgItem(IDC_BTN_FOR_TEST)->m_hWnd)
{
MessageBox("Button按钮按下");
// 在此调用Button按钮按下的操作
}
}
if(pMsg->message == WM_LBUTTONUP)
{
if(pMsg->hwnd == GetDlgItem(IDC_BTN_FOR_TEST)->m_hWnd)
{
MessageBox("Button按钮抬起");
// 在此调用Button按钮抬起的操作
}
}
}
…… ……
…… …… afx_msg void OnLButtonDown(UINT nFlags, CPoint point); afx_msg void OnLButtonUp(UINT nFlags, CPoint point); DECLARE_MESSAGE_MAP() …… ……
ForTestButton.cpp源文件中新增的源码如下:
…… ……
BEGIN_MESSAGE_MAP(CForTestButton, CButtion)
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
END_MESSAGE_MAP()
…… ……
…… ……
void CForTestButton::OnLButtonDown(UINT nFlags, CPoint point)
{
CRect rcJog;
this->GetClientRect(&rcJog);
if(rcJog.PtInRect(point))
{
MessageBox("Button按钮按下");
}
}
void CForTestButton::OnLButtonUp(UINT nFlags, CPoint point)
{
CRect rcJog;
this->GetClientRect(&rcJog);
if(rcJog.PtInRect(point))
{
MessageBox("Button按钮抬起");
}
}
…… ……
如何在MFC界面开发中响应Button按钮的Down和Up事件
标签:
原文地址:http://www.cnblogs.com/wolfmvp/p/5915177.html