Kevin
Kevin

Reputation: 840

Visual Studio 2017 MFC SDI Debug Assertion OnCreate

I want to create a MFC Single Document Application with Visual Studio 2017.

I had made the following Configuration when I create the new Project:

Configuration MFC SD

Configuration MFC SD

Configuration MFC SD

Configuration MFC SD

If i now Build and Run the newly created Project without any changes on the code it immediately crashes with an Debug Assertion Error. This is the Message i got:

enter image description here

It seems the Problem is inside the OnCreate Method of the MainFrame.cpp. The Function gives the pContext Variable with NULL to the m_wndSplitter.Create Function.

This is the OnCreate and OnCreateClient Function of the MainFrame Class:

int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
    if (CFrameWndEx::OnCreate(lpCreateStruct) == -1)
        return -1;

    BOOL bNameValid;

    // create a view to occupy the client area of the frame
    if (!m_wndView.Create(NULL, NULL, AFX_WS_DEFAULT_VIEW, CRect(0, 0, 0, 0), this, AFX_IDW_PANE_FIRST, NULL))
    {
        TRACE0("Failed to create view window\n");
        return -1;
    }

    m_wndRibbonBar.Create(this);
    m_wndRibbonBar.LoadFromResource(IDR_RIBBON);

    if (!m_wndStatusBar.Create(this))
    {
        TRACE0("Failed to create status bar\n");
        return -1;      // fail to create
    }

    CString strTitlePane1;
    CString strTitlePane2;
    bNameValid = strTitlePane1.LoadString(IDS_STATUS_PANE1);
    ASSERT(bNameValid);
    bNameValid = strTitlePane2.LoadString(IDS_STATUS_PANE2);
    ASSERT(bNameValid);
    m_wndStatusBar.AddElement(new CMFCRibbonStatusBarPane(ID_STATUSBAR_PANE1, strTitlePane1, TRUE), strTitlePane1);
    m_wndStatusBar.AddExtendedElement(new CMFCRibbonStatusBarPane(ID_STATUSBAR_PANE2, strTitlePane2, TRUE), strTitlePane2);

    // enable Visual Studio 2005 style docking window behavior
    CDockingManager::SetDockingMode(DT_SMART);
    // enable Visual Studio 2005 style docking window auto-hide behavior
    EnableAutoHidePanes(CBRS_ALIGN_ANY);

    return 0;
}


BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT /*lpcs*/,
    CCreateContext* pContext)
{
    return m_wndSplitter.Create(this,
        2, 2,               // TODO: adjust the number of rows, columns
        CSize(10, 10),      // TODO: adjust the minimum pane size
        pContext);
}

Upvotes: 1

Views: 544

Answers (1)

Kevin
Kevin

Reputation: 840

I solved the Problem. The Assertion happens because the Document/View Architecture is needed. If i added the Document/View Architecture the Program runs without any problem

Upvotes: 0

Related Questions