子对话框VK_TAB导航问题 [英] Child Dialog VK_TAB Navigating Problem
问题描述
我写了一个类CTpForm,它是CWnd派生的,并将其用作子类
对话.在我的文档视图项目中,我使用视图Cnsf2View作为持有人,其中有
视图中有两个CTpForm子窗口.我的问题是,当我使用Tab键在控件之间导航时,结果始终相同,它将foucs设置为第一个
当前子对话框中的子控件,我不知道原因.我的目标是
使用Tab键可在两个子对话框中的所有按钮之间导航.
谁能帮助我解决这个问题?我研究了CPropetyPage和CPropetySheet的代码,但我不知道为什么我的代码无法工作.任何想要获取我完整代码的人,请提供您的电子邮件地址,我将把我的项目发送给您.谢谢
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 nStyle,*/ UINT nID)
{
ASSERT(pParentWnd != NULL);
ASSERT(lpszTemplateName != NULL);
#ifdef _DEBUG
// dialog template must exist and be invisible with WS_CHILD set
if (!_AfxCheckDialogTemplate(lpszTemplateName, TRUE))
{
ASSERT(FALSE); // invalid dialog template name
PostNcDestroy(); // cleanup if Create fails too soon
return FALSE;
}
#endif //_DEBUG
// create a modeless dialog
BOOL bSuccess = CreateDlg(lpszTemplateName, pParentWnd);
if (!bSuccess)
return FALSE;
// dialog template MUST specify that the dialog
// is an invisible child window
SetDlgCtrlID(nID);
CRect rect;
GetWindowRect(&rect);
m_sizeDefault = rect.Size(); // set fixed size
// force WS_CLIPSIBLINGS
ModifyStyle(0, WS_CLIPSIBLINGS);
if (!ExecuteDlgInit(lpszTemplateName))
return FALSE;
// force the size to zero - resizing bar will occur later
SetWindowPos(NULL, 0, 0, 0, 0, SWP_NOZORDER|SWP_NOACTIVATE/*|SWP_SHOWWINDOW*/);
ModifyStyle(NULL, WS_CLIPCHILDREN | WS_CLIPSIBLINGS);
return TRUE;
}
BOOL CTpForm::PreTranslateMessage(MSG* pMsg)
{
return CWnd::PreTranslateMessage(pMsg);
}
BOOL Cnsf2View::PreTranslateMessage(MSG* pMsg)
{
// TODO: 在此添加专用代码和/或调用基类
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;
// only process WM_KEYDOWN ...
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;
}
推荐答案
问题已解决,TpForm(子对话框)需要使用ex-style WS_EX_CONTROLPARENT
The Porblem is solved, the TpForm (child dialog) need an ex-style WS_EX_CONTROLPARENT
BOOL CTpForm::Create(CWnd* pParentWnd, LPCTSTR lpszTemplateName, /*UINT nStyle,*/ UINT nID)
{
ASSERT(pParentWnd != NULL);
ASSERT(lpszTemplateName != NULL);
#ifdef _DEBUG
// dialog template must exist and be invisible with WS_CHILD set
if (!_AfxCheckDialogTemplate(lpszTemplateName, TRUE))
{
ASSERT(FALSE); // invalid dialog template name
PostNcDestroy(); // cleanup if Create fails too soon
return FALSE;
}
#endif //_DEBUG
// create a modeless dialog
BOOL bSuccess = CreateDlg(lpszTemplateName, pParentWnd);
if (!bSuccess)
return FALSE;
// dialog template MUST specify that the dialog
// is an invisible child window
SetDlgCtrlID(nID);
CRect rect;
GetWindowRect(&rect);
m_sizeDefault = rect.Size(); // set fixed size
// force WS_CLIPSIBLINGS
ModifyStyle(0, WS_CLIPSIBLINGS);
if (!ExecuteDlgInit(lpszTemplateName))
return FALSE;
// force the size to zero - resizing bar will occur later
SetWindowPos(NULL, 0, 0, 0, 0, SWP_NOZORDER|SWP_NOACTIVATE/*|SWP_SHOWWINDOW*/);
ModifyStyle(NULL, WS_CLIPCHILDREN | WS_CLIPSIBLINGS);
ModifyStyleEx(NULL, WS_EX_CONTROLPARENT);//这句重要,否则无法正常导航
return TRUE;
}
这篇关于子对话框VK_TAB导航问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!