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);
}