0

我知道一个文档可以有多个视图这些可以通过子框架类中的拆分器或通过 CTabView 但我想要多个选项卡,其中选项卡包含多个带有拆分器的视图?

这种组合可能吗?

4

1 回答 1

1

CTabCtrl::InsertItem 可以在 tabctrl 中将视图作为新选项卡插入。

CWnd* CObjectDlg::AddView(LPCTSTR lpszLabel, CRuntimeClass *pViewClass)

{

CCreateContext context;
context.m_pCurrentDoc       = NULL;
context.m_pCurrentFrame     = GetParentFrame();
context.m_pLastView         = NULL;
context.m_pNewDocTemplate   = NULL;
context.m_pNewViewClass     = pViewClass;

CWnd* pWnd;
TRY {
    pWnd = (CWnd*)pViewClass->CreateObject();
    if (pWnd == NULL){
        AfxThrowMemoryException();
    }
}
CATCH_ALL(e) {
    TRACE0(_T("Out of memory creating a view.\n"));
    return NULL;
}
END_CATCH_ALL

ASSERT_KINDOF(CWnd, pWnd);
ASSERT(pWnd->m_hWnd == NULL);       // not yet created

DWORD dwStyle = AFX_WS_DEFAULT_VIEW;
CRect rect;

// Create with the right size and position
if (!pWnd->Create(NULL, NULL, dwStyle, rect, &m_ObjectTab, 0, &context)) {
    TRACE0(_T("Warning: couldn't create client pane for view.\n"));
    // pWnd will be cleaned up by PostNcDestroy
    return NULL;
}
int nViews = m_ObjectTab.GetItemCount();
if (nViews != 0) {
    pWnd->EnableWindow(FALSE);
    pWnd->ShowWindow(SW_HIDE);
}
else{
    pWnd->EnableWindow(TRUE);
    pWnd->ShowWindow(SW_SHOW);
    m_pActiveView = (CView*)pWnd;
}

TC_ITEM tci;
tci.mask = TCIF_TEXT | TCIF_IMAGE | TCIF_PARAM;
tci.pszText = (LPTSTR)(LPCTSTR)lpszLabel;
tci.iImage = nViews;
tci.lParam = (DWORD)pWnd;
m_ObjectTab.InsertItem(nViews, &tci);
CRect rcChild;
m_ObjectTab.GetClientRect(&rcChild);
rcChild.top += 2;
rcChild.left += 2;
rcChild.bottom -= 23;
rcChild.right -= 2;
pWnd->MoveWindow(rcChild);
m_WndArray.Add(pWnd);
return pWnd;

}

于 2013-03-21T02:28:09.537 回答