Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '########################################################
- ' Credits 3DotDev from http://3dotdevcoder.blogspot.fr/
- '########################################################
- Imports System.Runtime.InteropServices
- Public Class Cls_ExtractBmp
- Private bmp As Bitmap
- Private hRes As IntPtr = IntPtr.Zero
- Private hLib As IntPtr = IntPtr.Zero
- Private m_filename As String = String.Empty
- Private m_ResName As Integer = 0
- Private Const LOAD_LIBRARY_AS_IMAGE_RESOURCE As Integer = 32
- Private Const LOAD_LIBRARY_AS_DATAFILE As Integer = 2
- Private Declare Function LoadLibraryEx Lib "kernel32" (ByVal lpLibFileName As String, ByVal hModule As IntPtr, ByVal dwFlags As Integer) As IntPtr
- Private Declare Function FreeLibrary Lib "kernel32" (ByVal hLibModule As Long) As IntPtr
- Private Declare Function LoadBitmap Lib "user32" Alias "LoadBitmapA" (ByVal hInstance As IntPtr, ByVal lpBitmapName As String) As IntPtr
- Public Sub New(ByVal Filename As String, ByVal ResName As Integer)
- m_filename = Filename
- m_ResName = ResName
- End Sub
- Public Property Filename() As String
- Get
- Return m_filename
- End Get
- Set(ByVal value As String)
- m_filename = value
- End Set
- End Property
- Public Property ResName() As String
- Get
- Return m_ResName
- End Get
- Set(ByVal value As String)
- m_ResName = value
- End Set
- End Property
- Private ReadOnly Property Handle() As IntPtr
- Get
- Return hLib
- End Get
- End Property
- Public Function GetImg() As Bitmap
- ClearUp()
- hLib = LoadLibraryEx(m_filename, IntPtr.Zero, LOAD_LIBRARY_AS_DATAFILE + LOAD_LIBRARY_AS_IMAGE_RESOURCE)
- If hLib <> Nothing Then
- hRes = LoadBitmap(hLib, ResName)
- If hRes <> 0 Then
- bmp = Bitmap.FromHbitmap(hRes)
- FreeLibrary(hLib)
- End If
- End If
- Return bmp
- End Function
- Private Sub ClearUp()
- If Not hLib.Equals(IntPtr.Zero) Then
- FreeLibrary(hLib)
- hLib = IntPtr.Zero
- End If
- End Sub
- End Class
- '##############################
- ' Comment utiliser cette classe
- '##############################
- 'Instanciation d'un objet de type PictureBox
- Dim Pbx as new PictureBox
- 'Si PictureBox déjà chargée alors suppression de l'image
- If Not (Pbx.Image Is Nothing) Then
- Pbx.Image.Dispose()
- Pbx.Image = Nothing
- End If
- 'Affichage de la ressource Bitmap 6801 dans la PictureBox en utilisant la classe "Cls_ExtractBmp"
- If File.Exists(My.Application.GetEnvironmentVariable("SYSTEMDRIVE") & "Windows\explorer.exe") Then
- Dim ext1 As New Cls_ExtractBmp(My.Application.GetEnvironmentVariable("SYSTEMDRIVE") & "Windows\explorer.exe", 6801)
- Pbx.Image = ext1.GetImg
- End If
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement