Loadlmage Callback

Using images that are included with Office is an easy way to use images in your applications. But if you are developing an application, there are likely many more times where you want to use your own images. To do so, the Ribbon provides a callback called loadlmage, which is called whenever an image is requested via the image attribute. To provide a single function for this task, the attribute is defined on the custom UI node as demonstrated in the following XML:

<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui"

loadImage="OnLoadImage">

<ribbon startFromScratch="true">

<tabs>

<tab id="tabLoadImageSamples" label="loadImage Samples">

<group id=

="grpBMP" label="BMP">

<button

id="btnLoadImage1"

label="News"

image="news.bmp"

size="large"/>

<button

id="btnLoadImage2"

label="Reminder"

image="bell.bmp"

size="large"/>

</group>

</tab>

The image attribute is the name of an image file that is passed to the loadlmage callback. You can use BMP, GIF, or JPG files for your images. The following code implements the loadlmage callback to load images in an Images subdirectory of the directory from which the database is currently opened. This means you can distribute images as a part of your application and load them dynamically.

Public Sub OnLoadImage(imageName As

String, ByRef image)

Dim strPath As String

strPath = CurrentProject.Path &

"\images\" & imageName

' return the image

Set image = LoadPicture(strPath)

End Sub

In this case, the image argument must return an object of type iPictureDisp. The easiest way to create one is to use the LoadPicture function.

0 0

Post a comment