BrowserTools.Utils.GetWindowTitle C# (CSharp) Метод

GetWindowTitle() публичный статический Метод

public static GetWindowTitle ( IntPtr hWnd ) : string
hWnd System.IntPtr
Результат string
        public static string GetWindowTitle(IntPtr hWnd)
        {
            long titleLength = 0;

            SendMessageTimeout(
                hWnd,
                WM_GETTEXTLENGTH,
                IntPtr.Zero,
                IntPtr.Zero,
                SMTO_ABORTIFHUNG,
                SEND_MESSAGE_TIMEOUT,
                out titleLength
            );

            if (titleLength <= 0)
                return "";

            StringBuilder titleBuilder = new StringBuilder((int)titleLength + 1);

            SendMessageTimeout(
                hWnd,
                WM_GETTEXT,
                (IntPtr)titleBuilder.Capacity,
                titleBuilder,
                SMTO_ABORTIFHUNG,
                SEND_MESSAGE_TIMEOUT,
                IntPtr.Zero
            );

            return titleBuilder.ToString();
        }

Usage Example

Пример #1
0
        private static bool CheckWindowTitle(IntPtr hWnd, string windowMark)
        {
            string title = Utils.GetWindowTitle(hWnd).ToLower();

            if (!title.Contains(windowMark.ToLower()))
            {
                return(true);
            }

            uint processID = 0;

            GetWindowThreadProcessId(hWnd, out processID);

            string processName = Process.GetProcessById((int)processID).ProcessName.ToLower();

            // NOTE: IE has two windows with the same title. We are searching for the main window by its class name.
            if (processName == "iexplore" && !IsIEMainWindow(hWnd))
            {
                return(true);
            }

            // NOTE: MS Edge has different process ("applicationframehost" and "microsoftedgecp") with windows with the same title.
            // "microsoftedgecp" is the wrong one.
            if (processName == "microsoftedgecp")
            {
                return(true);
            }

            Console.Out.WriteLine(hWnd);
            Console.Out.WriteLine(processName);
            Environment.Exit((int)EXIT_CODES.SUCCESS);

            return(false);
        }