如何在VB中用API获得EXE文件图标并显示在Picture控

页面导航:首页 > 软件编程 > vb.net > 如何在VB中用API获得EXE文件图标并显示在Picture控

如何在VB中用API获得EXE文件图标并显示在Picture控

来源: 作者: 时间:2016-02-05 12:32 【

Option ExplicitPrivate Declare Function DrawIcon Lib "user32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal hIcon As Long) As LongPrivate Declare Function Ex

 

 

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.dll" Alias "ExtractIconA" (ByVal hInst As Long, ByVal lpszExeFileName As String, ByVal nIconIndex As Long) As Long

Private Sub Command1_Click()

Dim total As Long

Dim p(50) As Long

Dim i As Integer

Me.Picture1.Cls

Me.CommonDialog1.Filter = "图标|*.Exe;*.Ico;*.Dll"

Me.CommonDialog1.ShowOpen

If Dir(Me.CommonDialog1.filename) <> "" Then

If ExtractIcon(App.hInstance, Me.CommonDialog1.filename, -1) = 0 Then 如果没有图标

MsgBox "No Icon!"

Else

total = ExtractIcon(App.hInstance, Me.CommonDialog1.filename, -1)

取得总图标数

For i = 0 To total - 1

p(i) = ExtractIcon(App.hInstance, Me.CommonDialog1.filename, i) 读取每个图标

Next i

For i = 0 To total - 1 依次显示每个图标

DrawIcon Picture1.hdc, 34 * i, 0, p(i)

Next i

End If

End If

End Sub

 

 

Tags:

相关文章

    文章评论

    最 近 更 新
    热 点 排 行
    Js与CSS工具
    代码转换工具
    
    <