我在下面使用了这段代码,我得到了在窗口中运行的所有应用程序。
现在我只想获取.Net (.exe) 的应用程序。你能帮助我吗?
public Form1()
{
InitializeComponent();
EnumWindows(new WindowEnumCallback(this.AddWnd), 0);
}
public delegate bool WindowEnumCallback(int hwnd, int lparam);
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool EnumWindows(WindowEnumCallback lpEnumFunc, int lParam);
[DllImport("user32.dll")]
public static extern void GetWindowText(int h, StringBuilder s, int nMaxCount);
[DllImport("user32.dll")]
public static extern bool IsWindowVisible(int h);
private List<string> Windows = new List<string>();
private bool AddWnd(int hwnd, int lparam)
{
if (IsWindowVisible(hwnd))
{
StringBuilder sb = new StringBuilder(255);
GetWindowText(hwnd, sb, sb.Capacity);
Windows.Add(sb.ToString());
txtTest.Text += hwnd.ToString()+" ";
lst.Items.Add(sb.ToString());
}
return true;
}