看看这个 Private Type BITMAP bmType As Long bmWidth As Long bmHeight As Long bmWidthBytes As Long bmPlanes As Integer bmBitsPixel As Integer bmBits As Long End Type 'Constant Declaration Private Const SND_RESOURCE = &H40004 Private Const SND_SYNC = &H0 Private Const SRCCOPY = &HCC0020 'API Function Declaration Private Declare Function LoadString Lib "user32" Alias "LoadStringA" (ByVal hInstance As Long, ByVal wID As Long, ByVal lpBuffer As String, ByVal nBufferMax As Long) As Long Private Declare Function LoadBitmap Lib "user32" Alias "LoadBitmapA" (ByVal hInstance As Long, ByVal lpBitmapName As String) As Long Private Declare Function LoadIcon Lib "user32" Alias "LoadIconA" (ByVal hInstance As Long, ByVal lpIconName As String) As Long Private Declare Function DrawIcon Lib "user32" (ByVal hDC As Long, ByVal x As Long, ByVal y As Long, ByVal hIcon As Long) As Long Private Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" (ByVal lpLibFileName As String) As Long Private Declare Function FreeLibrary Lib "kernel32" (ByVal hLibModule As Long) As Long Private Declare Function GetObject Lib "gdi32" Alias "GetObjectA" (ByVal hObject As Long, ByVal nCount As Long, lpObject As Any) As Long Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hDC As Long) As Long Private Declare Function SelectObject Lib "gdi32" (ByVal hDC As Long, ByVal hObject As Long) As Long Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long Private Declare Function DeleteDC Lib "gdi32" (ByVal hDC As Long) As Long Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long Private Declare Function PlaySound Lib "winmm.dll" Alias "PlaySoundA" (ByVal lpszName As String, ByVal hModule As Long, ByVal dwFlags As Long) As Long Public Sub DrawDLLIcon(DLLPath As String, IconDesc As String, hDC As Long, Optional dstX As Long = 0, Optional dstY As Long = 0) Dim hLibInst As Long Dim hIcon As Long hLibInst = LoadLibrary(DLLPath) hIcon = LoadIcon(hLibInst, IconDesc) Call DrawIcon(hDC, dstX, dstY, hIcon) Call FreeLibrary(hLibInst) End Sub Public Sub DrawDLLBitmap(DLLPath As String, picDesc As String, hDC As Long, Optional dstX As Long = 0, Optional dstY As Long = 0) Dim hLibInst As Long Dim hdcMemory As Long Dim hLoadedbitmap As Long Dim hOldBitmap As Long Dim bmpInfo As BITMAP hLibInst = LoadLibrary(DLLPath) hLoadedbitmap = LoadBitmap(hLibInst, picDesc) Call GetObject(hLoadedbitmap, Len(bmpInfo), bmpInfo) hdcMemory = CreateCompatibleDC(hDC) hOldBitmap = SelectObject(hdcMemory, hLoadedbitmap) Call BitBlt(hDC, dstX, dstY, bmpInfo.bmWidth, bmpInfo.bmHeight, hdcMemory, 0, 0, SRCCOPY) Call SelectObject(hdcMemory, hOldBitmap) Call DeleteObject(hLoadedbitmap) Call DeleteDC(hdcMemory) Call FreeLibrary(hLibInst) End Sub Public Sub PlayDLLSound(DLLPath As String, WavDesc As String) Dim hLibInst As Long hLibInst = LoadLibrary(DLLPath) Call PlaySound(WavDesc, hLibInst, SND_RESOURCE Or SND_SYNC) FreeLibrary (hLibInst) End Sub Public Function LoadDLLString(DLLPath As String, StrNum As Long) As String Dim hLibInst As Long Dim strTemp As String * 32768 Dim posTemp As Integer hLibInst = LoadLibrary(DLLPath) Call LoadString(hLibInst, StrNum, strTemp, Len(strTemp)) posTemp = InStr(strTemp, Chr$(0)) LoadDLLString = Left$(strTemp, posTemp - 1) FreeLibrary (hLibInst) End Function
Private Type BITMAP
bmType As Long
bmWidth As Long
bmHeight As Long
bmWidthBytes As Long
bmPlanes As Integer
bmBitsPixel As Integer
bmBits As Long
End Type
'Constant Declaration
Private Const SND_RESOURCE = &H40004
Private Const SND_SYNC = &H0
Private Const SRCCOPY = &HCC0020
'API Function Declaration
Private Declare Function LoadString Lib "user32" Alias "LoadStringA" (ByVal hInstance As Long, ByVal wID As Long, ByVal lpBuffer As String, ByVal nBufferMax As Long) As Long
Private Declare Function LoadBitmap Lib "user32" Alias "LoadBitmapA" (ByVal hInstance As Long, ByVal lpBitmapName As String) As Long
Private Declare Function LoadIcon Lib "user32" Alias "LoadIconA" (ByVal hInstance As Long, ByVal lpIconName As String) As Long
Private Declare Function DrawIcon Lib "user32" (ByVal hDC As Long, ByVal x As Long, ByVal y As Long, ByVal hIcon As Long) As Long
Private Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" (ByVal lpLibFileName As String) As Long
Private Declare Function FreeLibrary Lib "kernel32" (ByVal hLibModule As Long) As Long
Private Declare Function GetObject Lib "gdi32" Alias "GetObjectA" (ByVal hObject As Long, ByVal nCount As Long, lpObject As Any) As Long
Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hDC As Long) As Long
Private Declare Function SelectObject Lib "gdi32" (ByVal hDC As Long, ByVal hObject As Long) As Long
Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long
Private Declare Function DeleteDC Lib "gdi32" (ByVal hDC As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Private Declare Function PlaySound Lib "winmm.dll" Alias "PlaySoundA" (ByVal lpszName As String, ByVal hModule As Long, ByVal dwFlags As Long) As Long
Public Sub DrawDLLIcon(DLLPath As String, IconDesc As String, hDC As Long, Optional dstX As Long = 0, Optional dstY As Long = 0)
Dim hLibInst As Long
Dim hIcon As Long
hLibInst = LoadLibrary(DLLPath)
hIcon = LoadIcon(hLibInst, IconDesc)
Call DrawIcon(hDC, dstX, dstY, hIcon)
Call FreeLibrary(hLibInst)
End Sub
Public Sub DrawDLLBitmap(DLLPath As String, picDesc As String, hDC As Long, Optional dstX As Long = 0, Optional dstY As Long = 0)
Dim hLibInst As Long
Dim hdcMemory As Long
Dim hLoadedbitmap As Long
Dim hOldBitmap As Long
Dim bmpInfo As BITMAP
hLibInst = LoadLibrary(DLLPath)
hLoadedbitmap = LoadBitmap(hLibInst, picDesc)
Call GetObject(hLoadedbitmap, Len(bmpInfo), bmpInfo)
hdcMemory = CreateCompatibleDC(hDC)
hOldBitmap = SelectObject(hdcMemory, hLoadedbitmap)
Call BitBlt(hDC, dstX, dstY, bmpInfo.bmWidth, bmpInfo.bmHeight, hdcMemory, 0, 0, SRCCOPY)
Call SelectObject(hdcMemory, hOldBitmap)
Call DeleteObject(hLoadedbitmap)
Call DeleteDC(hdcMemory)
Call FreeLibrary(hLibInst)
End Sub
Public Sub PlayDLLSound(DLLPath As String, WavDesc As String)
Dim hLibInst As Long
hLibInst = LoadLibrary(DLLPath)
Call PlaySound(WavDesc, hLibInst, SND_RESOURCE Or SND_SYNC)
FreeLibrary (hLibInst)
End Sub
Public Function LoadDLLString(DLLPath As String, StrNum As Long) As String
Dim hLibInst As Long
Dim strTemp As String * 32768
Dim posTemp As Integer
hLibInst = LoadLibrary(DLLPath)
Call LoadString(hLibInst, StrNum, strTemp, Len(strTemp))
posTemp = InStr(strTemp, Chr$(0))
LoadDLLString = Left$(strTemp, posTemp - 1)
FreeLibrary (hLibInst)
End Function