Пример #1
0
        //****************************************************************************
        //See: https://stackoverflow.com/questions/42449050/cant-get-a-window-handle
        //****************************************************************************
        private static IntPtr[] FindChildWindows(IntPtr display, IntPtr window,
                                                 string title, ref List <IntPtr> windows)
        {
            IntPtr rootWindow;
            IntPtr parentWindow;

            IntPtr[] childWindows = new IntPtr[0];

            int childWindowsLength;

            X11lib.XQueryTree(display, window,
                              out rootWindow, out parentWindow,
                              out childWindows, out childWindowsLength);

            childWindows = new IntPtr[childWindowsLength];

            X11lib.XQueryTree(display, window,
                              out rootWindow, out parentWindow,
                              out childWindows, out childWindowsLength);

            string windowFetchedTitle;

            X11lib.XFetchName(display, window, out windowFetchedTitle);

            if (title == windowFetchedTitle &&
                !windows.Contains(window))
            {
                windows.Add(window);
            }

            for (int childWindowsIndexer = 0;
                 childWindowsIndexer < childWindows.Length;
                 childWindowsIndexer++)
            {
                IntPtr childWindow = childWindows[childWindowsIndexer];

                string childWindowFetchedTitle;

                X11lib.XFetchName(display, childWindow,
                                  out childWindowFetchedTitle);

                if (title == childWindowFetchedTitle &&
                    !windows.Contains(childWindow))
                {
                    windows.Add(childWindow);
                }

                FindChildWindows(display, childWindow, title, ref windows);
            }

            windows.TrimExcess();

            return(windows.ToArray());
        }