I write a class CTpForm, which is derivated from CWnd, and I use it as a child
dialog. In my doc-view project,i use the view Cnsf2View as a holder, there are
two CTpForm child windows in the view. my question is when i use tab key to navigeate between controls, the result is alway the same, it set foucs to the first
child control in the current child dialog,i don't know the reason. my target is
use tab key to navigate foucs between all the buttons in the two child dialog.
who will help me to analye the problem? I study the code of CPropetyPage and CPropetySheet, but i don't know why my code cannot work. any one who want get my full code, please give your email address, and i will send my project to you. thanks
BOOL CTpForm::Create(CWnd* pParentWnd, LPCTSTR lpszTemplateName, UINT nID)
{
ASSERT(pParentWnd != NULL);
ASSERT(lpszTemplateName != NULL);
#ifdef _DEBUG
if (!_AfxCheckDialogTemplate(lpszTemplateName, TRUE))
{
ASSERT(FALSE); PostNcDestroy(); return FALSE;
}
#endif //_DEBUG
BOOL bSuccess = CreateDlg(lpszTemplateName, pParentWnd);
if (!bSuccess)
return FALSE;
SetDlgCtrlID(nID);
CRect rect;
GetWindowRect(&rect);
m_sizeDefault = rect.Size();
ModifyStyle(0, WS_CLIPSIBLINGS);
if (!ExecuteDlgInit(lpszTemplateName))
return FALSE;
SetWindowPos(NULL, 0, 0, 0, 0, SWP_NOZORDER|SWP_NOACTIVATE);
ModifyStyle(NULL, WS_CLIPCHILDREN | WS_CLIPSIBLINGS);
return TRUE;
}
BOOL CTpForm::PreTranslateMessage(MSG* pMsg)
{
return CWnd::PreTranslateMessage(pMsg);
}
BOOL Cnsf2View::PreTranslateMessage(MSG* pMsg)
{
if ( CView::PreTranslateMessage(pMsg))
return TRUE;
return MyPreTranslateInput(pMsg);
}
BOOL Cnsf2View::MyPreTranslateInput(LPMSG lpMsg_)
{
ASSERT(::IsWindow(m_hWnd));
if (lpMsg_->message != WM_KEYDOWN)
return FALSE;
HWND _hwndFocus = ::GetFocus();
if (!_hwndFocus)
{
ASSERT(false);
return FALSE;
}
if (lpMsg_->wParam == VK_RETURN)
{
LRESULT _ret = ::SendMessage(_hwndFocus, WM_GETDLGCODE, 0, (LPARAM)lpMsg_);
if (_ret & DLGC_WANTMESSAGE)
return FALSE;
if (_ret & DLGC_BUTTON)
{
::SendMessage(_hwndFocus, BM_CLICK, 0, 0);
return TRUE;
}
}
else if (lpMsg_->wParam == VK_TAB)
{
LRESULT _ret = ::SendMessage(_hwndFocus, WM_GETDLGCODE, 0, (LPARAM)lpMsg_);
if (_ret & (DLGC_WANTALLKEYS | DLGC_WANTMESSAGE | DLGC_WANTTAB))
return FALSE;
if (::IsWindowVisible(_hwndFocus) &&
::IsChild(m_hWnd, _hwndFocus))
{
return PreTranslateInput(lpMsg_);
}
}
return FALSE;
}