MFC 捕获按钮 按下和抬起 (转)

BOOL Cxx::PreTranslateMessage(MSG* pMsg)
{
    // TODO: 在此添加专用代码和/或调用基类
    CString strShow = _T("");
 
    if(pMsg->message == WM_LBUTTONDOWN)//按钮按下
    {
        //按钮按下
        if(pMsg->hwnd == GetDlgItem(IDC_BTNRIGHT)->m_hWnd)
        {
            // 在此调用Button按钮按下的操作
 
            //发送控制设备右移指令
            SendCmdtoComm(m_cmdmoveright);
            SetDlgItemText(IDC_EDIT10,_T("设备右移指令已发送!"));
 
            pMsg->hwnd =NULL;//注意:如未添加该句,则会出错
        }
    }
    else if(pMsg->message == WM_LBUTTONUP)//按钮松开
    {
        //按钮松开
        if(pMsg->hwnd == GetDlgItem(IDC_BTNRIGHT)->m_hWnd)
        {
            // 在此调用Button按钮抬起的操作
            //发送设备停止右移指令
            SendCmdtoComm(m_cmdmovestop);
            SetDlgItemText(IDC_EDIT10,_T("设备右移结束!"));
            
            pMsg->hwnd =NULL;
        }
 
    }
 
    return CDialog::PreTranslateMessage(pMsg);
}

---------------------
作者:startfromnow86
来源:CSDN
原文:https://blog.csdn.net/sihua3211/article/details/79136231
版权声明:本文为博主原创文章,转载请附上博文链接!

猜你喜欢

转载自www.cnblogs.com/xigualixiang/p/10287190.html