public static IntPtr WaitToFocus(string caption, int maxWaitSec) { IntPtr win = IntPtr.Zero; DateTime start = DateTime.Now; while (true) { win = WindowAttrib.GetForegroundWindow(); string text = WindowAttrib.GetWindowText(win); if (text.Contains(caption)) { return(win); } Thread.Sleep(defaultSleep); if ((DateTime.Now - start).TotalSeconds > maxWaitSec) { break; } } return(win); }
public static List <IntPtr> GetAllThreadWindows(string processName, bool onlyVisible) { List <IntPtr> result = new List <IntPtr>(); Process process = null; Process[] p = Process.GetProcessesByName(processName); if (p.Count() > 0) { process = p[0]; } else { return(result); } result.AddRange(EnumerateProcessWindowHandles(process.Id)); for (int i = 0; i < result.Count; i++) { if (onlyVisible && !WindowAttrib.IsWindowVisible(result[i])) { result.RemoveAt(i); i--; } } return(result); }
public static bool ClickOnButton(string processName, string buttonText, bool exact) { List <IntPtr> wins = WindowSearch.GetAllWindowsByText(processName, buttonText, exact); wins.AddRange(WindowSearch.GetAllWindowsByCaption(processName, buttonText, exact)); wins = wins.Distinct().ToList(); if (wins.Count == 0) { return(false); } IntPtr win = wins.Last(); //WindowManipulation.SetForegroundWindow(win); Thread.Sleep(500); //WindowManipulation.SetForegroundWindow(win); Rectangle rect = WindowAttrib.GetWindowRect(win); rect.Location = new Point(rect.X + 7, rect.Y + 7); rect.Size = new Size(rect.Width - 10, rect.Height - 10); ClickOnRect(rect, 1); Thread.Sleep(200); return(true); }
/// <summary>"Доїжджає" курсором до заданого прямокутника</summary> /// <param name="box">Прямокутник</param> /// <param name="speed">Швидкість переміщення</param> /// <param name="clicks">Кількість натискань на клавішу миші після руху</param> /// <remarks>** НЕ ТЕСТОВАНО **</remarks> public static void ClickOnRect(IntPtr win, Rectangle rect, int clicks) { Rectangle winRect = WindowAttrib.GetClientRect(win); Rectangle clickRect = new Rectangle(rect.X + winRect.X, rect.Y + winRect.Y, rect.Width, rect.Height); ClickOnRect(clickRect, clicks); }
public static void ResizeWindow(IntPtr win, int width, int height) { if (win != IntPtr.Zero) { Rectangle rect = WindowAttrib.GetWindowRect(win); MoveWindow(win, rect.X, rect.Y, width, height, true); } }
public static void MoveWindow(IntPtr win, int x, int y) { if (win != IntPtr.Zero) { Rectangle rect = WindowAttrib.GetWindowRect(win); MoveWindow(win, x, y, rect.Width, rect.Height, true); } }
public static List <IntPtr> GetListViewItems(IntPtr listView) { var header = SendMessage(listView, (int)LVM.GETHEADER, 0, IntPtr.Zero); Console.WriteLine(header); Console.WriteLine(WindowAttrib.GetWindowText(header)); return(new List <IntPtr>()); }
/// <summary> /// Натиснути ліву клавішу миші /// </summary> /// <param name="win">Вікно</param> /// <param name="time">Час зажимання</param> /// <param name="x">Розташування курсора (відносна координата у вікні)</param> /// <param name="y">Розташування курсора (відносна координата у вікні)</param> public static void PressLeftMouseButton(IntPtr win, int time, int x, int y) { if (win != IntPtr.Zero) { Rectangle rect = WindowAttrib.GetClientRect(win); x += rect.X; y += rect.Y; } SetCursorPos(x, y); PressLeftMouseButton(time); }
public static IntPtr GetWindowByCaption(string processName, string windowCaption, bool exact) { List <IntPtr> wins = GetAllWindowsByProcess(processName, true); foreach (IntPtr w in wins) { string text = WindowAttrib.GetWindowCaption(w); if ((exact && text == windowCaption) || (!exact && text.Contains(windowCaption))) { return(w); } } return(IntPtr.Zero); }
public static IntPtr GetChildWindowByText(IntPtr parent, string windowText, bool exact) { var wins = WindowSearch.GetChildWindows(parent); foreach (IntPtr w in wins) { string text = WindowAttrib.GetWindowText(w); if ((exact && text == windowText) || (!exact && text.Contains(windowText))) { return(w); } } return(IntPtr.Zero); }
/// <summary>Пошук вікна за назвою процесу та заголовком вікна (з використанням GetAllThreadWindows)</summary> /// <param name="processName">Назва процесу</param> /// <param name="windowText">Заголовок вікна</param> public static IntPtr GetThreadWindowByText(string processName, string windowText, bool exact, bool onlyVisible) { List <IntPtr> wins = GetAllThreadWindows(processName, onlyVisible); foreach (IntPtr w in wins) { string text = WindowAttrib.GetWindowText(w); if ((exact && text == windowText) || (!exact && text.Contains(windowText))) { return(w); } } return(IntPtr.Zero); }
public static void ResizeWindow_Hard(IntPtr win, int width, int height, int xOffset, int yOffset) { if (win != IntPtr.Zero) { SetForegroundWindow(win); Rectangle rect = WindowAttrib.GetWindowRect(win); int dx = width - rect.Width; int dy = height - rect.Height; Point p = new Point(rect.Location.X + rect.Width - xOffset, rect.Location.Y + rect.Height - yOffset); MouseKeyboard.Drag(p, dx, dy); } }
/// <summary>Повертає усі вікна, що належать заданому процесу</summary> /// <param name="processName">Назва процесу</param> /// <param name="onlyVisible">Лише видимі вікна</param> public static List <IntPtr> GetAllWindowsByProcess(string processName, bool onlyVisible) { List <IntPtr> result = new List <IntPtr>(); Process process = null; Process[] p = Process.GetProcessesByName(processName); if (p.Count() > 0) { process = p[0]; } else { return(result); } IntPtr win = process.MainWindowHandle; result.Add(win); result.AddRange(GetChildWindows(win)); List <IntPtr> additional = new List <IntPtr>(); foreach (IntPtr w in result) { if (w != win) { additional.AddRange(GetChildWindows(w)); } } result.AddRange(additional); result = result.Distinct().ToList(); for (int i = 0; i < result.Count; i++) { if ((onlyVisible && !WindowAttrib.IsWindowVisible(result[i])) || (WindowAttrib.GetProcessId(result[i]) != process.Id)) { result.RemoveAt(i); i--; } } return(result); }
public static string SetForegroundWindowByName(string processName, string windowSubName, bool maximize) { Process process = null; Process[] p = Process.GetProcessesByName(processName); if (p.Length > 0) { process = p[0]; } else { return(""); } string currentText = WindowAttrib.GetForegroundWindowText(); IntPtr win = process.MainWindowHandle; foreach (Process pr in p) { pr.Dispose(); } if (windowSubName != "") { while (win != IntPtr.Zero) { string text = WindowAttrib.GetWindowText(win); if (text.Contains(windowSubName)) { if (currentText != text) { if (maximize) { MaximizeWindow(win); } SetForegroundWindow(win); } return(WindowAttrib.GetWindowText(win)); } win = GetWindow(win, 2); } } return(""); }
/// <summary>Пошук вікон за назвою процесу та заголовком вікна</summary> /// <param name="processName">Назва процесу</param> /// <param name="windowText">Заголовок вікна</param> public static List <IntPtr> GetAllWindowsByText(string processName, string windowText, bool exact) { List <IntPtr> result = new List <IntPtr>(); List <IntPtr> wins = GetAllWindowsByProcess(processName, true); foreach (IntPtr w in wins) { string text = WindowAttrib.GetWindowText(w); if ((exact && text == windowText) || (!exact && text.Contains(windowText))) { result.Add(w); } } return(result); }
public static IntPtr GetWindowByClass(IntPtr parent, string className) { string c = WindowAttrib.GetWindowClass(parent); if (c == className) { return(parent); } foreach (var w in GetChildWindows(parent)) { var found = GetWindowByClass(w, className); if (found != IntPtr.Zero) { return(found); } } return(IntPtr.Zero); }