新浪首页●免费邮件●用户注册●网站地图
上移动梦网
赢手机大奖

新浪首页 > 科技时代 > 网上学园 > 高级编程 > 正文
用Visual Basic提取图标资源

http://www.sina.com.cn 2001/10/31 13:54 中国电脑教育报

  文/云飞

  一、界面

  在窗体上放置一个对话框控件(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



【发表评论】【初学者园地】【科技聊天】【关闭窗口】

新 闻 查 询

 相关链接
VB.NET中的面向对象编程特征 (2001/10/23 13:23)
用VB6实现隐藏和显示“程序”选单 (2001/10/18 15:41)
在Excel中利用VBA创建多级选单 (2001/10/08 10:45)
在VB6中实现图像的变换 (2001/09/21 16:23)
VB.NET的重大转变 (2001/09/14 17:17)
用VB6编程监控CPU的资源状况 (2001/09/13 12:33)
在VB中实现文字的图片填充效果 (2001/09/11 12:39)
用VB编程让文本滚动更平滑 (2001/09/07 09:13)
加拿大VB程序员赚多少 (2001/09/04 13:20)
利用VB制作MP3播放列表 (2001/08/20 15:27)
用VB设计自己的E-mail系统 (2001/08/09 14:25)


科技时代意见反馈留言板 电话:010-82612286 或 010-82628888-3488   欢迎批评指正

网站简介 | 用户注册 | 广告服务 | 招聘信息 | 中文阅读 | Richwin | 联系方式 | 帮助信息

Copyright © 1996 - 2001 SINA.com, Stone Rich Sight. All Rights Reserved

版权所有 四通利方 新浪网