One option is to translate the C++ example that Ken pointed you to,
which creates a transparent icon on the clipboard that you can use for
PasteFace.
Another option is to create a transparent icon and save it in a resource
file in your assembly. When you need the image for your command bar
button you can extract the icon resource as a Drawing.Icon object, call
the Icon object's ToBitmap method to get a bitmap, and copy that to the
clipboard where you can use it for PasteFace.
You have to be careful when using the Clipboard not to clobber whatever
data the user might currently have stored on it. Here is a VB.NET
procedure that maintains the existing content when using PasteFace
''' <summary>
''' Preserve contents of clipboard while using PastFace to set button image
''' </summary>
''' <param name="cbb">CommandBar button getting the image</param>
''' <param name="bmpImage">Bitmap applied as button image</param>
Private Sub PasteImage(ByVal cbb As CommandBarButton, ByVal bmpImage As
Drawing.Bitmap)
Try
'save current data (in all of its formats) on the clipboard;
'don't interfere with user pasting something into a new email
Dim clipData As System.Windows.Forms.IDataObject = _
System.Windows.Forms.Clipboard.GetDataObject
Dim astrFormats() As String = clipData.GetFormats(False)
Dim savedData As System.Windows.Forms.IDataObject = New
System.Windows.Forms.DataObject
Dim i As Integer
' add data to new data object in reverse order
' that's how it went into current object
For i = astrFormats.Length - 1 To 0 Step -1
savedData.SetData(astrFormats(i),
clipData.GetData(astrFormats(i)))
Next
System.Windows.Forms.Clipboard.SetDataObject(bmpImage, False)
'PasteFace copies image to our button
cbb.PasteFace()
'restore original data to clipboard
System.Windows.Forms.Clipboard.SetDataObject(savedData)
Catch ex As Exception
'exception handling here
End Try
End Sub
Rog said:
Thanks Dmitry, that then supports what I saw when I tried to the use
mask on the Button and get an exception.
Do you know how I can get a transparent image onto the CommandBarButton
using PasteFace then. I used magenta and green as the background, but it
does not work. I am using C#.
Thanks,
Rog
Dmitry said:
If you are using the Word editor (default in Outlook 2003), you cannot set
the image using Picture and Mask properties from a COM addin since IPicture
interface cannot be marshalled across the process boundaries (Word
inspectors run in the windword.exe process space), so you must use the
PasteFace method.
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
Thanks Ken, so the mask is supported even on the inspector for Outlook
2003? I know it works for the Explorer buttons.
Thanks
Ken Slovak - [MVP - Outlook] wrote:
Mask is supported for Outlook 2002 and later. It's only for Outlook 2000
that you need to use a workaround. Are you needing to support Outlook
2000?
The trick with Outlook 2000 is to use one color as a mask color, say
magenta. That color can only be used where you want masking. Then you do
some fancy stuff with the Win32 API and separate the mask and image and
pop them onto the clipboard and use PasteFace to add the button image.
See
http://www.daveswebsite.com/articles/article1/default.shtml for a C++
example and KB288771 for a VB example. Offhand I'm not familiar with any
C# examples but there may be some out there if you Google for
"PasteFace".