In my continuing series, I am providing some workarounds/solutions to some issues in the Visual Studio 2008 SP1 projects created that use the new “MFC Feature Pack”.
Today’s issue is Print Preview.
In a new Office 2007 Ribbon application, if you tell the MFC Application Wizard to not include Print Preview support, it will still include it in the File/Application menu. Once you create your new project, you’ll still see Print, Print Preview, etc. in the File menu (by clicking the “Pearl” on the top-left corner of the window).
To fix this, locate and remove the following code in MainFrm.cpp:
bNameValid = strTemp.LoadString(IDS_RIBBON_PRINT);
ASSERT(bNameValid);
CMFCRibbonButton* pBtnPrint =
new CMFCRibbonButton(ID_FILE_PRINT,
strTemp, 6, 6);
pBtnPrint->SetKeys(_T("p"), _T("w"));
bNameValid = strTemp.LoadString(IDS_RIBBON_PRINT_LABEL);
ASSERT(bNameValid);
pBtnPrint->AddSubItem(new CMFCRibbonLabel(strTemp));
bNameValid = strTemp.LoadString(IDS_RIBBON_PRINT_QUICK);
ASSERT(bNameValid);
pBtnPrint->AddSubItem(
new CMFCRibbonButton(ID_FILE_PRINT_DIRECT,
strTemp, 7, 7, TRUE));
bNameValid = strTemp.LoadString(IDS_RIBBON_PRINT_PREVIEW);
ASSERT(bNameValid);
pBtnPrint->AddSubItem(
new CMFCRibbonButton(ID_FILE_PRINT_PREVIEW,
strTemp, 8, 8, TRUE));
bNameValid = strTemp.LoadString(IDS_RIBBON_PRINT_SETUP);
ASSERT(bNameValid);
pBtnPrint->AddSubItem(
new CMFCRibbonButton(ID_FILE_PRINT_SETUP,
strTemp, 11, 11, TRUE));
pMainPanel->Add(pBtnPrint);
Also, when you run the application, if you customize the Quick Access Toolbar, you’ll notice that Print Preview commands are still available. To remove this, add the following code just after the ribbon is created, before the call to CMainFrame::InitializeRibbon():
m_wndRibbonBar.EnablePrintPreview(FALSE);
I have submitted the issue to Microsoft. You can view the issue report here.