用Visual Basic提取圖標資源

發表于:2007-07-14來源:作者:點擊數: 標簽:
文/云飛 一、界面 在窗體上放置一個對話框控件(Commondialog1),用于找到要提取圖標的程序文件;一個圖片框(Picture1),用來顯示圖標;一個水平滾動條(Hscroll1),用來逐個觀察;兩個命令按鈕,其Caption屬性分別設為“打開文件”和“退出”;四個標簽控件(L
文/云飛

  一、界面

  在窗體上放置一個對話框控件(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 

原文轉自:http://www.anti-gravitydesign.com

国产97人人超碰caoprom_尤物国产在线一区手机播放_精品国产一区二区三_色天使久久综合给合久久97