文/云飛
一、界面
在窗體上放置一個對話框控件(Commondialog1),用于找到要提取圖標的程序文件;一個圖片框(Picture1),用來顯示圖標;一個水平滾動條(Hscroll1),用來逐個觀察;兩個命令按鈕,其Caption屬性分別設為“打開文件”和“退出”;四個標簽控件(Label),其Caption屬性分別設為“0”、“0”、“文件中圖標總數”和“當前圖標序號”。
二、程序代碼
聲明畫圖標函數DrawIcon
聲明取得文件句柄函數GetModuleHandle
聲明提取圖標函數ExtractIcon
Dim icon_n As Integer
Dim icon_filename As String
Dim icon_num As Integer
Dim x As Long
Dim hmodule As Long
Private Sub Command1_Click()
CommonDialog1.FileName = ""
CommonDialog1.Filter = "程序文件|*.exe"
CommonDialog1.ShowOpen
icon_filename = CommonDialog1.FileName
Picture1.Cls
hmodule = GetModuleHandle(icon_filename) '取得文件句柄
icon_num = ExtractIcon(hmodule, icon_filename, -1) '得到文件內圖標總數
HScroll1.Max = icon_num
Label1.Caption = Str(icon_num)
If icon_num - 1 > 0 Then
HScroll1.Enabled = True
Else
HScroll1.Enabled = False
End If
icon_n = ExtractIcon(hmodule, icon_filename, 0) '提取第一個圖標
x = DrawIcon(Picture1.hdc, 0, 0, icon_n) '畫出圖標
If icon_num = 0 Then
HScroll1.Value = 0
Else
HScroll1.Value = 1
End If
Label2.Caption = HScroll1.Value
End Sub
Private Sub Command2_Click()
End
End Sub
Private Sub HScroll1_Change()
Picture1.Cls
icon_n = HScroll1.Value
hmodule = GetModuleHandle(icon_filename)
icon_n = ExtractIcon(hmodule, icon_filename, icon_n - 1)
Label2.Caption = HScroll1.Value
x = DrawIcon(Picture1.hdc, 0, 0, icon_n)
End Sub
|