0
votes

I have a strange Problem with my MFC Application which i create with visual Studio 2015.

If i run the Application inside Visual Studio via Local Windows Debugger everything works as expected.

If i start the generated .exe File outside of Visual Studio the Toolbar and the Statusbar are not displayed in the Mainframe. I couldn't activate them via View Menu. So my application crashs when I use a Menu Point which writes text to the statusbar.

Did someone now whats the Problem??

Perhaps I didn't know which code i should display in the question feel free to ask for specific code sections in the comments. I will edit the question and provide the code.

This is the code in which the Tool- and Statusbar are created.

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

    if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
        !m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
    {
        //TRACE0("Failed to create toolbar\n");
        return -1;      // fail to create
    }

    m_wndToolBar.LoadTCToolBar(16, IDB_TOOLICONS, IDB_TOOLICONS_HOT, IDB_TOOLICONS_DISABLED, RGB(255, 0, 255));

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

    return 0;
}
1
"I didn't know which code i should display in the question" The minimum possible set of code that duplicates your error and results in a complete, runnable program. This is often called a minimal reproducible example or MCVE for short. The beauty of the MCVE is once you have produced one, the bug has very little room in which it can hide and quite often allows you to delete or self answer the question because the MCVE makes the cause of the problem clear.user4581301
Can you show the code, where you create the status and tool bar in the main frame?Sebastian Stern
I have created a clean new MFC Program like the one with the problem. In that newly created MFC Program the described error did not happen.Kevin

1 Answers

0
votes

I have solved the Problem with a simple Code rearranging in the OnCreate Method.

The Method now looks like this:

int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{


    if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
        !m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
    {
        //TRACE0("Failed to create toolbar\n");
        return -1;      // fail to create
    }

    m_wndToolBar.LoadTCToolBar(16, IDB_TOOLICONS, IDB_TOOLICONS_HOT, IDB_TOOLICONS_DISABLED, RGB(255, 0, 255));

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

    if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
        return -1;

    return 0;
}

I had to move the Lines

if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
            return -1;

to the end of the Method. After that the Bars are displayed.