Command bar button FaceID Icon

D

donald

I know that Command bar button have property FaceId, and if i assign
this property to some value (472 for example) an icon appears. Is it
possible to register my icon in system somehow, so it would have an Id?

thanks a lot

Donald
 
K

Ken Slovak - [MVP - Outlook]

No. For putting your own icon (actually a 16x16x256 color BMP file) on a
button you use the .PasteFace method for Outlook 2000 or later or the .Mask
and .Picture properties for Outlook 2002 or later.
 
D

donald

i going this in outlook 2003

trying with this code in a COM add-in for outlook 2003 but it doesn't
work becuase it doesn't find the command LoadPicture.

Any help please

Donald

Sub DisplayNewImage( )
Dim cbar As CommandBar
Dim cbarctrl As CommandBarControl
Dim pImage As IPictureDisp
Dim pMask As IPictureDisp
Dim sImageFile as String
Dim sMaskFile as String

sImageFile = "C:\Documents and Settings\My Documents\tarsier.bmp"
sMaskFile = "C:\Documents and Settings\My Documents\mask.bmp"

Set cbar = CommandBars.Add(Name:="My Picture",
Position:=msoBarFloating)

Set cbarctrl = cbar.Controls.Add(Type:=msoControlButton)
Set pImage = stdole.StdFunctions.LoadPicture(sImageFile)
Set pMask = stdole.StdFunctions.LoadPicture(sMaskFile)

cbarctrl.Picture = pImage
cbarctrl.Mask = pMask

cbar.visible = True

End Sub
 
T

Thaddaeus Parker

What it looks like you are trying to do is load the picture from the
clipboard. If the picture and mask are not in the clipboard you cannot get
them out of the clipboard.

Here is my code that does what you are trying to do.
using stdole
/// <summary>

/// AxHost2 is a derivative of AxHost for getting IPictureDisp from a .NET
image type

/// </summary>

internal class AxHost2 : AxHost

{

public AxHost2() : base(null)

{}

new public static IPictureDisp GetIPictureDispFromPicture(Image image)

{

return (IPictureDisp) AxHost.GetIPictureDispFromPicture(image);

}

}

public static void AssignButtonImageAndMask(ref CommandBarButton button,
string imageName, string imageMask)

{

//adds a custom icon to the face

ResourceManager rm = new ResourceManager(typeof(OutlookUtilities).Namespace
+ <ResourceImageFileName> typeof(OutlookUtilities).Assembly);

using (Bitmap bmp = (Bitmap) rm.GetObject(imageName))

{

if (bmp != null)

{

button.Picture = AxHost2.GetIPictureDispFromPicture(bmp);

}

}

using (Bitmap bmp = (Bitmap) rm.GetObject(imageMask))

{

if (bmp != null)

{

button.Mask = AxHost2.GetIPictureDispFromPicture(bmp);

}

}

}

That bit of code should help you along.



Regards,

Thaddaeus.
 
D

donald

hi there,

I don't want to do it with copy and paste i am using Outlook 2003.

I want to do it using .picture and .mask.

Any help please

Donald
 
D

donald

i look at that page but i can't do:

Set oPic = LoadPicture(App.Path & "\circle.bmp")

because I can't find 'LoadPicture' in VB.net as my project is a COM
add-in for outlook 2003

thanks again

Donald
 
J

Josh Einstein

Thaddaeus gave you an example of the only known way to do this in .NET. It's
the only way to get an IPictureDisp from a System.Drawing.Image object. Your
reply to him stated that you didn't want to use Copy/Paste but his example
showed you how to use Picture and Mask, not Copy/Paste.

--
Josh Einstein
Einstein Technologies
Microsoft Tablet PC MVP
Tablet Enhancements for Outlook 2.0 - Try it free for 14 days
www.tabletoutlook.com
 
D

Dmitry Streblechenko

