CSDN博客

img tanaya
博客专家

如何获取exe,dll中的图标以及源程序

发表于2004/9/29 11:04:00  2925人阅读

分类: >> VB6

今天网上有人问到这个,随便给解释了下,具体请看:

http://community.csdn.net/Expert/topic/3417/3417578.xml?temp=.30534

我出的源程序:

新建一个工程,在窗体上加上两个Label: Label1和Label2;以及一个VScroll1和Picture1
示例源代码如下:

Option Explicit

Private Declare Function DrawIcon Lib "user32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal hIcon As Long) As Long
Private Declare Function ExtractIcon Lib "shell32" Alias "ExtractIconA" (ByVal hInst As Long, ByVal lpszExeFileName As String, ByVal nIconIndex As Long) As Long
Private Declare Function DestroyIcon Lib "user32" (ByVal hIcon As Long) As Long

'这个路径根据你的系统改变
Private Const sIconFile As String = "c:/winnt/system32/User32.dll"

Private Sub Form_Load()
   Dim hIcon As Long
   Dim nIconCount As Long
   nIconCount = ExtractIcon(0&, sIconFile, -1)
   If nIconCount > 0 Then
      VScroll1.Min = 0
      VScroll1.Max = nIconCount - 1
      VScroll1.Value = 0
      Label1.Caption = nIconCount & " 个图标"
      Call VScroll1_Change
   End If
End Sub

Private Sub VScroll1_Change()
   Dim index As Long
   Dim hIcon As Long
   index = VScroll1.Value
   If index <= VScroll1.Max Then
      Picture1.Cls
      hIcon = ExtractIcon(0&, sIconFile, index)
      Call DrawIcon(Picture1.hdc, 0, 0, hIcon)
      Call DestroyIcon(hIcon)
      Label2.Caption = "序号: " & index
   End If
End Sub

Private Sub VScroll1_Scroll()
   Dim index As Long
   Dim hIcon As Long
   index = VScroll1.Value
   If index <= VScroll1.Max Then
      Picture1.Cls
      hIcon = ExtractIcon(0&, sIconFile, index)
      Call DrawIcon(Picture1.hdc, 0, 0, hIcon)
      Call DestroyIcon(hIcon)
      Label2.Caption = "序号: " & index
   End If
End Sub

'-------------------------------------------
' 转载请注明出处
' 作者:唐细刚
' 邮箱:tanaya@163.com
'-------------------------------------------

阅读全文
0 0

相关文章推荐

img
取 消
img