简体   繁体   English

C ++ MFC应用程序CMFCBaseTabCtrl选项卡不可见

[英]C++ MFC application CMFCBaseTabCtrl Tab is not visible

I have an C++ MFC application created in Visual Studio 2015. I want to add a new tab to the application and created this function in the mainFrame class: 我在Visual Studio 2015中创建了一个C ++ MFC应用程序。我想向该应用程序添加一个新标签,并在mainFrame类中创建此函数:

void CMainFrame::OnCustomerNewcustomer()
{
    const CObList &tabGroups = GetMDITabGroups();
    CMFCTabCtrl *wndTab = (CMFCTabCtrl*)tabGroups.GetHead();
    CCustomerList *customer = (CCustomerList*)RUNTIME_CLASS(CCustomerList)->CreateObject();
    ((CWnd*)customer)->Create(NULL, NULL, WS_VISIBLE | WS_CHILD, CRect(0, 0, 20, 20), this, IDD_FORMVIEW_NEW_CUSTOMER);
    wndTab->AddTab(customer, _T("New Customer"), -1, 1);
}

The new tab is showed in the tab controller but if I selecte the tab it does not show the frame in IDD_FORMVIEW_NEW_CUSTOMER it only show the last selected tab's frame. 新选项卡显示在选项卡控制器中,但是如果我选择该选项卡,则它不会在IDD_FORMVIEW_NEW_CUSTOMER显示框架,而只会显示最后选择的选项卡的框架。 Does anyone know how to fix this? 有谁知道如何解决这一问题?

You are mixing two concepts you should not: MDI Child Windows and the CMFCTabCtrl tabs. 您正在混合不应使用的两个概念:MDI子Windows和CMFCTabCtrl选项卡。

I presume your CMainFrame class is descendant from CMDIFrameWndEx or anything similar. 我假设您的CMainFrame类是CMDIFrameWndEx或类似对象的后代。 If you want to have a MDI application, you should read more about Document/View architecture. 如果要拥有MDI应用程序,则应阅读有关文档/视图体系结构的更多信息。

You will need to have at least one CMultiDocTemplate (or a derived class) object, which will have an association of {Document, Child Frame, View} 您将至少需要一个CMultiDocTemplate(或派生类)对象,该对象将具有一个{Document,Child Frame,View}的关联。

Your code on OnInitInstance will look something like: 您在OnInitInstance上的代码如下所示:

CYourDocument* pDoc = /*WriteFunctionToGetApplicationDocument*/();
if (!pDoc)
{
    ASSERT(FALSE);
    return FALSE;
}

CMultiDocTemplate* pDocTemplate;

pDocTemplate = new CMultiDocTemplate(IDR_YOUR_DOCUMENT_TYPE,
    RUNTIME_CLASS(CYourDocument),
    RUNTIME_CLASS(CYourChildFrame),
    RUNTIME_CLASS(CYourView));

if (!pDocTemplate)
{
    CoUninitialize();   // if you did CoInitailize before   
    return FALSE;
}
AddDocTemplate(pDocTemplate);

In the procedure you want to add a new tab, refer to that template and instruct to create the respective frame: 在要添加新选项卡的过程中,请参考该模板并指示创建各自的框架:

 CYourChildFrame* pFrame = NULL;

 // add code to see pFrame is already open

if (!pFrame)
{
    CWaitCursor wc;

    CDocTemplate* pDocTemplate = /*WriteFunctionToGetApplicationMultiDocTemplate*/();
    if (!pDocTemplate)
    {
        ASSERT(FALSE);
        return;
    }

    pFrame = dynamic_cast<CYourFrame*>(pDocTemplate->CreateNewFrame(pDoc, NULL));
    if (!pFrame)
    {
        ASSERT(FALSE);
        return;
    }

    pDocTemplate->InitialUpdateFrame(pFrame, pDoc);
}

if (pFrame)
    MDIMaximize(pFrame);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM