Fabio GRANDE

Hi all.

I've seen that, in ribbon's xml files, it's possible to specify icons by name, using the "imageMso" tag.

I'm wondering if I can use the same icons names for filling an imageList control....

TIA

FabioG



Re: Visual Studio Tools for Office Use of icons out of ribbons

Rachel Schaw - MSFT

Hi Fabio,

I assume you are referring to the WinForms imageList object since there isn't an equivelent in RibbonX. Are you wanting to display Office images in a WinForms dialog

While imageMso is only supported when using RibbonX there is a workaround. You can use the Application.CommandBars.GetImageMso() function to get the bitmap fo any given "imageMso" tag. Then, convert it to a System.Drawing.Bitmap and add it to an imageList.

Hope this helps,

Rachel Schaw - MSFT





Re: Visual Studio Tools for Office Use of icons out of ribbons

Misha Shneerson - MSFT

Conveniently, I also had an example of how to retrieve an mso image and convert it to System.Drawing.Image.

Hope this helps,

...
private Image _image;
public InitializeImageFromMso()
{
_image = ConvertImage.Convert(Globals.ThisAddIn.Application.CommandBars.GetImageMso("ComAddInsDialog", 16, 16));
}

....

sealed public class ConvertImage : System.Windows.Forms.AxHost
{
private ConvertImage()
: base(null)
{
}
public static stdole.IPictureDisp Convert
(System.Drawing.Image image)
{
return (stdole.IPictureDisp)System.
Windows.Forms.AxHost
.GetIPictureDispFromPicture(image);
}

public static System.Drawing.Image Convert(stdole.IPictureDisp image)
{
int type = image.Type;
if (type == 1)
{
IntPtr hPal = (IntPtr)image.hPal;
return Image.FromHbitmap((IntPtr)image.Handle, hPal );
}
return null;
}
}






Re: Visual Studio Tools for Office Use of icons out of ribbons

Gastiflex

Hi,
is it possible to do this with Word 2003 or is it a nonsense to talk about imageMso with Office 2003




Re: Visual Studio Tools for Office Use of icons out of ribbons

Misha Shneerson - MSFT

imageMso concept has been only introduced in Office 2007.

I individual CommandBarButton objects in Office 2003 still have Picture property which would return IPictureDisp representation.

This page (http://office.microsoft.com/en-us/ork2000/HA011380611033.aspx) has some examples to get to a particular control (or to find control's id, which later can be used by CommandBars.FindControl API).






Re: Visual Studio Tools for Office Use of icons out of ribbons

Thierry Nenin

Hi Misha,

I am currently developping a kind of "light business contact mamanger" with posibility of encoding Invoice or account for a contact and so on... All of this fully integrated in Outlook 2007 and using word or excel to print various document based upon data encoded within outlook...

Sure that I would be glad to reuse some of ImageMso used elsewhere in office. But with the AxHost wrapper class you give or a static method I found a "VB6 support assembly" out of the box (3.5 framwork), there is a big transparency problem for most of the Images...

Indeed, you get the ImageMso, convert it in an .net Image, assign it to the Image property of a picture box and all what have transparency when displayed on the ribbon is converted in beautifull full black pixels on your picturebox .net control.

"Unusable..."

I understand well that we can't use Office images outside of office, but in order to left consistant with the user experience, we should be (we: isv's) happy to get original images with their transparrency properties as they are really display in the ribbon or at least, a solution that really convert the IPictureDisp com object in an .net Image but without loosing transparency.

To be convinced about what i am talking about, have a look at the well known Office2007IconsGallery workbook, watch the gallery, find the VB image that is shown on the developper tab, click it, if you have enabled the macro given with that workbook, you will get a little screen showing you this wonderfull image with full black 2 pixels right/down borders.

I know you are everyone listening at developpers wishes or criticism... At least, if this is a story of protecting those images from abuse, I would be glad to have an explanation about this even if it exists no solutions. In this later case, i will let down hours spended trying to find an elegant way to get those perfect images.

Regards.

PS : I don't know if you also read the VSTO 3.0 forum but I Also ask some questions without any responses (end of augustus). This is not usual in the microsoft's forums...

Addendum : I apologize about this remark, I didn't realize that I finally got some answers about my questions into th eVSTO 3.0 forum. And some of the answers are very promising for the futur.






Re: Visual Studio Tools for Office Use of icons out of ribbons

Misha Shneerson - MSFT

Hello Thierry,

It turns out that the bitmap contained in IPictureDisp.Handle() (which is returned by GetImageMso()) contains an alpha channel with full transparency information in it. In theory such bitmaps can be rendered using AlphaBlend() function (this is Win32 API and AFAIK there is no .NET analogue to it - but there is always PInvoke). Unfortunately when I first tried rendering the bitmap using AlphaBlend API things not work correctly either - I saw white background instead of transparent.

Digging deeper it turns that AlphaBlend expects what is called "pre-multiplied" values in R, G, B channels (i.e. the values of R, G, B channels should already be multiplied by the value of A channel) .i.e. correct "transparent" pixel should be specified by an ARGB quadruple set to 0, 0, 0,0. However, for various reasons Office chose to specifty transparent pixels as 0,255,255,255 tuple which causes the algorithm used by AlphaBlend to render such pixels as opaque white.

There is a workaround to post-process the DIB (device independent bitmap) returned by Office by modifying all the 0,255,255,255 pixels to 0,0,0,0 and then use AlphaBlend for rendering. Courtesy of Eric Faller (who has some guest appearances on Jensen's blog) I actually do have this code working on my box but due to a lot of PInvoke declarations I would not want to put it here. Lets use this post a very high-level explanation of what is going on w/o actual code.

In a couple of days I will have Eric as a guest writer on my blog where he will explain the problem in more details and provide sample code.






Re: Visual Studio Tools for Office Use of icons out of ribbons

Thierry Nenin

Misha,

Thanks. It's crystal clear... as usual with your answers...

Regards






Re: Visual Studio Tools for Office Use of icons out of ribbons