Ribbon LoadImage/GetImage callbacks with VB6 COM Add-In

T

Tom Winter

I cannot get Word 2007 Ribbon LoadImage/GetImage callbacks to work with my
VB6 COM Add-in.

Word calls my LoadImage function correctly for each image that needs loaded,
and I load by images with LoadPicture and return them, but they don't show
up. Any ideas?

Here's the code, basically. It's getting called and appears to work, but
nothing shows up. I've tried a GDI load picture variant (for use with PNGs)
(http://www.bmsltd.ie/Excel/SBXLPage.asp) and it did not help. Same result.
Changing the return type to stdole.IPictureDisp doesn't help. If I return
one of the builtin image ids (like "FileNew") those images show up OK.

Public Function GetRibbonImage(ByVal vImageID As Variant) As Variant

Set GetRibbonImage = LoadPicture(m_sMyFolder & vImageID &
".gif")

End Function

Trying this didn't help...

Public Sub GetRibbonImage(ByVal vImageID As Variant, ByRef vImageOut As
Variant)

Could there be something wrong with my image files? They worked fine when I
had them in a DOTM created with the Office Custom UI Editor Tool.

Thanks!

-Tom
(e-mail address removed)
 
P

Patrick Schmid [MVP]

You have to return it as stdole.IPictureDisp.
Are you sure you are actually loading the picture into your variable?
Did you put something in your code that checks or even displays what you
loaded?

Patrick Schmid [OneNote MVP]
--------------
http://pschmid.net
***
Outlook 2007 Performance Update: http://pschmid.net/blog/2007/04/13/105
Office 2007 RTM Issues: http://pschmid.net/blog/2006/11/13/80
***
Customize Office 2007: http://pschmid.net/office2007/customize
RibbonCustomizer Add-In: http://ribboncustomizer.com
OneNote 2007: http://pschmid.net/office2007/onenote
***
Subscribe to my Office 2007 blog: http://pschmid.net/blog/feed
 
T

Tom Winter

I believe I had tried it with returning a stdole.IPictureDisp. I will try
again and see if that helps.

I but a breakpoint in the function, and it breaks there for every image in
my ribbon. The locals window shows a picture object, but I have not tried
displaying to see what it looks like. I will try that.

Thanks!

Patrick Schmid said:
You have to return it as stdole.IPictureDisp.
Are you sure you are actually loading the picture into your variable? Did
you put something in your code that checks or even displays what you
loaded?

Patrick Schmid [OneNote MVP]
--------------
http://pschmid.net
***
Outlook 2007 Performance Update: http://pschmid.net/blog/2007/04/13/105
Office 2007 RTM Issues: http://pschmid.net/blog/2006/11/13/80
***
Customize Office 2007: http://pschmid.net/office2007/customize
RibbonCustomizer Add-In: http://ribboncustomizer.com
OneNote 2007: http://pschmid.net/office2007/onenote
***
Subscribe to my Office 2007 blog: http://pschmid.net/blog/feed




I cannot get Word 2007 Ribbon LoadImage/GetImage callbacks to work with
my
VB6 COM Add-in.

Word calls my LoadImage function correctly for each image that needs
loaded,
and I load by images with LoadPicture and return them, but they don't
show
up. Any ideas?

Here's the code, basically. It's getting called and appears to work, but
nothing shows up. I've tried a GDI load picture variant (for use with
PNGs)
(http://www.bmsltd.ie/Excel/SBXLPage.asp) and it did not help. Same
result.
Changing the return type to stdole.IPictureDisp doesn't help. If I return
one of the builtin image ids (like "FileNew") those images show up OK.

Public Function GetRibbonImage(ByVal vImageID As Variant) As Variant

Set GetRibbonImage = LoadPicture(m_sMyFolder & vImageID &
".gif")

End Function

Trying this didn't help...

Public Sub GetRibbonImage(ByVal vImageID As Variant, ByRef vImageOut As
Variant)

Could there be something wrong with my image files? They worked fine when
I
had them in a DOTM created with the Office Custom UI Editor Tool.

Thanks!

-Tom
(e-mail address removed)
 
T

Tom Winter

Here's the whole procedure I've tried, with all the extra guts:

=============================
Public Function GetRibbonImage(ByVal vImageID As Variant) As
stdole.IPictureDisp

MsgBox vImageID ' DEBUG

On Error GoTo ErrorHandler

Dim sFileSpec As String

sFileSpec =
MakeFileSpec(MakeFolderSpec(MakeFolderSpec(GetInstallFolder(),
tbsFolderRibbons), tbsFolderImages), vImageID & ".bmp")

If FileExists(sFileSpec) Then

Set GetRibbonImage = LoadPicture(sFileSpec)

Load frmImage: Set frmImage.Image1.Picture = GetRibbonImage:
frmImage.Show vbModal ' DEBUG

Else

Set GetRibbonImage = Nothing

End If

Exit Function

ErrorHandler:

Set GetRibbonImage = Nothing

End Function
=============================

All of the imaged display just fine in my little image showing form, but
they still do not show up in Word. I've tried both BMP and GIF.

Here is my (simplified) RibbonX:

=============================
<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui"
loadImage="GetRibbonImage">
<ribbon startFromScratch="false">
<tabs>
<tab idMso="TabAddIns">
<group id="StationeryGroup" label="Stationery">
<button id="NewLetter" onAction="NewLetter"
label="Letter" image="NewLetter" size="normal" />
</group>
</tab>
</tabs>
</ribbon>
</customUI>
=============================

Tom Winter said:
I believe I had tried it with returning a stdole.IPictureDisp. I will try
again and see if that helps.

I but a breakpoint in the function, and it breaks there for every image in
my ribbon. The locals window shows a picture object, but I have not tried
displaying to see what it looks like. I will try that.

Thanks!

Patrick Schmid said:
You have to return it as stdole.IPictureDisp.
Are you sure you are actually loading the picture into your variable? Did
you put something in your code that checks or even displays what you
loaded?

Patrick Schmid [OneNote MVP]
--------------
http://pschmid.net
***
Outlook 2007 Performance Update: http://pschmid.net/blog/2007/04/13/105
Office 2007 RTM Issues: http://pschmid.net/blog/2006/11/13/80
***
Customize Office 2007: http://pschmid.net/office2007/customize
RibbonCustomizer Add-In: http://ribboncustomizer.com
OneNote 2007: http://pschmid.net/office2007/onenote
***
Subscribe to my Office 2007 blog: http://pschmid.net/blog/feed




I cannot get Word 2007 Ribbon LoadImage/GetImage callbacks to work with
my
VB6 COM Add-in.

Word calls my LoadImage function correctly for each image that needs
loaded,
and I load by images with LoadPicture and return them, but they don't
show
up. Any ideas?

Here's the code, basically. It's getting called and appears to work, but
nothing shows up. I've tried a GDI load picture variant (for use with
PNGs)
(http://www.bmsltd.ie/Excel/SBXLPage.asp) and it did not help. Same
result.
Changing the return type to stdole.IPictureDisp doesn't help. If I
return
one of the builtin image ids (like "FileNew") those images show up OK.

Public Function GetRibbonImage(ByVal vImageID As Variant) As Variant

Set GetRibbonImage = LoadPicture(m_sMyFolder & vImageID &
".gif")

End Function

Trying this didn't help...

Public Sub GetRibbonImage(ByVal vImageID As Variant, ByRef vImageOut As
Variant)

Could there be something wrong with my image files? They worked fine
when I
had them in a DOTM created with the Office Custom UI Editor Tool.

Thanks!

-Tom
(e-mail address removed)
 
T

Tom Winter

I figured it out. When I "run" the project in the VB6 IDE, the images do not
show up. When I use the compiled project, they do show up. Interesting.

Of course now I find that the transparancy does not work in my GIF images
when using VB's LoadPicture. Geez. Too bad my client won't pay me to
re-write in VB.NET!

Thanks for your help

-Tom

Tom Winter said:
Here's the whole procedure I've tried, with all the extra guts:

=============================
Public Function GetRibbonImage(ByVal vImageID As Variant) As
stdole.IPictureDisp

MsgBox vImageID ' DEBUG

On Error GoTo ErrorHandler

Dim sFileSpec As String

sFileSpec =
MakeFileSpec(MakeFolderSpec(MakeFolderSpec(GetInstallFolder(),
tbsFolderRibbons), tbsFolderImages), vImageID & ".bmp")

If FileExists(sFileSpec) Then

Set GetRibbonImage = LoadPicture(sFileSpec)

Load frmImage: Set frmImage.Image1.Picture = GetRibbonImage:
frmImage.Show vbModal ' DEBUG

Else

Set GetRibbonImage = Nothing

End If

Exit Function

ErrorHandler:

Set GetRibbonImage = Nothing

End Function
=============================

All of the imaged display just fine in my little image showing form, but
they still do not show up in Word. I've tried both BMP and GIF.

Here is my (simplified) RibbonX:

=============================
<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui"
loadImage="GetRibbonImage">
<ribbon startFromScratch="false">
<tabs>
<tab idMso="TabAddIns">
<group id="StationeryGroup" label="Stationery">
<button id="NewLetter" onAction="NewLetter"
label="Letter" image="NewLetter" size="normal" />
</group>
</tab>
</tabs>
</ribbon>
</customUI>
=============================

Tom Winter said:
I believe I had tried it with returning a stdole.IPictureDisp. I will try
again and see if that helps.

I but a breakpoint in the function, and it breaks there for every image
in my ribbon. The locals window shows a picture object, but I have not
tried displaying to see what it looks like. I will try that.

Thanks!

Patrick Schmid said:
You have to return it as stdole.IPictureDisp.
Are you sure you are actually loading the picture into your variable?
Did you put something in your code that checks or even displays what you
loaded?

Patrick Schmid [OneNote MVP]
--------------
http://pschmid.net
***
Outlook 2007 Performance Update: http://pschmid.net/blog/2007/04/13/105
Office 2007 RTM Issues: http://pschmid.net/blog/2006/11/13/80
***
Customize Office 2007: http://pschmid.net/office2007/customize
RibbonCustomizer Add-In: http://ribboncustomizer.com
OneNote 2007: http://pschmid.net/office2007/onenote
***
Subscribe to my Office 2007 blog: http://pschmid.net/blog/feed





I cannot get Word 2007 Ribbon LoadImage/GetImage callbacks to work with
my
VB6 COM Add-in.

Word calls my LoadImage function correctly for each image that needs
loaded,
and I load by images with LoadPicture and return them, but they don't
show
up. Any ideas?

Here's the code, basically. It's getting called and appears to work,
but
nothing shows up. I've tried a GDI load picture variant (for use with
PNGs)
(http://www.bmsltd.ie/Excel/SBXLPage.asp) and it did not help. Same
result.
Changing the return type to stdole.IPictureDisp doesn't help. If I
return
one of the builtin image ids (like "FileNew") those images show up OK.

Public Function GetRibbonImage(ByVal vImageID As Variant) As Variant

Set GetRibbonImage = LoadPicture(m_sMyFolder & vImageID &
".gif")

End Function

Trying this didn't help...

Public Sub GetRibbonImage(ByVal vImageID As Variant, ByRef vImageOut As
Variant)

Could there be something wrong with my image files? They worked fine
when I
had them in a DOTM created with the Office Custom UI Editor Tool.

Thanks!

-Tom
(e-mail address removed)
 
N

Nick Hebb

I figured it out. When I "run" the project in the VB6 IDE, the images do not
show up. When I use the compiled project, they do show up. Interesting.

It's probably the same as using the Picture and Mask properties in
Excel 2002 and 2003. They must be set in process. When running from
the IDE you are marshaling across processes, whereas (compiled) COM
add-ins operate in the same process space.

BTW, thanks for the postings. I've delayed implementing a ribbon for
my add-in and your code above gives me a good starting point.

Nicholas Hebb
BreezeTree Software
http://www.breezetree.com
 
P

Patrick Schmid [MVP]

I figured it out. When I "run" the project in the VB6 IDE, the images
do not
show up. When I use the compiled project, they do show up. Interesting.
Very. I don't get that fluke with VS 2005.
Of course now I find that the transparancy does not work in my GIF images
when using VB's LoadPicture. Geez. Too bad my client won't pay me to
re-write in VB.NET!
That's not it. GIF transparency won't work. See
http://blogs.msdn.com/jensenh/archive/2006/11/27/ribbonx-image-faq.aspx
for details on what to use (PNG with alpha channel should work I
believe)

Patrick Schmid [OneNote MVP]
--------------
http://pschmid.net
***
Outlook 2007 Performance Update: http://pschmid.net/blog/2007/04/13/105
Office 2007 RTM Issues: http://pschmid.net/blog/2006/11/13/80
***
Customize Office 2007: http://pschmid.net/office2007/customize
RibbonCustomizer Add-In: http://ribboncustomizer.com
OneNote 2007: http://pschmid.net/office2007/onenote
***
Subscribe to my Office 2007 blog: http://pschmid.net/blog/feed



Thanks for your help

-Tom

Tom Winter said:
Here's the whole procedure I've tried, with all the extra guts:

=============================
Public Function GetRibbonImage(ByVal vImageID As Variant) As
stdole.IPictureDisp

MsgBox vImageID ' DEBUG

On Error GoTo ErrorHandler

Dim sFileSpec As String

sFileSpec =
MakeFileSpec(MakeFolderSpec(MakeFolderSpec(GetInstallFolder(),
tbsFolderRibbons), tbsFolderImages), vImageID & ".bmp")

If FileExists(sFileSpec) Then

Set GetRibbonImage = LoadPicture(sFileSpec)

Load frmImage: Set frmImage.Image1.Picture = GetRibbonImage:
frmImage.Show vbModal ' DEBUG

Else

Set GetRibbonImage = Nothing

End If

Exit Function

ErrorHandler:

Set GetRibbonImage = Nothing

End Function
=============================

All of the imaged display just fine in my little image showing form, but
they still do not show up in Word. I've tried both BMP and GIF.

Here is my (simplified) RibbonX:

=============================
<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui"
loadImage="GetRibbonImage">
<ribbon startFromScratch="false">
<tabs>
<tab idMso="TabAddIns">
<group id="StationeryGroup" label="Stationery">
<button id="NewLetter" onAction="NewLetter"
label="Letter" image="NewLetter" size="normal" />
</group>
</tab>
</tabs>
</ribbon>
</customUI>
=============================

Tom Winter said:
I believe I had tried it with returning a stdole.IPictureDisp. I will try
again and see if that helps.

I but a breakpoint in the function, and it breaks there for every image
in my ribbon. The locals window shows a picture object, but I have not
tried displaying to see what it looks like. I will try that.

Thanks!

You have to return it as stdole.IPictureDisp.
Are you sure you are actually loading the picture into your variable?
Did you put something in your code that checks or even displays what you
loaded?

Patrick Schmid [OneNote MVP]
--------------
http://pschmid.net
***
Outlook 2007 Performance Update: http://pschmid.net/blog/2007/04/13/105
Office 2007 RTM Issues: http://pschmid.net/blog/2006/11/13/80
***
Customize Office 2007: http://pschmid.net/office2007/customize
RibbonCustomizer Add-In: http://ribboncustomizer.com
OneNote 2007: http://pschmid.net/office2007/onenote
***
Subscribe to my Office 2007 blog: http://pschmid.net/blog/feed





I cannot get Word 2007 Ribbon LoadImage/GetImage callbacks to work with
my
VB6 COM Add-in.

Word calls my LoadImage function correctly for each image that needs
loaded,
and I load by images with LoadPicture and return them, but they don't
show
up. Any ideas?

Here's the code, basically. It's getting called and appears to work,
but
nothing shows up. I've tried a GDI load picture variant (for use with
PNGs)
(http://www.bmsltd.ie/Excel/SBXLPage.asp) and it did not help. Same
result.
Changing the return type to stdole.IPictureDisp doesn't help. If I
return
one of the builtin image ids (like "FileNew") those images show up OK.

Public Function GetRibbonImage(ByVal vImageID As Variant) As Variant

Set GetRibbonImage = LoadPicture(m_sMyFolder & vImageID &
".gif")

End Function

Trying this didn't help...

Public Sub GetRibbonImage(ByVal vImageID As Variant, ByRef vImageOut As
Variant)

Could there be something wrong with my image files? They worked fine
when I
had them in a DOTM created with the Office Custom UI Editor Tool.

Thanks!

-Tom
(e-mail address removed)
 
K

Ken Slovak - [MVP - Outlook]

For VB 6 what I do is take a PNG file and add a Custom type to the project
resources using the PNG. That puts the file in the project as a binary of
the original image. Then I extract the Custom resource as a binary array of
Bytes and save it to the file system in a temp folder and pass that image
file to the ribbon getImage callback handler.

An alternative is to deploy the PNG to the installation folder and pass the
file path to that file but I generally prefer not to expose various files
like that in the installation folder.




Patrick Schmid said:
I figured it out. When I "run" the project in the VB6 IDE, the images do not
show up. When I use the compiled project, they do show up. Interesting.
Very. I don't get that fluke with VS 2005.
Of course now I find that the transparancy does not work in my GIF images
when using VB's LoadPicture. Geez. Too bad my client won't pay me to
re-write in VB.NET!
That's not it. GIF transparency won't work. See
http://blogs.msdn.com/jensenh/archive/2006/11/27/ribbonx-image-faq.aspx
for details on what to use (PNG with alpha channel should work I believe)

Patrick Schmid [OneNote MVP]
--------------
http://pschmid.net
***
Outlook 2007 Performance Update: http://pschmid.net/blog/2007/04/13/105
Office 2007 RTM Issues: http://pschmid.net/blog/2006/11/13/80
***
Customize Office 2007: http://pschmid.net/office2007/customize
RibbonCustomizer Add-In: http://ribboncustomizer.com
OneNote 2007: http://pschmid.net/office2007/onenote
***
Subscribe to my Office 2007 blog: http://pschmid.net/blog/feed
 
T

Tom Winter

I've created a GDI+ LoadPicture in order to use GIFs and PNGs, based on
these:
http://www.oaltd.co.uk/Excel/Default.htm
http://www.vbaccelerator.com/home/VB/Tips/Create_a_VB_Picture_from_a_GDI_Bitmap_Handle/article.asp

I use the LoadPictureGdiPlus() in my loadImage callback to load the picture
off disk. Having the pictures as separate files I can easily change is
actually an advantage for me over putting them in resources. But each
project is different.

Thanks!

-Tom

Ken Slovak - said:
For VB 6 what I do is take a PNG file and add a Custom type to the project
resources using the PNG. That puts the file in the project as a binary of
the original image. Then I extract the Custom resource as a binary array
of Bytes and save it to the file system in a temp folder and pass that
image file to the ribbon getImage callback handler.

An alternative is to deploy the PNG to the installation folder and pass
the file path to that file but I generally prefer not to expose various
files like that in the installation folder.




Patrick Schmid said:
I figured it out. When I "run" the project in the VB6 IDE, the images do not
show up. When I use the compiled project, they do show up. Interesting.
Very. I don't get that fluke with VS 2005.
Of course now I find that the transparancy does not work in my GIF
images
when using VB's LoadPicture. Geez. Too bad my client won't pay me to
re-write in VB.NET!
That's not it. GIF transparency won't work. See
http://blogs.msdn.com/jensenh/archive/2006/11/27/ribbonx-image-faq.aspx
for details on what to use (PNG with alpha channel should work I believe)

Patrick Schmid [OneNote MVP]
--------------
http://pschmid.net
***
Outlook 2007 Performance Update: http://pschmid.net/blog/2007/04/13/105
Office 2007 RTM Issues: http://pschmid.net/blog/2006/11/13/80
***
Customize Office 2007: http://pschmid.net/office2007/customize
RibbonCustomizer Add-In: http://ribboncustomizer.com
OneNote 2007: http://pschmid.net/office2007/onenote
***
Subscribe to my Office 2007 blog: http://pschmid.net/blog/feed
 

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