How can I change the behavior of the TAB-Key in a Dialog? I want the TAB-Key to activate the next dialog control.
You should override OnGetDlgCode() (add a message map entry for WM_GETDLGCODE) and return
return CWnd::OnGetDlgCode() | DLGC_WANTARROWS | DLGC_WANTCHARS;
And a final thing is that when a edit control has the focus, it will continue to interprete the TAB Key. A solution for this is to override ProcessKeys() and check for the TAB Key.
The following code fragments should help you. If you would like to test it immediately, you can copy them to the file dergrdlg.cpp in the sample1 application.
/////////////////////////////////////////////////////////////////
// CDerGridWnd message handlers
BOOL CDerGridWnd::ProcessKeys(CWnd* pSender, UINT nMessage, UINT nChar, UINT nRepCnt, UINT flags)
{
if (pSender != this)
{
if (nMessage == WM_KEYDOWN && nChar == VK_TAB)
{
CWnd* pDlg = GetParent();
while (pDlg && !pDlg->IsKindOf(RUNTIME_CLASS(CDialog)))
pDlg = pDlg->GetParent();
if (pDlg)
{
CWnd* pWndNext = pDlg->GetNextDlgTabItem(m_pGridWnd);
if (pWndNext != NULL)
{
TRACE("SetFocus\n");
pWndNext->SetFocus();
return TRUE;
}
}
}
}
return CGXGridWnd::ProcessKeys(pSender, nMessage, nChar, nRepCnt, flags);
}