'Structures Declaration
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 example, Se avete un numero elevat di Files BMP o WAV potete leggerli e caricarli tramite un file risorse, ma rendendo enorme l'eseguibile, in questo modo potete utilizzare una DLL per raggruppare i files e caricarli tramite questa funzione Inputs: Path del file DLL, nome della risorsa Funzioni: DrawDLLBitmap: Carica una bitmap dalla DLL e la visualizza Parametri: DLLPath: Path del file DLL contenente le risorse PicDesc: Nome della risorsa Bitmap all'interno della DLL hDC: Specca dove disegnare la Bitmap bitmap dstX: Optional coord. X del punto di partenza del disegno dstY: Optional coord. Y del punto di partenza del disegno DrawDLLIcon: Carica una risorsa Icona dalla DLL e la visualizza Parametri: Exactly the same as DrawDLLBitmap LoadDLLString: Stringa della risorsa nella DLL DLLPath: Path della DLL StrNum: Numero assegnato alla Stringa PlayDLLSound: Carica una risorsa Wave dalla DLL e la riproduce DLLPath: Path to the DLL file containing the resources WavDesc: Nome della risorsa WAV sulla DLL |