首先使用类向导在对话框类里边添加虚函数PreTranslateMessage。
然后在该虚函数里写如下代码:
BOOL C充电插座产品序列号工具Dlg::PreTranslateMessage(MSG* pMsg)
{
// TODO: 在此添加专用代码和/或调用基类
if(WM_KEYDOWN ==pMsg->message && VK_RETURN == pMsg->wParam)
{
if (GetFocus() == GetDlgItem(IDC_EDIT1))
{
OnBnClickedButton1();
}
if (GetFocus() == GetDlgItem(IDC_EDIT2))
{
OnBnClickedButton2();
}
return true;
}
return CDialogEx::PreTranslateMessage(pMsg);
}