using System.Text;
using System.Runtime.InteropServices;
delegate bool EnumWindowsProc(IntPtr hWnd, IntPtr lParam);
[DllImport("user32.dll")]
static extern bool EnumWindows(EnumWindowsProc lpEnumFunc, IntPtr lParam);
[DllImport("user32.dll")]
static extern int GetWindowText(IntPtr hWnd, StringBuilder lpString, int nMaxCount);
[DllImport("user32.dll")]
static extern int GetWindowTextLength(IntPtr hWnd);
private bool EnumWin(IntPtr hWnd, IntPtr lParam)
{
int sz = GetWindowTextLength(hWnd);
StringBuilder sb = new StringBuilder(sz + 1);
GetWindowText(hWnd,sb,sb.Capacity);
if (sb.Length > 0) listBox1.Items.Add(sb.ToString());
return true;
}
private EnumWindowsProc lpEnumFunc = null;
private void button1_Click(object sender, System.EventArgs e)
{
lpEnumFunc = new EnumWindowsProc(EnumWin);
EnumWindows(lpEnumFunc,IntPtr.Zero);
}
|