如何将 CFormView 派生类附加到 CMFCTabCrtl?

发布于 2024-08-01 14:08:22 字数 863 浏览 3 评论 0原文

我创建了带有基类 CFormView、功能区、标题栏等的 MFC MDI 项目。 在CMainFrame中,OnCreate()调用EnableMDITabbedGroups(),它会自动添加一个选项卡 并附加 CMyProjectView 视图。 现在我想添加第二个选项卡并将第二个视图附加到该选项卡。 我创建了新对话框并向其中添加了 CFormView 派生类。

这是代码:

void CMainFrame::CreateViews()
{
const CObList &tabGroups = GetMDITabGroups();
CMFCTabCtrl *wndTab = (CMFCTabCtrl*)tabGroups.GetHead();
wndTab->m_bEnableWrapping = TRUE;

CRect dummyRect;
CNewFormView *pNewView = (CNewFormView*)RUNTIME_CLASS(CNewFormView)->CreateObject();
((CWnd*)pNewView)->Create(NULL, NULL, WS_CHILD, dummyRect, wndTab, IDD_NEWFORMVIEW); 

wndTab->AddTab(pNewView, _T("NewTab"), -1, TRUE);

}

现在,我很确定我错过了一些微不足道的事情或者一起走错了方向, 但我无法显示新视图。 另外,我无法在 CMainFrame 中捕获 AFX_WM_CHANGE_ACTIVE_TAB 或 AFX_WM_CHANGING_ACTIVE_TAB 。 消息从 CMFCBaseTabCtrl::FireChangingActiveTab 发送,但没有任何反应。

I have created MFC MDI project with base class CFormView, ribbon, caption bar etc.
In CMainFrame, OnCreate() calls EnableMDITabbedGroups() which automatically adds one tab
and attaches CMyProjectView view. Now I want to add second tab and attach second view to that tab. I created new dialog and added CFormView derived class to it.

Here is the code:

void CMainFrame::CreateViews()
{
const CObList &tabGroups = GetMDITabGroups();
CMFCTabCtrl *wndTab = (CMFCTabCtrl*)tabGroups.GetHead();
wndTab->m_bEnableWrapping = TRUE;

CRect dummyRect;
CNewFormView *pNewView = (CNewFormView*)RUNTIME_CLASS(CNewFormView)->CreateObject();
((CWnd*)pNewView)->Create(NULL, NULL, WS_CHILD, dummyRect, wndTab, IDD_NEWFORMVIEW); 

wndTab->AddTab(pNewView, _T("NewTab"), -1, TRUE);

}

Now, I'm pretty sure I missed something trivial or went in wrong direction all together,
but I can't get new view to show up. Also, I can't catch AFX_WM_CHANGE_ACTIVE_TAB or AFX_WM_CHANGING_ACTIVE_TAB in CMainFrame. Message gets send from CMFCBaseTabCtrl::FireChangingActiveTab but nothing happens.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

抱猫软卧 2024-08-08 14:08:22

视图样式中缺少 WS_VISIBLE?
您可能还想为框架设置活动视图。

WS_VISIBLE is missing from the view's styles?
You may want to set the active view for the frame too.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文