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
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?