Welcome to Office Zealot Sign in | Join | Help
Office 2007 Ribbon Extensibility

Well I suppose it’s time I come up for air and share some of my experiences with Office 12, er, I mean Office 2007, programmability. As a prominent new UI paradigm, I’m sure a lot of us will be getting intimate with the details of ribbon extensibility. One of the things I recently needed to figure out how to do while implementing a custom chunk on the ribbon is load my own button images.


 

This is fairly straightforward except for the IPictureDisp expected by the ribbon. I saw a few examples of how to deal with this from various posts/material on the internet. The one I liked best was from Omar Shahine. After dropping in his handy AxHost2 class, the task was a piece of cake. At a high level, here is what you need to do.

1) Implement the IRibbonExtensibility interface. This interface has only one member, string GetCustomUI(string). Where the string it returns is the XML that defines your custom ribbon.
2) Develop the XML that defines your ribbon.
3) Implement any callbacks required by your ribbon to respond to events such as onAction events or onLoad events.
4) Add a resource file to your project. Add your ribbon XML as a resource. Add any images you want to use as resources.
5) Create a class that can return an IPictureDisp interface from an image. (see Omar's post)

Here are the project files for a simple “Hello World” type project if you'd like to dissect them. The project is a plain vanilla Shared Add-In project targeting Word. Standard disclaimers apply. :)

As Maarten points out, the VSTO team has put together a tutorial document that shows how to do this using VSTOv3 CTP. Note that the project files I developed for this sample do note use VSTOv3 CTP. However, I'd recommend reading the document as Andrew goes into great detail regarding the hows and whys of ribbon extensibility. A ribbon design tool would be great and handling the details of dealing with IPictureDisp would also be a wonderful thing, so it sounds like the VSTO team is on the right track IMHO. I think it would be ideal to have a design surface that you could drop controls on to and then expose properties that'd allow you to do things like add images and such.

One difference that's worth pointing out between the VSTO tutorial and what I've done in this sample code is that I used the loadImage attribute in the customUI node. This allows you to specify one single callback that gets called for each control that has an image attribute. Then in the image attribute you specify the name of the image. This name gets passed to the method specified in the loadImage attribute. The VSTO tutorial uses the getImage attribute associated with each control. You could in theory specify a different callback for each control. This would give you more control if needed. If you merely need to load images for each control from a resource file, the loadImage method I've used works great too. The specifics of your situation will dictate the method and in many cases either method will work just fine.

Posted: Tuesday, April 11, 2006 10:00 AM by hansen
Filed under: , ,

Comments

No Comments

Anonymous comments are disabled