我在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
提前致谢!