![]() |
|
|||||||
| 論壇說明 | 標記討論區已讀 |
|
歡迎您來到『史萊姆論壇』 ^___^ 您目前正以訪客的身份瀏覽本論壇,訪客所擁有的權限將受到限制,您可以瀏覽本論壇大部份的版區與文章,但您將無法參與任何討論或是使用私人訊息與其他會員交流。若您希望擁有完整的使用權限,請註冊成為我們的一份子,註冊的程序十分簡單、快速,而且最重要的是--註冊是完全免費的! 請點擊這裡:『註冊成為我們的一份子!』 |
![]() |
|
|
主題工具 | 顯示模式 |
|
|
|
|
#1 (permalink) |
|
版區管理員
![]() |
語法:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Toolstoy
{
public partial class Form1 : Form
{
[StructLayout(LayoutKind.Sequential)]
public struct SHFILEINFO
{
public IntPtr hIcon;
public int iIcon;
public uint dwAttributes;
public string szDisplayName;
public string szTypeName;
};
const uint SHGFI_ICON = 0x00000100;
const uint SHGFI_LARGEICON = 0x00000000;
const uint SHGFI_SMALLICON = 0x00000001;
const uint SHGFI_SYSICONINDEX = 0x4000;
[DllImport("shell32.dll")]
public static extern IntPtr SHGetFileInfo(string filename, uint fileattributes, ref SHFILEINFO shfi, uint cbfi, uint flag);
[DllImport("user32.dll")]
public static extern bool DestroyIcon(IntPtr hIcon);
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
listView1.Items.Clear();
listView1.Columns.Add("名稱", 300, HorizontalAlignment.Left);
listView1.Columns.Add("大小", 100, HorizontalAlignment.Right);
listView1.View = View.Details;
//DirectoryInfo selDir = new DirectoryInfo(Environment.CurrentDirectory);
DirectoryInfo selDir = new DirectoryInfo(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments));
//this.Text=Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
DirectoryInfo[] listDir;
FileInfo[] listFile;
try { }
catch { }
listDir = selDir.GetDirectories();
listFile = selDir.GetFiles();
foreach (DirectoryInfo d in listDir)
{
SHFILEINFO shfi = new SHFILEINFO();
SHGetFileInfo(d.FullName, 0, ref shfi, (uint)Marshal.SizeOf(shfi), SHGFI_ICON | SHGFI_SMALLICON);
Icon myicon = (Icon)Icon.FromHandle(shfi.hIcon).Clone();
DestroyIcon(shfi.hIcon);
imageList1.Images.Add("dir", myicon);
ListViewItem lv = new ListViewItem(d.Name);
lv.ImageKey = "dir";
listView1.Items.Add(lv);
}
foreach (FileInfo d in listFile)
{
SHFILEINFO shfi = new SHFILEINFO();
SHGetFileInfo(d.FullName, 0, ref shfi, (uint)Marshal.SizeOf(shfi), SHGFI_ICON | SHGFI_SMALLICON);
Icon myicon = (Icon)Icon.FromHandle(shfi.hIcon).Clone();
DestroyIcon(shfi.hIcon);
imageList1.Images.Add(d.Extension, myicon);
ListViewItem lv = new ListViewItem(d.Name);
string num = d.Length.ToString();
lv.ImageKey = d.Extension;
lv.SubItems.Add(num);
listView1.Items.Add(lv);
}
}
}
}
![]() |
|
__________________ 『唸金母心咒:嗡。金母。悉地。吽。』 持此咒者,可免一切瘟疫,一切瘟神抱頭四散。 魔術就是欣賞神奇的效果 如果魔術的秘密被破解了 那魔術就失去欣賞的價值 |
|
|
|
送花文章: 1550,
|