1 /// <summary>
2 /// Gets the title text of a window.
3 /// </summary>
4 /// <param name="hwnd">Window handle</param>
5 /// <returns>Title text of window.</returns>
6 private String GetWindowTitle(int hwnd)
7 {
8 int length = GetWindowTextLength((IntPtr)hwnd);
9 StringBuilder windowTitle = new StringBuilder(length + 1);
10 GetWindowText((IntPtr)hwnd, windowTitle, windowTitle.Capacity);
11 return windowTitle.ToString();
12 }
13
14 [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
15 public static extern int GetWindowText(IntPtr hWnd, StringBuilder lpString, int nMaxCount);
16
17 [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
18 public static extern int GetWindowTextLength(IntPtr hWnd);