I wrote the following sample to get you started:
delegate int 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, [Out] StringBuilder
lpString, int nMaxCount);
[DllImport("user32.dll")]
static extern int GetWindowTextLength(IntPtr hWnd);
[DllImport("user32.dll")]
static extern bool IsWindowVisible(IntPtr hWnd);
private static int PrintText(IntPtr hWnd, IntPtr lParam)
{
if (IsWindowVisible(hWnd))
{
int length = GetWindowTextLength(hWnd);
StringBuilder sb = new StringBuilder(length + 1);
int res = GetWindowText(hWnd, sb, sb.Capacity);
if (res > 0)
Console.WriteLine(sb.ToString());
}
return 1;
}
public static void Main(string[] args)
{
EnumWindowsProc cb = new EnumWindowsProc(PrintText);
EnumWindows(cb, IntPtr.Zero);
}
HTH, Jakob.
--
http://www.dotninjas.dk
http://www.powerbytes.dk
Tedmond said:
Dear all,
How can I get all the titles of all openning windows? I found a API in
win32 that called EnumWindows() but it returns only the windows handles, not
titles. How can I get the list just like the Applications tab in Windows Task
Manager?
Thanks,
Tedmond