Re: How to add button on Mail editor which is not outlook.??



Hi Ken,

We've one more issue, we don't want to see some anoying message in the
tooltip, presently it shows after the tooltip(screenTip attrib.) 'Press F1
for more help'. We feel it is not neccessary. Could you pls let me know how
to achieve the same?

I've tried wat u suggested, but still i'm facing the problem with the folg
code changes.

'Callback function for getImage

Public Function LoadImage(ByVal control As office.IRibbonControl) As
IPictureDisp

'The bmp files are added to a resource file.

'In general it's not recommended to use the default value references for
the bitmaps

'in the resource file.
Select Case control.id

Case "Add":


' TO Ken
'===================
'In the resource file, we've added our png file with 32x32 resolution.
' code is working fine
' but still we're unable to get our png image
'===================

Set LoadImage = LoadPictureResource(101, "CUSTOM")

'Inside LoadPictureResource it is calling the LoadPicturePlus which
you(Ken) have said in the last thread

End Select

End Function
GDI.bas
' ----==== API Declarations ====----

Private Type GdiplusStartupInput
GdiplusVersion As Long
DebugEventCallback As Long
SuppressBackgroundThread As Long
SuppressExternalCodecs As Long
End Type

Private Declare Function GdiplusStartup Lib "GDIPlus" ( _
token As Long, _
inputbuf As GdiplusStartupInput, _
Optional ByVal outputbuf As Long = 0) As Long

Private Declare Function GdiplusShutdown Lib "GDIPlus" ( _
ByVal token As Long) As Long

Private Declare Function GdipCreateBitmapFromFile Lib "GDIPlus" ( _
ByVal filename As Long, _
bitmap As Long) As Long

Private Declare Function GdipDisposeImage Lib "GDIPlus" ( _
ByVal image As Long) As Long

Private Declare Function GdipCreateHBITMAPFromBitmap Lib "GDIPlus" ( _
ByVal bitmap As Long, _
hbmReturn As Long, _
ByVal background As Long) As Long

Private Type PICTDESC
cbSizeOfStruct As Long
picType As Long
hgdiObj As Long
hPalOrXYExt As Long
End Type

Private Type IID
Data1 As Long
Data2 As Integer
Data3 As Integer
Data4(0 To 7) As Byte
End Type

Private Declare Sub OleCreatePictureIndirect Lib "oleaut32.dll" ( _
lpPictDesc As PICTDESC, _
riid As IID, _
ByVal fOwn As Boolean, _
lplpvObj As Object)

'------------------------------------------------------
' Procedure : LoadPicturePlus
' Purpose : Loads an image using GDI+
' Returns : The image loaded in a StdPicture object
' Author : Eduardo A. Morcillo
'------------------------------------------------------
'
Public Function LoadPicturePlus( _
ByVal filename As String) As StdPicture
Dim tSI As GdiplusStartupInput
Dim lGDIP As Long
Dim lRes As Long
Dim lBitmap As Long

' Initialize GDI+
tSI.GdiplusVersion = 1
lRes = GdiplusStartup(lGDIP, tSI)

If lRes = 0 Then

' Open the image file
lRes = GdipCreateBitmapFromFile(StrPtr(filename), lBitmap)

If lRes = 0 Then

Dim hBitmap As Long

' Create a GDI bitmap
lRes = GdipCreateHBITMAPFromBitmap(lBitmap, hBitmap, 0)

' Create the StdPicture object
Set LoadPicturePlus = HandleToPicture(hBitmap, vbPicTypeBitmap)

' Dispose the image
GdipDisposeImage lBitmap

End If

' Shutdown GDI+
GdiplusShutdown lGDIP
End If

If lRes Then Err.Raise 5, , "Cannot load file"

End Function

'------------------------------------------------------
' Procedure : HandleToPicture
' Purpose : Creates a StdPicture object to wrap a GDI
' image handle
'------------------------------------------------------
'
Public Function HandleToPicture( _
ByVal hGDIHandle As Long, _
ByVal ObjectType As PictureTypeConstants, _
Optional ByVal hPal As Long = 0) As StdPicture
Dim tPictDesc As PICTDESC
Dim IID_IPicture As IID
Dim oPicture As IPicture

