65.9K
CodeProject 正在变化。 阅读更多。
Home

在 VB 6.0 中从外部 DLL 加载位图图片

starIconstarIconstarIconstarIcon
emptyStarIcon
starIcon

4.27/5 (10投票s)

2004年5月5日

viewsIcon

60640

downloadIcon

1147

在 VB 6.0 中从外部 DLL 加载位图图片 - (运行时)。

Bitmap ID 131 fromm Shell32.dll

Bitmap ID 130 fromm Shell32.dll

Bitmap ID 132 fromm Shell32.dll

引言

通过此示例,您可以使用存储在外部文件(DLL)中的位图。然后,您可以使用 Windows 系统中的位图,或者在 VB DLL 中创建自己的位图库。这对于创建位图库而无需在硬盘上保留大量文件非常有用。在这种情况下,任何人都可以删除这些图片。

模块代码

Type GUID
     Data1 As Long
     Data2 As Integer
     Data3 As Integer
     Data4(7) As Byte
End Type

Type PicBmp
     Size As Long
     Type As Long
     hBmp As Long
     hPal As Long
     Reserved As Long
End Type

Declare Function OleCreatePictureIndirect Lib "olepro32.dll" _
           (PicDesc As PicBmp, RefIID As GUID, ByVal fPictureOwnHandle As Long, _
           IPic As IPicture) As Long
Declare Function LoadBitmap Lib "user32" Alias "LoadBitmapA" _
               (ByVal hInstance As Long, ByVal lpBitmapID As Long) As Long
Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" _
               (ByVal lpLibFileName As String) As Long
Declare Function FreeLibrary Lib "kernel32" _
               (ByVal hLibModule As Long) As Long

'Exemplo em SHELL32.DLL com ID 131               
Public Function LoadPictureDLL(sResourceFileName As String, _
                        ByVal lResourceId As Long) As Picture
     Dim hInst As Long
     Dim hBmp  As Long
     Dim Pic As PicBmp
     
     Dim IPic As IPicture
     Dim IID_IDispatch As GUID
     Dim lRC As Long
     
     
     hInst = LoadLibrary(sResourceFileName)
     If hInst <> 0 Then
          hBmp = LoadBitmap(hInst, lResourceId)
          If hBmp <> 0 Then
               IID_IDispatch.Data1 = &H20400
               IID_IDispatch.Data4(0) = &HC0
               IID_IDispatch.Data4(7) = &H46
               Pic.Size = Len(Pic)
               Pic.Type = vbPicTypeBitmap
               Pic.hBmp = hBmp
               Pic.hPal = 0
               lRC = OleCreatePictureIndirect(Pic, IID_IDispatch, 1, IPic)
               If lRC = 0 Then
                    Set LoadPictureDLL = IPic
                    Set IPic = Nothing
               Else
                    Call DeleteObject(hBmp)
               End If
          End If
          FreeLibrary (hInst)
          hInst = 0
     End If
End Function

示例

示例应用程序包含更好的代码示例。请下载它以获取更多信息。

© . All rights reserved.