示例#1
0
        public static string GetWindowTitle(IntPtr hWnd)
        {
            int           titleLength = NativeMethods.GetWindowTextLength(hWnd);
            StringBuilder builder     = new(titleLength);

            NativeMethods.GetWindowText(hWnd, builder, titleLength + 1);
            return(builder.ToString());
        }
        public static string GetWindowTitle(IntPtr hWnd)
        {
            int           titleLength = NativeMethods.GetWindowTextLength(hWnd);
            StringBuilder builder     = new(titleLength);
            int           result      = NativeMethods.GetWindowText(hWnd, builder, titleLength + 1);

            if (result < 0)
            {
                throw new Exception("Unable to get window title");
            }
            return(builder.ToString());
        }