Dim lIcon As Long Dim sSourcePgm As String Dim sDestFile As StringPrivate Declare Function ExtractIcon Lib "shell32.dll" Alias "ExtractIconA" _ (ByVal hInst As Long, ByVal lpszExeFileName As String, ByVal nIconIndex As Long) As LongPrivate Declare Function DrawIcon Lib "user32" _ (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal hIcon As Long) As LongPrivate Declare Function DestroyIcon Lib "user32" (ByVal hIcon As Long) As LongPrivate Sub CmdSave_Click() '另存图示 On Error Resume Next With Dlg '存档问话框 .FileName = sDestFile .CancelError = True .Action = 2 If Err Then Err.Clear Exit Sub End If sDestFile = .FileName SavePicture Picture1.Image, sDestFile '将抓出的图示存盘 End With End SubPrivate Sub CmdOpen_Click() '开启档案 Dim a%
On Error Resume Next With Dlg '开档问话框 .FileName = sSourcePgm .CancelError = True .DialogTitle = "请选择包含图示的 DLL 或 EXE 文件" .Filter = "Icon Resources (*.ico;*.exe;*.dll)|*.ico;*.exe;*.dll|All files|*.*" .Action = 1 If Err Then Err.Clear Exit Sub End If sSourcePgm = .FileName Label3.Caption = .FileName DestroyIcon lIcon Do lIcon = ExtractIcon(App.hInstance, sSourcePgm, a) If lIcon = 0 Then Exit Do a = a + 1 DestroyIcon lIcon Loop If a = 0 Then MsgBox "在这个档中没有任何图示!" End If Label1.Caption = "在这个档中共有 " & a & " 个图示" VScroll1.Max = IIf(a = 0, 0, a - 1) VScroll1.Value = 0 VScroll1_Change End With End SubPrivate Sub Form_Load() CmdOpen_Click End Sub Private Sub VScroll1_Change() Label2.Caption = "正在浏览的图标索引值: " & VScroll1.Value DestroyIcon lIcon Picture1.Cls lIcon = ExtractIcon(App.hInstance, sSourcePgm, VScroll1.Value) Picture1.AutoSize = True Picture1.AutoRedraw = True DrawIcon Picture1.hdc, 0, 0, lIcon Picture1.Refresh End Sub
Dim sSourcePgm As String
Dim sDestFile As StringPrivate Declare Function ExtractIcon Lib "shell32.dll" Alias "ExtractIconA" _
(ByVal hInst As Long, ByVal lpszExeFileName As String, ByVal nIconIndex As Long) As LongPrivate Declare Function DrawIcon Lib "user32" _
(ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal hIcon As Long) As LongPrivate Declare Function DestroyIcon Lib "user32" (ByVal hIcon As Long) As LongPrivate Sub CmdSave_Click() '另存图示
On Error Resume Next
With Dlg '存档问话框
.FileName = sDestFile
.CancelError = True
.Action = 2
If Err Then
Err.Clear
Exit Sub
End If
sDestFile = .FileName
SavePicture Picture1.Image, sDestFile '将抓出的图示存盘
End With
End SubPrivate Sub CmdOpen_Click() '开启档案
Dim a%
On Error Resume Next
With Dlg '开档问话框
.FileName = sSourcePgm
.CancelError = True
.DialogTitle = "请选择包含图示的 DLL 或 EXE 文件"
.Filter = "Icon Resources (*.ico;*.exe;*.dll)|*.ico;*.exe;*.dll|All files|*.*"
.Action = 1
If Err Then
Err.Clear
Exit Sub
End If
sSourcePgm = .FileName
Label3.Caption = .FileName
DestroyIcon lIcon
Do
lIcon = ExtractIcon(App.hInstance, sSourcePgm, a)
If lIcon = 0 Then Exit Do
a = a + 1
DestroyIcon lIcon
Loop
If a = 0 Then
MsgBox "在这个档中没有任何图示!"
End If
Label1.Caption = "在这个档中共有 " & a & " 个图示"
VScroll1.Max = IIf(a = 0, 0, a - 1)
VScroll1.Value = 0
VScroll1_Change
End With
End SubPrivate Sub Form_Load()
CmdOpen_Click
End Sub
Private Sub VScroll1_Change()
Label2.Caption = "正在浏览的图标索引值: " & VScroll1.Value
DestroyIcon lIcon
Picture1.Cls
lIcon = ExtractIcon(App.hInstance, sSourcePgm, VScroll1.Value)
Picture1.AutoSize = True
Picture1.AutoRedraw = True
DrawIcon Picture1.hdc, 0, 0, lIcon
Picture1.Refresh
End Sub