Beispiel #1
0
        /// <summary>
        /// Finds all windows, parent and child, that match the supplied classname or window title.
        /// </summary>
        /// <param name="Classname">Classname of the window(s) to match.</param>
        /// <param name="WindowTitle">Window title of the window(s) to match.</param>
        /// <returns>Returns an array of window handles.</returns>
        public static IntPtr[] FindWindows(string Classname, string WindowTitle)
        {
            if (Classname == null)
            {
                Classname = String.Empty;
            }
            if (WindowTitle == null)
            {
                WindowTitle = String.Empty;
            }

            List <IntPtr> hWnds = new List <IntPtr>();

            lock (lWindowsLock)
            {
                if (!_EnumWindows())
                {
                    return(null);
                }

                foreach (IntPtr hWnd in lWindows)
                {
                    if ((WindowTitle.Length > 0 && Imports.GetWindowTitle(hWnd) == WindowTitle) ||
                        (Classname.Length > 0 && Imports.GetClassName(hWnd) == Classname))
                    {
                        hWnds.Add(hWnd);
                    }
                }
            }

            return(hWnds.ToArray());
        }
Beispiel #2
0
        /// <summary>
        /// Finds the first window, parent and child, that contains either of the supplied classname or window title.
        /// </summary>
        /// <param name="Classname">Classname of the window(s) to match.</param>
        /// <param name="WindowTitle">Window title of the window(s) to match.</param>
        /// <returns>Returns a window handle.</returns>
        public static IntPtr FindWindowContains(string Classname, string WindowTitle)
        {
            if (Classname == null)
            {
                Classname = String.Empty;
            }
            if (WindowTitle == null)
            {
                WindowTitle = String.Empty;
            }

            lock (lWindowsLock)
            {
                if (!_EnumWindows())
                {
                    return(IntPtr.Zero);
                }


                foreach (IntPtr hWnd in lWindows)
                {
                    if ((WindowTitle.Length > 0 && Imports.GetWindowTitle(hWnd).Contains(WindowTitle)) ||
                        (Classname.Length > 0 && Imports.GetClassName(hWnd).Contains(Classname)))
                    {
                        return(hWnd);
                    }
                }
            }

            return(IntPtr.Zero);
        }