Also note that if you are using the Word editor, PasteFace is your only
option: IPicture object cannot be marshaled across thee process boundaries:
Word inspectors live in the ewinword.exe process space rather than
outlook.exe
Also note that you can save the clipboard contents before copying a bitmap
to the clipboard and restore it afterwards. Babelfish sample COM add-in
source code (url below) has a utility class to do that (Delphi) - see
uSaveClipboard.pas file.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 
J

Josh Einstein

Be cautious about saving/restoring the clipboard contents because it can
have unintended side effects. For example, if the data object is a large
object on another machine (like in RDP) or in another process (like a 300mb
bitmap in photoshop) then you might introduce long unexpected blocks in your
application and spikes of memory use and the user will have no idea what is
going on since they didn't initiate a clipboard operation.

--
Josh Einstein
Einstein Technologies
Microsoft Tablet PC MVP
Tablet Enhancements for Outlook 2.0 - Try it free for 14 days
www.tabletoutlook.com
 
D

donald

I try very think in this topic but i still can't get it working. I
don;t want to use the copy and paste because the user will loss there
clipboard and if you try so save it, it could be 300mb as explain
above.

So could some one who got it working post there code up. The code i
have is:

Dim path As String = "C:\Visual Studio
Projects\DC\DMCRM\icons\AddTelephoneCall.ico"

Dim imgconv As ImageConverter
Dim img As System.Drawing.Image

img = System.Drawing.Image.FromFile(path)
Dim a As stdole.IPictureDisp =
imgconv.ImageToIPicDisp(img)

.Picture = a

Public Class ImageConverter
Inherits System.Windows.Forms.AxHost

Public Sub New(ByVal pGUID As String)
MyBase.New(pGUID)
End Sub

Public Shared Function ImageToIPicDisp(ByVal value As
System.Drawing.Image) As stdole.IPictureDisp
Return
System.Windows.Forms.AxHost.GetIPictureDispFromPicture(value)
End Function

Public Shared Function IPicDispToImage(ByVal value As
stdole.IPictureDisp) As System.Drawing.Image
Return
System.Windows.Forms.AxHost.GetPictureFromIPictureDisp(CType(value,
Object))
End Function
End Class


the code get a error on this line ' .Picture = a'

any help please

Donald
 
J

Josh Einstein

As far as I know, you have to use a bitmap type of image.
(System.Drawing.Bitmap) Not an icon.

--
Josh Einstein
Einstein Technologies
Microsoft Tablet PC MVP
Tablet Enhancements for Outlook 2.0 - Try it free for 14 days
www.tabletoutlook.com
 
D

donald

this is a bitmap type of image.

I look in to this and i don;t think it is Converting the image to a
ImageToIPicDisp in the right way.
 
D

donald

just so you know i get this error message:

System.Runtime.InteropServices.COMException (0x80004005): Unspecified
error
at Microsoft.Office.Core._CommandBarButton.set_Picture(IPictureDisp
ppdispPicture)
at DC.Connect.createBar() in C:\Visual Studio
Projects\DC\DMCRM\Connect.vb:line 853

line 853 is .Picture = a

thanks

Donald
 
T

Thaddaeus Parker

I did some research on what you were trying to do. According to a thread I
found at ureader.com. Ken Slovak said that IPictureDisp constraint is that
the image must be a 16x16 256 color BMP. Other wise you might get the error
that you are experiencing.

If I were you I would convert your .ico to a .bmp and try to run the program
again. Or, go ahead and add the image to a resource file inside your add-in
and use a resource manager to pull the appropriate image out of and then use
the IPictureDisp code that you already have to render the image on the
commandbar button.

It's an idea, for what it's worth

Thaddaeus.

http://support.microsoft.com/kb/288771
 
D

donald

Hi there,

thanks for your reply's but i try it as a 256 color 16x16 bitmap and no
luck at all.

As for the 2 web link they both use LoadPicture which is not available
in vb.net

i am using vb.net 2003 with office outlook 2003

thanks

Donald
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top