这就是我得到所有工作流程的方式:
Process[] processlist = Process.GetProcesses();
foreach (Process theprocess in processlist)
{
listBox1.Items.Add(theprocess.ProcessName);
}
这就是我在目录中获取文件的方式:
foreach (System.IO.FileInfo file in dir.GetFiles())
{
}
我想在每个进程的目录中获取文件。这是我使用的方法:
ListView listView1;
ImageList imageList1;
public void ExtractAssociatedIconEx()
{
listView1 = new ListView();
imageList1 = new ImageList();
listView1.Location = new Point(37, 12);
listView1.Size = new Size(151, 262);
listView1.SmallImageList = imageList1;
listView1.View = View.SmallIcon;
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.Add(this.listView1);
this.Text = "Form1";
System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(@"c:\");
ListViewItem item;
listView1.BeginUpdate();
foreach (System.IO.FileInfo file in dir.GetFiles())
{
Icon iconForFile = SystemIcons.WinLogo;
item = new ListViewItem(file.Name, 1);
iconForFile = Icon.ExtractAssociatedIcon(file.FullName);
if (!imageList1.Images.ContainsKey(file.Extension))
{
iconForFile = System.Drawing.Icon.ExtractAssociatedIcon(file.FullName);
imageList1.Images.Add(file.Extension, iconForFile);
}
item.ImageKey = file.Extension;
listView1.Items.Add(item);
}
listView1.EndUpdate();
}
但是,我不想只获取C:\中文件的图标,而是想要获取当前正在运行的进程的图标。
基于此:
foreach (Process in Process.GetProcesses())
{
string filePath = process.Modules[0].FileName;
Icon fileIcon = Icon.ExtractAssociatedIcon(filePath);
...
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句