/// <summary>
        ///     Returns the caption of a window by given HWND identifier.
        /// </summary>
        public static string GetWindowText(IntPtr hWnd)
        {
            var title       = new StringBuilder(MaxTitle);
            var titleLength = Win32Interop.GetWindowText(hWnd, title, title.Capacity + 1);

            title.Length = titleLength;

            return(title.ToString());
        }
Beispiel #2
0
 public static IEnumerable <string> WindowTitlesForClass(string className)
 {
     foreach (var windowHandle in WindowsMatchingClassName(className))
     {
         var length = Win32Interop.GetWindowTextLength(windowHandle);
         var sb     = new StringBuilder(length + 1);
         Win32Interop.GetWindowText(windowHandle, sb, sb.Capacity);
         yield return(sb.ToString());
     }
 }
Beispiel #3
0
 public static IEnumerable <IntPtr> FindWindowByTitle(this IEnumerable <IntPtr> handles, string title)
 {
     return(handles.Where(windowHandle =>
     {
         var length = Win32Interop.GetWindowTextLength(windowHandle);
         var sb = new StringBuilder(length + 1);
         Win32Interop.GetWindowText(windowHandle, sb, sb.Capacity);
         if (sb.ToString() == title)
         {
             return true;
         }
         return false;
     }));
 }