C#中ListView添加系统文件图标
来源:互联网 发布:淘宝怎么增加产品类别 编辑:程序博客网 时间:2024/04/27 03:23
using System.Runtime.InteropServices;
public static uint SHGFI_ICON = 0x100;
public static uint SHGFI_DISPLAYNAME = 0x200;
public static uint SHGFI_TYPENAME = 0x400;
public static uint SHGFI_ATTRIBUTES = 0x800;
public static uint SHGFI_ICONLOCATION = 0x1000;
public static uint SHGFI_EXETYPE = 0x2000;
public static uint SHGFI_SYSICONINDEX = 0x4000;
public static uint SHGFI_LINKOVERLAY = 0x8000;
public static uint SHGFI_SELECTED = 0x10000;
public static uint SHGFI_LARGEICON = 0x0;
public static uint SHGFI_SMALLICON = 0x1;
public static uint SHGFI_OPENICON = 0x2;
public static uint SHGFI_SHELLICONSIZE = 0x4;
public static uint SHGFI_PIDL = 0x8;
public static uint SHGFI_USEFILEATTRIBUTES = 0x10;
public static uint FILE_ATTRIBUTE_NORMAL = 0x80;
public static uint LVM_FIRST = 0x1000;
public static uint LVM_SETIMAGELIST = LVM_FIRST + 3;
public static uint LVSIL_NORMAL = 0;
public static uint LVSIL_SMALL = 1;
[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;
}
[DllImport("User32.DLL")]
public static extern int SendMessage(IntPtr hWnd,
uint Msg, IntPtr wParam, IntPtr lParam);
public void ListViewSysImages(ListView AListView)
{
SHFILEINFO vFileInfo = new SHFILEINFO();
IntPtr vImageList = SHGetFileInfo("", 0, ref vFileInfo,
Marshal.SizeOf(vFileInfo), SHGFI_SHELLICONSIZE |
SHGFI_SYSICONINDEX | SHGFI_LARGEICON);
SendMessage(AListView.Handle, LVM_SETIMAGELIST, (IntPtr)LVSIL_NORMAL,
vImageList);
vImageList = SHGetFileInfo("", 0, ref vFileInfo,
Marshal.SizeOf(vFileInfo), SHGFI_SHELLICONSIZE |
SHGFI_SYSICONINDEX | SHGFI_SMALLICON);
SendMessage(AListView.Handle, LVM_SETIMAGELIST, (IntPtr)LVSIL_SMALL,
vImageList);
}
public int FileIconIndex(string AFileName)
{
SHFILEINFO vFileInfo = new SHFILEINFO();
SHGetFileInfo(AFileName, 0, ref vFileInfo,
Marshal.SizeOf(vFileInfo), SHGFI_SYSICONINDEX);
return vFileInfo.iIcon;
}
private void button1_Click(object sender, EventArgs e)
{
ListViewSysImages(listView1);
listView1.Items.Add("temp.txt", FileIconIndex(@"c:/temp/temp.txt"));
}
- C#中ListView添加系统文件图标
- C#中ListView添加系统文件图标
- [c# WinForm]往ListView中添加大量的不同图标
- Delphi 中 listview 根据文件扩展名 设置系统图标
- C# 获取系统文件图标
- c# 获取系统文件图标
- 在C#中获取各种文件的系统图标
- C# ListView实例:文件图标显示
- Listview中动态添加多个EXE文件的图标和文件名
- 在 ListView 中显示文件和文件夹系统图标的实现类
- c#使用系统ImageList显示文件图标
- C#获取系统文件及文件夹图标
- C# 系统应用之ListView控件 (三).添加ContextMenuStrip右键菜单打开删除文件
- C# 在listview 中添加进度条
- c#中listview控件如何添加信息
- [WinForm]C# Listview中添加Button
- win32 listview控件添加图标
- 添加系统栏图标
- Jmeter常用组件介绍
- 木马编程天天练 开始第1天 获取系统信息
- 关于WeifenLuo.WinFormsUI.Docking控件
- 委托
- ugg boots
- C#中ListView添加系统文件图标
- 如何更改ALERT LABEL提示信息
- .Net C# Web Service 中的cacheDuration解释
- (十三)有一点心动 - 1
- 为Struts应用配置Web.xml文件
- 无需刻盘,在windows XP/VISTA/7下,硬盘安装ubuntu
- Android onTouch事件与ScrollView冲突
- 网上SQL问题连载6
- Jmeter函数