A community member has associated this post with a similar question:
dynamically switch mfc ribbon resource

Only moderators can edit this content.

Print Preview fails after ribbon resource changed

Steve H 21 Reputation points
2021-04-22T13:30:35.433+00:00

The users of my MFC Windows desktop app need to be able to click on a ribbon button to switch to a different ribbon UI (for example, in a different language). The 2 ribbon resources are named IDR_RIBBON and IDR_RIBBON1. The "switch" button has the following event handler:

void CMainFrame::OnSwitchRibbon()
{
//close cats/tabs to avoid appending when new ribbon opens
m_wndRibbonBar.RemoveAllCategories();
m_wndRibbonBar.RemoveAllFromTabs();

//close ribbon bar
RemovePaneFromDockManager(&m_wndRibbonBar, TRUE, TRUE, FALSE, NULL);

//close control bars/panes inserted after ribbon bar
RemovePaneFromDockManager(&m_wndNavigationBar, TRUE, TRUE, FALSE, NULL);
RemovePaneFromDockManager(&m_wndCaptionBar, TRUE, TRUE, FALSE, NULL);

VERIFY(m_wndRibbonBar.Create(this));
VERIFY(m_wndRibbonBar.LoadFromResource(IDR_RIBBON1));

//restore bars/panes after ribbon bar
VERIFY(CreateOutlookBar(m_wndNavigationBar, ID_VIEW_NAVIGATION, m_wndTree, m_wndCalendar, 250));
VERIFY(CreateCaptionBar());

RecalcLayout();

}

The event handler works fine. The problem is that when the user clicks on the “Print Preview” menu item in the new ribbon Application button, the following CMFCRibbonBar code posts an unhandled exception error message (it apparently can’t read the Print Preview ribbon bar):

void CMFCRibbonBar::SetPrintPreviewMode(BOOL bSet)
{
ASSERT_VALID(this);

if (!m_bIsPrintPreview)
{
    return;
}

m_bPrintPreviewMode = bSet;

if (bSet)
{
    ASSERT_VALID(m_pPrintPreviewCategory);

FAILS ON NEXT LINE

    OnSetPrintPreviewKeys(m_pPrintPreviewCategory->GetPanel(0), m_pPrintPreviewCategory->GetPanel(1), m_pPrintPreviewCategory->GetPanel(2));

FAILURE MESSAGE:

An unhandled exception was encountered during a user callback.

This seems to be an MFC ribbon bug. Is there a workaround and/or will MS fix it?

Visual Studio
Visual Studio
A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.
4,604 questions
C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,527 questions
Visual Studio Debugging
Visual Studio Debugging
Visual Studio: A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.Debugging: The act or process of detecting, locating, and correcting logical or syntactical errors in a program or malfunctions in hardware. In hardware contexts, the term troubleshoot is the term more frequently used, especially if the problem is major.
939 questions
0 comments No comments
{count} votes