How to block mouse inputs on dialog box in MFC

I have a dialog based MFC application. I have a hidden Edit Control on it which has the default focus for reading USB connected scanner input. All other controls on the dialog are read only. But when user clicks on any of the controls, the hidden edit control loses the focus. How can I solve the problem, so that this hidden edit control has the focus even after user clicks on the dialog box anywhere.


Well, most mouse messages in an MFC application are posted and not sent. So, you could override PreTranslateMessage(MSG*) in your CDialog derived class and then eat those message by returning TRUE to prevent message dispatch or FALSE to allow normal processing.

BOOLCMyDlg::PreTranslateMessage(MSG* pMsg)
{
    switch (pMsg->message)
    {
    case WM_LBUTTONDOWN:
    case WM_RBUTTONDOWN:
    ///etc, etc
        {
            // might want other tests
            return TRUE;
        } break;
    }
    return CDialog::PreTranslateMessage(MSG* pMsg);
}
链接地址: http://www.djcxy.com/p/39266.html

上一篇: 为什么会发生QEvent :: ShortcutOverride事件?

下一篇: 如何在MFC中的对话框中阻止鼠标输入