BOOL CMyDialog::PreTranslateMessage(MSG *pMsg)
{
if (pMsg->message==WM_KEYDOWN && pMsg->wParam==VK_RETURN)
{
DWORD def_id=GetDefID();
if (def_id!=0)
{
CWnd *wnd=FromHandle(pMsg->hwnd);
// you may implement other ways of testing, e.g.
// comparing to array of CWnd*, comparing to array of IDs etc.
char class_name[16];
if (GetClassName(wnd->GetSafeHwnd(),
class_name,sizeof(class_name))!=0)
{
if (strnicmp(class_name,"Edit",5)==0)
{
GetDlgItem(LOWORD(def_id))->SetFocus();
return TRUE;
// discard the message!
}
}
}
}
// be a good citizen - call the base class
return CDialog::PreTranslateMessage(pMsg);
}