|
| 1 | +VERSION 5.00 |
| 2 | +Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "comdlg32.ocx" |
| 3 | +Begin VB.Form Form1 |
| 4 | + BorderStyle = 1 'Fixed Single |
| 5 | + Caption = "DoubleClick to save the icon" |
| 6 | + ClientHeight = 6015 |
| 7 | + ClientLeft = 45 |
| 8 | + ClientTop = 345 |
| 9 | + ClientWidth = 9210 |
| 10 | + LinkTopic = "Form1" |
| 11 | + MaxButton = 0 'False |
| 12 | + MinButton = 0 'False |
| 13 | + ScaleHeight = 6015 |
| 14 | + ScaleWidth = 9210 |
| 15 | + StartUpPosition = 2 'CenterScreen |
| 16 | + Begin MSComDlg.CommonDialog cDialog |
| 17 | + Left = 240 |
| 18 | + Top = 1440 |
| 19 | + _ExtentX = 847 |
| 20 | + _ExtentY = 847 |
| 21 | + _Version = 393216 |
| 22 | + End |
| 23 | + Begin VB.CommandButton cmdOpen |
| 24 | + Caption = "..." |
| 25 | + Height = 375 |
| 26 | + Left = 80 |
| 27 | + TabIndex = 1 |
| 28 | + Top = 160 |
| 29 | + Width = 495 |
| 30 | + End |
| 31 | + Begin VB.PictureBox Picture1 |
| 32 | + Height = 600 |
| 33 | + Index = 0 |
| 34 | + Left = 0 |
| 35 | + ScaleHeight = 540 |
| 36 | + ScaleWidth = 540 |
| 37 | + TabIndex = 0 |
| 38 | + Top = 0 |
| 39 | + Visible = 0 'False |
| 40 | + Width = 600 |
| 41 | + End |
| 42 | +End |
| 43 | +Attribute VB_Name = "Form1" |
| 44 | +Attribute VB_GlobalNameSpace = False |
| 45 | +Attribute VB_Creatable = False |
| 46 | +Attribute VB_PredeclaredId = True |
| 47 | +Attribute VB_Exposed = False |
| 48 | +Private Type PicBmp |
| 49 | + Size As Long |
| 50 | + tType As Long |
| 51 | + hBmp As Long |
| 52 | + hPal As Long |
| 53 | + Reserved As Long |
| 54 | +End Type |
| 55 | +Private Type GUID |
| 56 | + Data1 As Long |
| 57 | + Data2 As Integer |
| 58 | + Data3 As Integer |
| 59 | + Data4(7) As Byte |
| 60 | +End Type |
| 61 | +Private Declare Function OleCreatePictureIndirect _ |
| 62 | +Lib "olepro32.dll" (PicDesc As PicBmp, RefIID As GUID, _ |
| 63 | +ByVal fPictureOwnsHandle As Long, IPic As IPicture) As Long |
| 64 | +Private Declare Function ExtractIconEx Lib "shell32.dll" _ |
| 65 | +Alias "ExtractIconExA" (ByVal lpszFile As String, ByVal _ |
| 66 | +nIconIndex As Long, phiconLarge As Long, phiconSmall As _ |
| 67 | +Long, ByVal nIcons As Long) As Long |
| 68 | +Private Declare Function DestroyIcon Lib "user32" (ByVal _ |
| 69 | +hicon As Long) As Long |
| 70 | +Private err As Boolean |
| 71 | +Public Function GetIconFromFile(FileName As String, _ |
| 72 | +IconIndex As Long, UseLargeIcon As Boolean) As Picture |
| 73 | + |
| 74 | +'Parameters: |
| 75 | +'FileName - File (EXE or DLL) containing icons |
| 76 | +'IconIndex - Index of icon to extract, starting with 0 |
| 77 | +'UseLargeIcon-True for a large icon, False for a small icon |
| 78 | +'Returns: Picture object, containing icon |
| 79 | + |
| 80 | +Dim hlargeicon As Long |
| 81 | +Dim hsmallicon As Long |
| 82 | +Dim selhandle As Long |
| 83 | + |
| 84 | +' IPicture requires a reference to "Standard OLE Types." |
| 85 | +Dim pic As PicBmp |
| 86 | +Dim IPic As IPicture |
| 87 | +Dim IID_IDispatch As GUID |
| 88 | + |
| 89 | +If ExtractIconEx(FileName, IconIndex, hlargeicon, _ |
| 90 | +hsmallicon, 1) > 0 Then |
| 91 | + |
| 92 | +If UseLargeIcon Then |
| 93 | +selhandle = hlargeicon |
| 94 | +Else |
| 95 | +selhandle = hsmallicon |
| 96 | +End If |
| 97 | + |
| 98 | +' Fill in with IDispatch Interface ID. |
| 99 | +With IID_IDispatch |
| 100 | +.Data1 = &H20400 |
| 101 | +.Data4(0) = &HC0 |
| 102 | +.Data4(7) = &H46 |
| 103 | +End With |
| 104 | +' Fill Pic with necessary parts. |
| 105 | +With pic |
| 106 | +.Size = Len(pic) ' Length of structure. |
| 107 | +.tType = vbPicTypeIcon ' Type of Picture (bitmap). |
| 108 | +.hBmp = selhandle ' Handle to bitmap. |
| 109 | +End With |
| 110 | + |
| 111 | +' Create Picture object. |
| 112 | +Call OleCreatePictureIndirect(pic, IID_IDispatch, 1, IPic) |
| 113 | + |
| 114 | +' Return the new Picture object. |
| 115 | +Set GetIconFromFile = IPic |
| 116 | + |
| 117 | +DestroyIcon hsmallicon |
| 118 | +DestroyIcon hlargeicon |
| 119 | + |
| 120 | +End If |
| 121 | +End Function |
| 122 | + |
| 123 | + |
| 124 | + |
| 125 | +Private Sub cmdOpen_Click() |
| 126 | +Dim strFileName |
| 127 | + cDialog.FileName = "" |
| 128 | + cDialog.ShowOpen |
| 129 | + strFileName = cDialog.FileName |
| 130 | + LoadAllIacons (strFileName) |
| 131 | +End Sub |
| 132 | + |
| 133 | +Private Sub Form_Load() |
| 134 | +LoadAllIacons (App.Path & "\moricons.dll") |
| 135 | +End Sub |
| 136 | + |
| 137 | + |
| 138 | +Private Sub Picture1_DblClick(Index As Integer) |
| 139 | + SavePicture Picture1(Index).Picture, App.Path & "\" & InputBox("Icon name", "Extract icons", "test") & ".ico" |
| 140 | +End Sub |
| 141 | +Private Function LoadAllIacons(strFileName As String) |
| 142 | +On Error GoTo errHandle |
| 143 | +Dim i As Integer |
| 144 | +For i = 1 To Picture1.Count - 1 |
| 145 | + Unload Picture1(i) |
| 146 | +Next |
| 147 | +i = 1 |
| 148 | +While Not err |
| 149 | + Load Picture1(i) |
| 150 | + Picture1(i).Visible = True |
| 151 | + Picture1(i).Top = Picture1(0).Height * Int(i / 15) + 100 |
| 152 | + Picture1(i).Left = Picture1(0).Width * (i Mod 15 - 1) + cmdOpen.Width + 200 |
| 153 | + retval = GetIconFromFile(strFileName, i - 1, True) |
| 154 | + If retval = 0 Then err = True |
| 155 | + Set Picture1(i).Picture = GetIconFromFile(strFileName, i - 1, True) |
| 156 | + i = i + 1 |
| 157 | +Wend |
| 158 | +Picture1(0).Visible = False |
| 159 | +Exit Function |
| 160 | +errHandle: |
| 161 | +Picture1(0).Visible = False |
| 162 | +Unload Picture1(i) |
| 163 | + |
| 164 | +End Function |
| 165 | + |
0 commit comments