在C#中怎样才能得到一个文件的图标? 我用这个可以SHGetFileInfohttp://www.dotnet247.com/247reference/msgs/13/66688.aspx 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 回去找着写了个,给你贴上来.using System;using System.Runtime.InteropServices;using System.Drawing;namespace WindowsAppTmp{ public class ExtractIcon { [DllImport("Shell32.dll")] private static extern int SHGetFileInfo ( string pszPath, uint dwFileAttributes, out SHFILEINFO psfi, uint cbfileInfo, SHGFI uFlags ); [StructLayout(LayoutKind.Sequential)] private struct SHFILEINFO { public SHFILEINFO(bool b) { hIcon=IntPtr.Zero;iIcon=0;dwAttributes=0;szDisplayName="";szTypeName=""; } public IntPtr hIcon; public int iIcon; public uint dwAttributes; [MarshalAs(UnmanagedType.LPStr, SizeConst=260)] public string szDisplayName; [MarshalAs(UnmanagedType.LPStr, SizeConst=80)] public string szTypeName; }; private ExtractIcon() { } private enum SHGFI { SmallIcon = 0x00000001, LargeIcon = 0x00000000, Icon = 0x00000100, DisplayName = 0x00000200, Typename = 0x00000400, SysIconIndex = 0x00004000, UseFileAttributes = 0x00000010 } public static Icon GetIcon(string strPath, bool bSmall) { SHFILEINFO info = new SHFILEINFO(true); int cbFileInfo = Marshal.SizeOf(info); SHGFI flags; if (bSmall) flags = SHGFI.Icon|SHGFI.SmallIcon|SHGFI.UseFileAttributes; else flags = SHGFI.Icon|SHGFI.LargeIcon|SHGFI.UseFileAttributes; SHGetFileInfo(strPath, 256, out info,(uint)cbFileInfo, flags); return Icon.FromHandle(info.hIcon); } }} 生成的类库文件如何才能显示注释 C#如何引用数组 谁能给据个例子,Icon(Type, string);,谢谢 excel插入的问题~~急~~ 水晶报表3层子报表的实现?希望高手解答. 关于添加interface的简单问题,请高手指点! C# Thread.sleep()后 无法继续运行 关于object.Equals()的疑问? 请教advapi32.dll 是什么?谢谢各位高手 XMPP服务端压缩支持 哪儿有c#基础教程下啊!!!谢谢 在C#如何实现实现C++中的SetRop2(hdc,R2_XORPEN),up有分
using System.Runtime.InteropServices;
using System.Drawing;
namespace WindowsAppTmp
{
public class ExtractIcon
{
[DllImport("Shell32.dll")]
private static extern int SHGetFileInfo
(
string pszPath,
uint dwFileAttributes,
out SHFILEINFO psfi,
uint cbfileInfo,
SHGFI uFlags
); [StructLayout(LayoutKind.Sequential)]
private struct SHFILEINFO
{
public SHFILEINFO(bool b)
{
hIcon=IntPtr.Zero;iIcon=0;dwAttributes=0;szDisplayName="";szTypeName="";
}
public IntPtr hIcon;
public int iIcon;
public uint dwAttributes;
[MarshalAs(UnmanagedType.LPStr, SizeConst=260)]
public string szDisplayName;
[MarshalAs(UnmanagedType.LPStr, SizeConst=80)]
public string szTypeName;
}; private ExtractIcon()
{
} private enum SHGFI
{
SmallIcon = 0x00000001,
LargeIcon = 0x00000000,
Icon = 0x00000100,
DisplayName = 0x00000200,
Typename = 0x00000400,
SysIconIndex = 0x00004000,
UseFileAttributes = 0x00000010
}
public static Icon GetIcon(string strPath, bool bSmall)
{
SHFILEINFO info = new SHFILEINFO(true);
int cbFileInfo = Marshal.SizeOf(info);
SHGFI flags;
if (bSmall)
flags = SHGFI.Icon|SHGFI.SmallIcon|SHGFI.UseFileAttributes;
else
flags = SHGFI.Icon|SHGFI.LargeIcon|SHGFI.UseFileAttributes; SHGetFileInfo(strPath, 256, out info,(uint)cbFileInfo, flags);
return Icon.FromHandle(info.hIcon);
}
}
}