| 关键词: icon 图标 filename HScroll 文件 hmodule CommonDialog Caption ExtractIcon GetModuleHandle |
一、界面 在窗体上放置一个对话框控件(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 |
|
声明:文章版权归原作者所有 部分文章转自互联网 如有侵权请联系
[邮箱地址] 删除
|