// The following is NOT needed since I am using accelerators to map // ENTER to ID_MY_ENTER. But if all you want to do is ignore the Enter key, // you can handle DM_GETDEFID as below. // ON_MESSAGE(DM_GETDEFID, OnGetDefID) // not used END_MESSAGE_MAP()
//////////////////// Initialize dialog: BOOL CMyDlg::OnInitDialog() { CDlgWithAccelerators::OnInitDialog(); // Set the icon for this dialog. The framework does this automatically // when the application's main window is not a dialog m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); ASSERT(m_hIcon); SetIcon(m_hIcon, TRUE); // Set big icon SetIcon(m_hIcon, FALSE); // Set small icon // use same resource name as dialog to load dialog's accelerators m_hAccel = ::LoadAccelerators(AfxGetResourceHandle(),m_lpszTemplateName); ASSERT(m_hAccel); return TRUE; // return TRUE unless you set the focus to a control }
//////////////////// This is called to handle ID_MY_ENTER--ie, Enter key. void CMyDlg::OnMyEnter() { TRACE(_T("CMyDlg::OnMyEnter\n")); NextInTabOrder(); // move to next control }
//////////////////// Helper function to move focus to the next control. void CMyDlg::NextInTabOrder() { CWnd* pWndNext = GetNextDlgTabItem(GetFocus()); if (pWndNext) { pWndNext->SetFocus(); } }
////////////////// // This function is not used, since its message map entry is commented out. // If all you want to do is ignore the Enter key (not map it to a command), // then all you have to do is return zero here. Note that you MUST return // the special code DC_HASDEFID in the high-order word!! LRESULT CMyDlg::OnGetDefID(WPARAM wp, LPARAM lp) { TRACE(_T("CMyDlg::OnGetDefID\n")); return MAKELONG(0,DC_HASDEFID); }