' Initialize the PICTDESC structure
With tPictDesc
.cbSizeOfStruct = Len(tPictDesc)
.picType = ObjectType
.hgdiObj = hGDIHandle
.hPalOrXYExt = hPal
End With

' Initialize the IPicture interface ID
With IID_IPicture
.Data1 = &H7BF80981
.Data2 = &HBF32
.Data3 = &H101A
.Data4(0) = &H8B
.Data4(1) = &HBB
.Data4(3) = &HAA
.Data4(5) = &H30
.Data4(6) = &HC
.Data4(7) = &HAB
End With

' Create the object
OleCreatePictureIndirect tPictDesc, IID_IPicture, _
True, oPicture

' Return the picture object
Set HandleToPicture = oPicture

End Function

---

Res.bas

' Attribute VB_Name = "M_Res"
Option Explicit

'------------------------------------------------------------
' Source : support.microsoft.com
'------------------------------------------------------------

Public Declare Function GetTempFileName Lib "kernel32" _
Alias "GetTempFileNameA" ( _
ByVal lpszPath As String, _
ByVal lpPrefixString As String, _
ByVal wUnique As Long, _
ByVal lpTempFileName As String _
) As Long

Public Declare Function GetTempPath Lib "kernel32" _
Alias "GetTempPathA" ( _
ByVal nBufferLength As Long, _
ByVal lpBuffer As String _
) As Long


'' Public Function LoadPictureResource( _
'' ByVal ResourceID As Long, _
'' ByVal sResourceType As String, _
'' Optional TempFile _
'' ) As Picture
'' '=====================================================
'' 'Returns a picture object from a resource file.
'' 'Used for loading images other than ICO and BMP into a
'' 'Picture property. (Such as GIF and JPG images)
'' '=====================================================
''
'' 'EXAMPLE CALL:
'' 'Set Picture1.Picture = LoadPictureResource(101, "Custom",
"C:\temp\temp.tmp")
'' Dim sFileName As String
''
'' 'Check if the TempFile Name has been specified
''If IsMissing(TempFile) Then
'' 'Create a temp file name such as "~res1234.tmp"
'' GetTempFile "", "~rs", 0, sFileName
''Else
'' 'Use the specified temp file name
'' sFileName = TempFile
''End If
''
'' 'Save the resource item to disk
''If SaveResItemToDisk(ResourceID, sResourceType, sFileName) = 0 Then
''
'' 'Return the picture
'' Set LoadPictureResource = LoadPicture(sFileName)
''
'' 'Delete the temp file
'' Kill sFileName
''End If
''
'' End Function

Public Function LoadPictureResource( _
ByVal ResourceID As Long, _
ByVal sResourceType As String, _
Optional TempFile _
) As Picture
'=====================================================
'Returns a picture object from a resource file.
'Used for loading images other than ICO and BMP into a
'Picture property. (Such as GIF and JPG images)
'=====================================================

'EXAMPLE CALL:
'Set Picture1.Picture = LoadPictureResource(101, "Custom",
"C:\temp\temp.tmp")
Dim sFileName As String

'Check if the TempFile Name has been specified
If IsMissing(TempFile) Then
'Create a temp file name such as "~res1234.tmp"
GetTempFile "", "~rs", 0, sFileName
Else
'Use the specified temp file name
sFileName = TempFile
End If

'Save the resource item to disk
If SaveResItemToDisk(ResourceID, sResourceType, sFileName) = 0 Then

'Return the picture
Set LoadPictureResource = LoadPicturePlus(sFileName)

'Delete the temp file
Kill sFileName
End If

End Function

Public Function SaveResItemToDisk( _
ByVal iResourceNum As Integer, _
ByVal sResourceType As String, _
ByVal sDestFileName As String _
) As Long
'=============================================
'Saves a resource item to disk
'Returns 0 on success, error number on failure
'=============================================

'Example Call:
' iRetVal = SaveResItemToDisk(101, "CUSTOM", "C:\myImage.gif")

Dim bytResourceData() As Byte
Dim iFileNumOut As Integer

On Error GoTo SaveResItemToDisk_err

'Retrieve the resource contents (data) into a byte array
bytResourceData = LoadResData(iResourceNum, sResourceType)

'Get Free File Handle
iFileNumOut = FreeFile

'Open the output file
Open sDestFileName For Binary Access Write As iFileNumOut

'Write the resource to the file
Put iFileNumOut, , bytResourceData

'Close the file
Close iFileNumOut

'Return 0 for success
SaveResItemToDisk = 0

Exit Function
SaveResItemToDisk_err:
'Return error number
SaveResItemToDisk = Err.Number
End Function

Public Function GetTempFile( _
ByVal strDestPath As String, _
ByVal lpPrefixString As String, _
ByVal wUnique As Integer, _
lpTempFileName As String _
) As Boolean
'==========================================================================
' Get a temporary filename for a specified drive and filename prefix
' PARAMETERS:
' strDestPath - Location where temporary file will be created. If this
' is an empty string, then the location specified by the
' tmp or temp environment variable is used.
' lpPrefixString - First three characters of this string will be part of
' temporary file name returned.
' wUnique - Set to 0 to create unique filename. Can also set to integer,
' in which case temp file name is returned with that integer
' as part of the name.
' lpTempFilename - Temporary file name is returned as this variable.
' RETURN:
' True if function succeeds; false otherwise
'==========================================================================

If strDestPath = "" Then
' No destination was specified, use the temp directory.
strDestPath = String(255, vbNullChar)
If GetTempPath(255, strDestPath) = 0 Then
GetTempFile = False
Exit Function
End If
End If
lpTempFileName = String(255, vbNullChar)
GetTempFile = GetTempFileName(strDestPath, lpPrefixString, wUnique,
lpTempFileName) > 0
lpTempFileName = StripTerminator(lpTempFileName)
End Function


Public Function StripTerminator(ByVal strString As String) As String
'==========================================================
' Returns a string without any zero terminator. Typically,
' this was a string returned by a Windows API call.
'
' IN: [strString] - String to remove terminator from
'
' Returns: The value of the string passed in minus any
' terminating zero.
'==========================================================

Dim intZeroPos As Integer

intZeroPos = InStr(strString, Chr$(0))
If intZeroPos > 0 Then
StripTerminator = Left$(strString, intZeroPos - 1)
Else
StripTerminator = strString
End If
End Function
------------------

'
___________________________________________________________________________________


Thanks & Regards
Ashokkumar

"Ken Slovak - [MVP - Outlook]" wrote:

I usually save a PNG file to the file system and then if I want to add it to
my RES file I add it as a custom binary file. I'd then save the binary
information back to the file system and then load the file as an
IPictureDisp object.

I use 2 methods for that, SaveResItemToDisk() and LoadPicturePlus().

SaveResItemToDisk uses LoadResData to load the custom resource, then I use
VB file methods to Put the destination file which was opened for Binary
Access. LoadResData returns an array of Byte that I then Put to the file.

LoadPicturePlus is a method posted on his Web site by Eduardo A. Morcillo,
you can google for that method and use it in your code.

You can add your own controls to an existing tab by adding a custom group to
the tab you want to add to. For example for a new group added to the
existing Insert tab you'd use this XML fragment:

<tabs>
<tab idMso="TabInsert">
<group id="myInsertGroup" insertAfterMso="GroupInclude"
getLabel="Ribbon_getLabel" getVisible="Ribbon_getVisible">
<button id="myInsertButton" size="normal" getLabel="Ribbon_getLabel"
onAction="Ribbon_onAction" getSupertip="Ribbon_getSuperTip"
getImage="Ribbon_getImage" getVisible="Ribbon_getVisible"
getEnabled="Ribbon_getEnabled" />
</group>
</tab>

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


"Ashok" <Ashok@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:F632E8BF-AD6B-464C-BDAB-457584239FF4@xxxxxxxxxxxxxxxx
Hi Ken,

I made while paste here. After doing all things, we didn't a button with
icon. If I create a new png file. How can i add to my commands in VB.
Becoz,
Whole day we've investigated, but didn't get any thoughts.

One more issue. Is it possible to add my custom ctrls to built in
tabs(Message, Insert, format Text). If yes, Could you please provide me
those
details inorder to achieve the same?

Regards
Ashok


.