/// <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()); }
/// <summary> /// Finds all top-level windows that contain 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[] FindMainWindowsContains(string Classname, string WindowTitle) { if (Classname == null) { Classname = String.Empty; } if (WindowTitle == null) { WindowTitle = String.Empty; } List <IntPtr> hWnds = new List <IntPtr>(); Process[] procs = Process.GetProcesses(); foreach (Process proc in procs) { if (proc.MainWindowHandle != IntPtr.Zero) { if ((WindowTitle.Length > 0 && proc.MainWindowTitle.Contains(WindowTitle)) || (Classname.Length > 0 && Imports.GetClassName(proc.MainWindowHandle).Contains(Classname))) { hWnds.Add(proc.MainWindowHandle); } } } return(hWnds.ToArray()); }
/// <summary> /// Finds the first top-level window that contains 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 FindMainWindowContains(string Classname, string WindowTitle) { if (Classname == null) { Classname = String.Empty; } if (WindowTitle == null) { WindowTitle = String.Empty; } Process[] procs = Process.GetProcesses(); foreach (Process proc in procs) { if (proc.MainWindowHandle != IntPtr.Zero) { if ((WindowTitle.Length > 0 && proc.MainWindowTitle.Contains(WindowTitle)) || (Classname.Length > 0 && Imports.GetClassName(proc.MainWindowHandle).Contains(Classname))) { return(proc.MainWindowHandle); } } } return(IntPtr.Zero); }
/// <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); }