Wednesday, May 4, 2011

Converting An MFC Ribbon To Designer Format

Converting An MFC Ribbon To Designer Format


Converting An MFC Ribbon To Designer Format

Posted: 04 May 2011 11:40 AM PDT

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 (http://archive.msdn.microsoft.com/vcsamplesmfc ) 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("");


  5. Right click on the file tab and select "Copy Full Path" to get the full path name for the file.

  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.

  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);

  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

Herb Sutter Shares Perspectives on the New C++ Standard

Posted: 04 May 2011 10:27 AM PDT

Charles TorreHi, I'm Charles Torre, Sr. Technographer with Channel 9. I'm back with an interview made last week with Herb Sutter, Principal Architect on the Visual C++ team at Microsoft and chairman of the ISO committee which recently approved the final technical changes to the C++0x standard – the publication of which is expected this summer. Go C++11!!! :-)

It's always great to talk to Herb. In this specific conversation, it's uplifting to see how excited Herb is for the future of one of the world's most capable and widely used general purpose programming languages. C++ is a modern programming language for power and performance, but it's also a highly abstracted general purpose language for building user mode applications, mobile apps, etc. The amazing part is how C++ can provide rich general programming abstractions and also ensure that your code can run at machine speeds. We talk about this, of course.

See below for the specific questions that were asked. You can simply click on a link to move directly to that point in the conversation. I do, however, strongly recommend that you watch the entire thing.

Tune in. Learn. Go native!

 

1:37 -> What were the goals of the C++0x standard, at a high level?

2:40 -> Language and Library abstractions and performance (how high can you go and still be fast as possible?)...

5:23 -> C++ as an application development language (in addition to the traditional C++ is a systems programming language meme)...

07:17 -> C++0x or can we now call it C++11?

09:21 -> Standards committees and real world user representation...

10:39 -> Who comes up with the new features that get standardized (or not...)?

13:01 -> What were the goals of the C++0x standard (non-canned answer)?

14:21 -> What does Bjarne mean by C++0x being a better C++ for novice programmers?

15:51 -> Why can't C++ look more like C#?

18:50 -> At the end of the day, everything(in terms of programmer-controlled computing) boils down to memory, right?

23:12 -> What are some of the most significant new features in C++0x?

25:05 -> What can VC++ developers expect to see in terms of C++0x implementation in Visual C++ next?

27:09 -> C++ and type safety...

29:05 -> C++0x and backwards compatibility: any big breaking changes?

34:16 -> C++0x in the Standard Library...

37:01 -> Any thinking in the Committee about doing more frequent experimental releases C++?

39:04 -> Are their features that didn't make it into the standard that you really wanted to be standardized?

41:45 -> Are you comfortable with C++'s current state? Is it modern enough?

43:22 -> Conclusion (or Charles doesn't end the conversation when his farewell begins - where does it go from there? )

Should I use HTML5 or Silverlight? One man's opinion.

Posted: 04 May 2011 01:25 PM PDT

I was in Belgium and The Netherlands this last week presenting and talking to folks in the community. After I presented on ASP.NET MVC 3, HTML5 and jQuery, one fellow came up after and said, "Should I use Silverlight or HTML5. I don't understand...( read more )...(read more)

Should I use HTML5 or Silverlight? One man's opinion.

Posted: 04 May 2011 01:25 PM PDT

I was in Belgium and The Netherlands this last week presenting and talking to folks in the community. After I presented on ASP.NET MVC 3, HTML5 and jQuery, one fellow came up after and said, "Should I use Silverlight or HTML5. I don't understand Read More......(read more)

Something "sort" of handy... [IListExtensions adds easy sorting to .NET list types - enabling faster search and removal, too!]

Posted: 04 May 2011 09:58 AM PDT

If you want to display a dynamically changing collection of items in WPF, Silverlight, or Windows Phone, there are a lot of collection classes to pick from - but there's really just one good choice: ObservableCollection(T) . Although nearly all the IList...( read more )...(read more)

Step-by-Step Using ImplicitDataType in Silverlight 5 Beta

Posted: 04 May 2011 02:55 AM PDT

ImplicitDataType is a new feature in Silverlight 5. Using ImplicitDataType, you can declare multiple Data Templates for your control and based on the data type, you can load the proper data template automatically.   In this article we will discuss...( read more )...(read more)

Silverlight Cream for May 03, 2011 -2 -- #1083

Posted: 03 May 2011 10:35 PM PDT

In this Issue: Max Paulousky , Roy Dallal , Colin Eberhardt , Deborah Kurata , David Anson , Mike Taulty ( -2- ), Jesse Liberty , and Jeremy Likness . Above the Fold: Silverlight: "The BestFitPanel collection of layout containers provides flexible, easy...( read more )...(read more)

Jeremy Likness on Clean Design-Time Friendly ViewModels: A Walkthrough

Posted: 03 May 2011 10:13 PM PDT

Jeremy provides a quick walkthrough to demonstrate clean design-time view models. These are view models that provide design-time data for your application, but don't embed that date in the final product. The release DLL and XAP files will only contain...( read more )...(read more)

No comments:

Post a Comment