Files
mirror-processhacker/trunk/ProcessHacker/Forms/HandleStatisticsWindow.cs
T
wj32 91d4e3d5d4 #2831605 - "Add handle count by type to process properties handle tab"
git-svn-id: svn://svn.code.sf.net/p/processhacker/code@1738 21ef857c-d57f-4fe0-8362-d861dc6d29cd
2009-08-23 10:05:24 +00:00

72 lines
2.0 KiB
C#

using System.Collections.Generic;
using System.Windows.Forms;
using ProcessHacker.Common;
using ProcessHacker.Native;
using ProcessHacker.Native.Objects;
using ProcessHacker.Native.Security;
using ProcessHacker.UI;
namespace ProcessHacker
{
public partial class HandleStatisticsWindow : Form
{
private int _pid;
public HandleStatisticsWindow(int pid)
{
InitializeComponent();
this.AddEscapeToClose();
_pid = pid;
listTypes.SetDoubleBuffered(true);
listTypes.SetTheme("explorer");
listTypes.AddShortcuts();
listTypes.ContextMenu = listTypes.GetCopyMenu();
var typeStats = new Dictionary<string, int>();
using (var phandle = new ProcessHandle(pid, ProcessAccess.DupHandle))
{
var handles = Windows.GetHandles();
foreach (var handle in handles)
{
if (pid != -1 && handle.ProcessId != pid)
continue;
ObjectInformation info;
if (pid != -1)
{
info = handle.GetHandleInfo(phandle, false);
}
else
{
info = handle.GetHandleInfo(false);
}
if (typeStats.ContainsKey(info.TypeName))
typeStats[info.TypeName]++;
else
typeStats.Add(info.TypeName, 1);
}
}
foreach (var pair in typeStats)
{
listTypes.Items.Add(new ListViewItem(new string[]
{
pair.Key,
pair.Value.ToString("N0")
}));
}
}
private void buttonClose_Click(object sender, System.EventArgs e)
{
this.Close();
}
}
}