7,655
社区成员
发帖
与我相关
我的任务
分享
<DllImport("Shell32.dll")> _
Public Shared Function SHGetFileInfo(pszPath As String, dwFileAttributes As UInteger, ByRef psfi As SHFILEINFO, cbfileInfo As Integer, uFlags As UInteger) As IntPtr
End Function
Public Structure SHFILEINFO
Public hIcon As IntPtr
Public iIcon As Integer
Public dwAttributes As Integer
Public szDisplayName As String
Public szTypeName As String
End Structure
[DllImport("Shell32.dll")]
public static extern IntPtr SHGetFileInfo(string pszPath,
uint dwFileAttributes, ref SHFILEINFO psfi,
int cbfileInfo, uint uFlags);
public struct SHFILEINFO
{
public IntPtr hIcon;
public int iIcon;
public int dwAttributes;
public string szDisplayName;
public string szTypeName;
}
public struct SHFILEINFO
{
public IntPtr hIcon;
public int iIcon;
public uint dwAttributes;
public string szDisplayName;
public string szTypeName;
}
namespace TEST
{
static class Program
{
static uint SHGFI_ICON = 0x000000100; // get icon,must be
static uint SHGFI_LARGEICON = 0x000000000; // get large icon
static uint SHGFI_SMALLICON = 0x000000001; // get small icon
/// <summary>
/// SHGetFileInfo 获取文件信息(包括图标)
/// </summary>
[System.Runtime.InteropServices.DllImport("Shell32.dll")]
private static extern uint SHGetFileInfo(string pszPath,uint dwFileAttributes, ref SHFILEINFO psfi,uint cbfileInfo, uint uFlags);
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[MTAThread]
static void Main()
{
SHFILEINFO FI=new SHFILEINFO();
SHGetFileInfo("路径", 0, ref FI, (uint)System.Runtime.InteropServices.Marshal.SizeOf(FI), SHGFI_ICON|SHGFI_SMALLICON);
//SHGetFileInfo("路径", 0, ref FI, (uint)System.Runtime.InteropServices.Marshal.SizeOf(FI), SHGFI_ICON|SHGFI_LARGEICON);
//其中,FI.hIcon即是图标句柄
}
}
}