这个是源码:是在一个窗体中拖入一个exe文件可以获取,你可以修改一下
[DllImport("Shell32.dll")]//引入"Shell32.dll"
private static extern int SHGetFileInfo(string pszPath, uint dwFileAttributes, out SHFILEINFO psfi, uint cbfileInfo, SHGFI uFlags);
[StructLayout(LayoutKind.Sequential)]
struct SHFILEINFO
{
public IntPtr hIcon;
public int iIcon;
public uint attributes;
[MarshalAs(UnmanagedType.LPStr, SizeConst = 260)]
public string szDisplayName;
[MarshalAs(UnmanagedType.LPStr, SizeConst = 80)]
public string szTypeName;
public SHFILEINFO(bool b)
{
hIcon = IntPtr.Zero;
iIcon = 0;
attributes = 0;
szDisplayName = "";
szTypeName = "";
}
}
private enum SHGFI
{
SmallIcon = 0x00000001,
LargeIcon = 0x00000020,
Icon = 0x00000100,
DisplayName = 0x00000200,
TypeName = 0x00000400,
SysIconIndex = 0x00004000,
UseFileAttributes = 0x00000010
}
public static Icon GetIcon(string path, bool small)
{
SHFILEINFO info = new SHFILEINFO(true);
int cbFileInfo = Marshal.SizeOf(info);
SHGFI flags;
if (small)
{
flags = SHGFI.Icon | SHGFI.SmallIcon | SHGFI.UseFileAttributes;
}
else
{
flags = SHGFI.Icon | SHGFI.LargeIcon | SHGFI.UseFileAttributes;
}
SHGetFileInfo(path, 256, out info, (uint)cbFileInfo, flags);
return Icon.FromHandle(info.hIcon);
}
答案补充
public static void GetIcon(string path)
{
SHFILEINFO info = new SHFILEINFO(true);
int cbFileInfo = Marshal.SizeOf(info);
SHGFI flags;
flags = SHGFI.Icon | SHGFI.SmallIcon | SHGFI.UseFileAttributes;
SHGetFileInfo(path, 256, out info, (uint)cbFileInfo,flags);
答案补充
MessageBox.Show(info.attributes.ToString());
MessageBox.Show(info.hIcon.T oString());
MessageBox.Show(info.iIcon.ToString());
MessageBox.Show(info.szDisplayName);
MessageBox.Show(info.szTypeName);
}
答案补充
void Form1_DragEnter(object sender, System.Windows.Forms.DragEventArgs e) {
if (e.Data.GetDataPresent(DataFormats.FileDrop))
{
e.Effect = DragDropEffects.Copy;
}
else
{
e.Effect = DragDropEffects.None;
}
icon图标库}
答案补充
void Form1_DragDrop(object sender, System.Windows.Forms.DragEventArgs e) {
string path = ((System.Array)e.Data.GetData(DataFormats.FileDrop)).GetValue(0).ToString();
this.pictureBox1.Image = GetIcon(path, false).ToBitmap();
}
终于Over了,受不了问问了

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。