When a dialog has controls on it, the dialog itself never gets the focus. It’s stolen by the child controls. When you press a button, a WM_KEYDOWN message is sent to the control with focus so your CgDlg::OnKeyDown is never called. Override the dialog’s PreTranslateMessage function if you want dialog to handle the WM_KEYDOWN message:
BOOL CgDlg::PreTranslateMessage(MSG *pMsg)
{
if (pMsg->message == WM_KEYDOWN)
{
if (pMsg->wParam == VK_DOWN)
{
// do something here
}
else if (pMsg->wParam == ...)
{
// do something here
}
else
{
// do something here
}
}
return CDialog::PreTranslateMessage(pMsg);
}Also see this article on CodeProject: http://www.codeproject.com/KB/dialog/pretransdialog01.aspx