|
-
May 4th, 2000, 06:23 AM
#7
Frenzied Member
Hi... I'm not sure if you already had got it to work, but here's some code from a prog. I wrote.
Code:
Option Explicit
Private Type PicBmp
Size As Long
tType 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
Private Declare Function ExtractIconEx Lib "shell32.dll" _
Alias "ExtractIconExA" (ByVal lpszFile As String, ByVal _
nIconIndex As Long, phiconLarge As Long, phiconSmall As _
Long, ByVal nIcons As Long) As Long
Private Declare Function DestroyIcon Lib "user32" (ByVal _
hicon As Long) As Long
Public Function GetIconFromFile(Filename As String, _
IconIndex As Long, UseLargeIcon As Boolean) As Picture
'Parameters:
'FileName - File (EXE or DLL) containing icons
'IconIndex - Index of icon to extract, starting with 0
'UseLargeIcon-True for a large icon, False for a small icon
'Returns: Picture object, containing icon
Dim hlargeicon As Long
Dim hsmallicon As Long
Dim selhandle As Long
'IPicture requires a reference to "Standard OLE Types."
Dim pic As PicBmp
Dim IPic As IPicture
Dim IID_IDispatch As GUID
If ExtractIconEx(Filename, IconIndex, hlargeicon, _
hsmallicon, 1) > 0 Then
If UseLargeIcon Then
selhandle = hlargeicon
Else
selhandle = hsmallicon
End If
'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.
.tType = vbPicTypeIcon 'Type of Picture (bitmap).
.hBmp = selhandle 'Handle to bitmap.
End With
'Create Picture object.
Call OleCreatePictureIndirect(pic, IID_IDispatch, 1, IPic)
'Return the new Picture object.
Set GetIconFromFile = IPic
DestroyIcon hsmallicon
DestroyIcon hlargeicon
End If
End Function
Private Sub lblIcon_MouseDown(Button As Integer, Shift As Integer, x As Single, Y As Single)
'Right click > popup menu
If Button = vbRightButton Then
Me.PopupMenu mnuFile
ElseIf Button = vbLeftButton Then
Me.PopupMenu mnuConvert
End If
End Sub
Private Sub lblStatus_MouseDown(Button As Integer, Shift As Integer, x As Single, Y As Single)
'Right click > popup menu
If Button = vbRightButton Then
Me.PopupMenu mnuFile
ElseIf Button = vbLeftButton Then
Me.PopupMenu mnuConvert
End If
End Sub
Private Sub lblW_MouseDown(Button As Integer, Shift As Integer, x As Single, Y As Single)
If Button = vbRightButton Then
Me.PopupMenu mnuFile
ElseIf Button = vbLeftButton Then
Me.PopupMenu mnuConvert
End If
End Sub
Private Sub lblH_MouseDown(Button As Integer, Shift As Integer, x As Single, Y As Single)
'Right click > popup menu
If Button = vbRightButton Then
Me.PopupMenu mnuFile
ElseIf Button = vbLeftButton Then
Me.PopupMenu mnuConvert
End If
End Sub
Private Sub mnuBI_Click()
Dim SaveBI As String, F As Integer
Picture2.Picture = Picture1.Image
Comd1.Flags = cdlOFNOverwritePrompt + cdlOFNNoChangeDir
Comd1.DialogTitle = "Save Icon"
Comd1.Filter = "Icons (*.ico)|*.ico"
Comd1.ShowSave
SaveBI = Comd1.Filename
SavePicture Picture2.Picture, SaveBI
End Sub
Private Sub mnuSaveBMP_Click()
Dim SaveBMP As String, F As Integer
Picture2.Picture = Picture1.Picture
Comd1.Flags = cdlOFNOverwritePrompt + cdlOFNNoChangeDir
Comd1.DialogTitle = "Save Icon"
Comd1.Filter = "Bitmaps (*.bmp)|*.bmp"
Comd1.ShowSave
SaveBMP = Comd1.Filename
SavePicture Picture2.Image, SaveBMP
End Sub
Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, x As Single, Y As Single)
'Right click > popup menu
If Button = vbRightButton Then
Me.PopupMenu mnuFile
ElseIf Button = vbLeftButton Then
Me.PopupMenu mnuConvert
End If
End Sub
Private Sub mnuExtract_Click()
'Menu Extract Icon
Dim IcoFile As String
Dim Filename As String
Comd1.DialogTitle = "Extract File"
Comd1.Filter = "All supported files|*.exe;*.dll;*.ico,*.bmp|Executables (*.exe)|*.exe|DLL Files (*.dll)|*.dll|Ico Files (*.ico)|*.ico|Bitmap(*.bmp)|*.bmp|All Files (*.*)|*.*"
Comd1.ShowOpen
IcoFile = Comd1.Filename
'Plaats Ico in PictureBox
Set Picture1.Picture = GetIconFromFile(IcoFile, 0, True)
lblH = Picture1.Height
lblW = Picture1.Width
lblStatus.Caption = Comd1.FileTitle
End Sub
Private Sub mnuInfo_Click()
frmAbout.Show
End Sub
Private Sub mnuSave_Click()
Dim SaveIco As String, F As Integer
Comd1.Flags = cdlOFNOverwritePrompt + cdlOFNNoChangeDir
Comd1.DialogTitle = "Save Icon"
Comd1.Filter = "Icons (*.ico)|*.ico"
Comd1.ShowSave
SaveIco = Comd1.Filename
SavePicture Picture1.Picture, SaveIco
End Sub
Private Sub mnuQuit_Click()
Unload Me
End Sub
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, x As Single, Y As Single)
'Right click > popup menu
If Button = vbRightButton Then
Me.PopupMenu mnuFile
ElseIf Button = vbLeftButton Then
Me.PopupMenu mnuConvert
End If
End Sub
Private Sub Picture2_MouseDown(Button As Integer, Shift As Integer, x As Single, Y As Single)
'Right click > popup menu
If Button = vbRightButton Then
Me.PopupMenu mnuFile
ElseIf Button = vbLeftButton Then
Me.PopupMenu mnuConvert
End If
End Sub
I'm sorry for posting non-nessecary elements, but I'm tired..
if you have any questions, just mail me:
[email protected]
Jop
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|