Private Type PicBmp
Size As Long Type As Long hBmp As Long hPal As Long Reserved As Long End Type Private Type GUID Data1 As Long Data2 As Integer Data3 As Integer Data4(7) As Byte End Type Private Declare Function OleCreatePictureIndirect Lib "olepro32.dll" (PicDesc As PicBmp, RefIID As GUID, ByVal fPictureOwnsHandle As Long, IPic As IPicture) As Long Public Function CreatePictureFromHandle(Handle As Long, PictureType As Long) As IPictureDisp Dim Pic As PicBmp ' IPicture requires a reference to "Standard OLE Types" Dim IPic As IPicture Dim IID_IDispatch As GUID ' Fill in with IDispatch Interface ID With IID_IDispatch .Data1 = &H20400 .Data4(0) = &HC0 .Data4(7) = &H46 End With ' Fill Pic with necessary parts With Pic .Size = Len(Pic) ' Length of structure .Type = PictureType ' Type of Picture .hBmp = Handle ' Handle to bitmap .hPal = 0 ' Handle to palette (may be null) End With ' Create Picture object OleCreatePictureIndirect Pic, IID_IDispatch, 1, IPic ' Return the new Picture object Set CreatePictureFromHandle = IPic End Function |