Converting An MFC Ribbon To Designer Format

Visual CPP Team

Pat Brenner

Hello, I’m Pat Brenner, a developer on the Visual C++ Libraries team, and I primarily work on MFC.

In Visual Studio 2010, a ribbon designer was added which allows you to visually edit the ribbon used in your MFC application. This doesn’t help you, however, if you adopted the ribbon user interface with Visual Studio 2008 SP1 and you’re creating your ribbon UI entirely with code in your application. We did consider that scenario, however, and added functionality to MFC to allow conversion of a “code” ribbon to an XML ribbon resource. I’ve been meaning to post an article on how to do this, so here it is.

I’ll use the conversion of the ribbon in the MSOffice2007Demo sample as an example:


  1. Download (if necessary) and open the MSOffice2007Demo sample solution. It can be found at this link ( ) under the “MFC Samples – Visual C++ 2008 Feature Pack” section. You may want to make a copy first if you want to keep the original sample around for reference.
  2. Build and run the solution. Check the contents of the different tabs of the ribbon. Exit the application.
  3. Open MainFrm.cpp and go to line 196 (where CreateStatusBar is called).
  4. Insert the following code at line 196 (immediately following the call to CreateRibbonBar):m_wndRibbonBar.SaveToXMLFile(“”); Image 2350 image thumb 73B42DE6
  5. Right click on the file tab and select “Copy Full Path” to get the full path name for the file. Image 5305 image thumb 0C43CB37
  6. Put the cursor between the double-quotes and insert the filename. Then modify the path to write the file to MSOffice2007Demo.mfcribbon-ms in the RES folder. Image 5811 image thumb 0BD79842
  7. Build and run the application again. As soon as the application starts up, you can exit the application. This will leave the XML file created on disk in the RES folder (with the mfcribbon-ms extension).
  8. Open the MSOffice2007Demo.mfcribbon-ms XML file and reformat it, using the “Format the whole document” button in the “XML Editor” group on the toolbar (or use the Ctrl+K, Ctrl+D keyboard shortcut to format the file).
  9. Edit the resource.h file using the text edit and add the ribbon resource ID:#define IDR_RIBBON 33000
  10. Edit the MSOffice2007Demo.rc file using the text editor and add the ribbon resource (since the ribbon is not a native resource type, 28 is used as the number for the ribbon resource type):IDR_RIBBON 28 DISCARDABLE “res\\MSOffice2007Demo.mfcribbon-ms”
  11. Remove the call to SaveToXMLFile from MainFrm.cpp (that you added earlier in steps 5 and 6).
  12. Remove lines 362-373 from MainFrm.cpp, the code to add ribbon tabs in code (except for the Developer tab).
  13. Add one line at line 362:m_wndRibbonBar.LoadFromResource(IDR_RIBBON); Image 8228 image thumb 44160F5A
  14. Build and run the application again. Verify that all the ribbon UI looks the same as it did in step 2.
  15. You can now open the RC file using the Resource View and edit the ribbon resource using the ribbon designer.


I hope you find this information helpful.



Pat Brenner Visual C++ Libraries Development


Discussion is closed.

Feedback usabilla icon