[DllImport("User32.dll")]
public static extern int EnumWindows(CallBack x, int y);//所有进程窗口
[DllImport("User32.dll")]
public extern static int GetWindowText(int hWnd, StringBuilder lpString, int nMaxCount);
public static bool Report(int hwnd, int lParam)
{
string name = "";
StringBuilder windowname = new StringBuilder(50000);
if (GetWindowText(hwnd, windowname, 50000) > 0)
{
name = windowname.ToString();
}
if (name.Length > 0)
{
MessageBox.Show("Window handle is :" + hwnd + "名字为" + name + "\n");
}
return true;
}
public delegate bool CallBack(int hwnd, int lParam);
private void Form1_Load(object sender, EventArgs e)
{
CallBack myCallBack = new CallBack(Report);
EnumWindows(myCallBack, 0);
}