0

我在 C# 中找到了很多示例,但无论我尝试什么,我都无法在 VB 中完成这项工作。我可以提取的唯一图标是代表没有关联的文件的图标。如果有更好的方法,我也愿意。这是代码:

宣言:

Declare Auto Function ExtractAssociatedIcon Lib "shell32.dll" Alias "ExtractAssociatedIconA" (ByVal hInst As IntPtr, ByVal lpIconPat As String, ByRef lpiIcon As Integer) As IntPtr

其他代码:

Dim handle As IntPtr
Dim li As ListViewItem
Dim modul As System.Reflection.Module()

For Each filename As FileInfo In quotesFolder.GetFiles()

    If ImgLstQuotes.Images.ContainsKey(filename.Extension) Then
    Else
        modul = System.Reflection.Assembly.GetExecutingAssembly.GetModules()
        'handle = ExtractAssociatedIcon(Marshal.GetHINSTANCE(modul(0)), filename.FullName, -1) 'doesnt work

        'handle = ExtractAssociatedIcon(IntPtr.Zero(), filename.FullName, -1)  'doesn't work
        handle = ExtractAssociatedIcon(Process.GetCurrentProcess().Handle, filename.FullName, -1)  'doesn't work
        ImgLstQuotes.Images.Add(filename.Extension, Drawing.Icon.FromHandle(handle))
    End If

    li = LstVwQuotes.Items.Add(filename.Name, filename.Extension)
    li.Name = UCase(filename.Name)
    li.SubItems.Add(filename.LastWriteTime)

Next 

提前致谢!

4

0 回答 0