Undocumented Office Ribbon Callback functionality

I just stumbled on an undocumented feature of the getImage callback for the Office 2010 Ribbon (well, backstage actually)

The “official” callback signature is
[csharp]
Public System.Drawing.Bitmap GetImage(Office.IRibbonControl control) {}
[/csharp]

Or sometimes

[csharp]
Public stdole.IPictureDisp GetImage(Office.IRibbonControl control) {}
[/csharp]

I don’t know which is “best”, but if you return a Bitmap it sure is easier to work with.

Now back in Office 2007 there are a couple controls with a GetImageMso callback that allows you to provide an Office Control ID for a built-in image. This is lacking from any 2010 backstage controls.

Whilst doing some unpleasant native debugging to try to “figure out” what office expects in these callback delegates, I tried creating a GetImage callback that returned a string.

[xml]
<?xml version="1.0" encoding="utf-8"?>
<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="Ribbon_Load">
<backstage>
<tab id="MyTabShare" label="Testing">
<firstColumn>
<group id="MyGroup">
<topItems>
<imageControl id="imageControl1" getImage="GetImage"/>
</topItems>
</group>
</firstColumn>
</tab>
</backstage>
</customUI>
[/xml]

[csharp]
public string GetImage(Office.IRibbonControl control)
{
return "hello world";
}
[/csharp]

I was really hoping for an error about a bad callback signature, possible including an exception in MSO.DLL that I could dig into…

Instead, I got this:

Really… So when GetImage returns a string, Office interprets it as an ImageMso? I had to try:
[csharp]
public string GetImage(Office.IRibbonControl control)
{
return "WindowKeepOnTop";
}
[/csharp]

The result: SUCCESS!

So, at least for the Office 2010 backstage ribbon, the getImage callback has an alternate signature:
[csharp]
string GetImage(IRibbonControl control)
[/csharp]

Where string is an Office Image Id (or the value you would place statically in imageMso).

1 thought on “Undocumented Office Ribbon Callback functionality”

Leave a Comment

Your email address will not be published. Required fields are marked *