Fixing up MFC Office 2007 Ribbon Applications, Part 3

Posted by Matt | Filed under , , , ,

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.

Comments

February 5, 2009 17:13

Nate

Thanks, I was wondering why the print preview options were still showing, added that code and now is gone. Great!

Nate

Nate United Kingdom

June 8, 2009 12:34

Nuno

It is nice to know this, because i had already try to do this, and more Smile

By the way i'm trying to remove the ribbon bar, but let stay the quick access toolbar and the icon orb, do you know if this is possible?

Thanks

Nuno Portugal

June 8, 2009 13:16

Matt

The quick access toollbar is built right into the ribbon. Keeping the QAT but removing the toolbar may not be possible.

...Matt

Matt Canada

Comments are closed