コード例 #1
0
        public string GetText()
        {
            int length = User32Native.GetWindowTextLength(Handle);

            if (length == 0)
            {
                return(string.Empty);
            }

            var text = new StringBuilder(length * 2);

            User32Native.GetWindowText(Handle, text, text.Capacity);

            return(text.ToString());
        }
コード例 #2
0
        public static string GetWindowText(HWND window)
        {
            var length = User32Native.GetWindowTextLength(window) + 1;
            var sb     = new StringBuilder(length);

            User32Native.GetWindowText(window, sb, length);
            try
            {
                return(sb.ToString());
            }
            finally
            {
                sb.Clear();
            }
        }