簡體   English   中英

MFC應用程序不在Visual Studio外部顯示工具欄

[英]MFC Application don't display toolbar outside Visual Studio

我使用Visual Studio 2015創建的MFC應用程序存在一個奇怪的問題。

如果我通過本地Windows調試器在Visual Studio中運行該應用程序,則一切正常。

如果我在Visual Studio外部啟動生成的.exe文件,則工具欄和狀態欄不會顯示在大型機中。 我無法通過“查看菜單”激活它們。 因此,當我使用將文本寫入狀態欄的菜單點時,我的應用程序崩潰。

現在有人出了什么問題嗎?

也許我不知道我應該在問題中顯示哪個代碼,請隨時在注釋中詢問特定的代碼部分。 我將編輯問題並提供代碼。

這是在其中創建工具欄和狀態欄的代碼。

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;
}

我已經用OnCreate方法中的簡單代碼重新排列解決了該問題。

方法現在看起來像這樣:

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;
}

我不得不移動線

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

到方法的結尾。 之后,將顯示條。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM