private void setValueControlByHandle(Process p, int ID, string valueIP) { try { int num2; Thread.Sleep(0x3e8); IntPtr mainWindowHandle = p.MainWindowHandle; List <HwndObject> windows = HwndObject.GetWindows(); int num = -1; for (num2 = 0; num2 < windows.Count; num2++) { if (windows[num2].Hwnd == mainWindowHandle) { num = num2; break; } } List <HwndObject> children = windows[num].GetChildren(); int num3 = -1; for (num2 = 0; num2 < children.Count; num2++) { if (GetDlgCtrlID(children[num2].Hwnd) == ID) { num3 = num2; break; } } children[num3].Text = valueIP; } catch (Exception exception) { CtlError.WriteError("ErroLog", "setValueControlByHandle Loi khi set handle tren form", exception.Message); } }
public static void ScanWindows() { foreach (HwndObject o in HwndObject.GetWindows()) { Console.WriteLine(GetHwndInfoString(o)); } }
/// <summary> /// Tries 5 times to get a HwndObject corresponding to Paint's window. Returns true if one was found, false (and null) otherwise. /// </summary> /// <param name="obj">The HwndObject found</param> static bool ForceGetPaintHwnd(out HwndObject obj) { const int MaxTries = 5; List <HwndObject> list = HwndObject.GetWindows(); int i = 0; while (true) { if (GetPaintHwnd(out obj)) { Console.ForegroundColor = Colors.Success; Console.WriteLine("[Program] Found (hopefully) paint window: " + obj.Text); return(true); } if (++i >= MaxTries) { Console.WriteLine(String.Concat("[Program] (", i, ')', " No Paint window found. Not retrying #yolo")); obj = null; return(false); } Console.ForegroundColor = Colors.Error; Console.WriteLine(String.Concat("[Program] (", i, ")", "No Paint window found. Retrying in 1s...")); Thread.Sleep(1000); } }
private bool InitializeReport(out HwndObject parameters, out HwndObject report, string reportName) { parameters = null; report = null; foreach (HwndObject o in HwndObject.GetWindows()) { if (o.Title.Equals(reportName)) { report = o; } else if (o.Title.Equals("Enter Parameter Values")) { parameters = o; } } if (parameters == null || report == null) { Console.ForegroundColor = Colors.Error; Console.WriteLine("Not enough time to find these windows."); return(false); } return(true); }
public static int GetWindowCount(params WindowExtractor[] tableNameExtractors) { return(tableNameExtractors .SelectMany(extractor => HwndObject .GetWindows() .Select(w => extractor.Extractor(w.Title)) .Where(n => !string.IsNullOrEmpty(n))) .Count()); }
// if combobox is empty, refresh the window titles autocomplete source public void RefreshHwndAutocomplete() { if (windowsComboBox.Text.Length == 0) { AutoCompleteStringCollection data = new AutoCompleteStringCollection(); foreach (HwndObject o in HwndObject.GetWindows()) { data.Add(o.Title); } windowsComboBox.AutoCompleteCustomSource = data; } }
private void ClearOpenReports() { List <HwndObject> list = HwndObject.GetWindows().FindAll(o => o.Title.Equals("Enter Parameter Values")); foreach (HwndObject o in list) { o.CloseWindow(); Thread.Sleep(1000); Input.PressKey(Input.KEY_SPACE); axiUm.Activate(); } }
// ideally this should utilize the find/move single window function, however // the Hwnd library i'm using does not really allow for that :/ private void MoveLayoutWindows(WindowCollection coll) { foreach (HwndObject o in HwndObject.GetWindows()) { foreach (Window w in coll.Windows) { if (TitlesMatch(w, o)) { w.MoveAndResize(o); } } } }
public static IEnumerable <WindowInfo> GetWindowList(Size screenSize, Size targetSize, params WindowExtractor[] tableNameExtractors) { foreach (var extractor in tableNameExtractors) { var ws = HwndObject .GetWindows(); var windows = ws .Select(w => new { Room = extractor.Name, Window = w, TableName = extractor.Extractor(w.Title) }) .Where(w => !string.IsNullOrEmpty(w.TableName)); foreach (var window in windows) { var size = window.Window.Size; if (targetSize != size) { Console.WriteLine($"Current size {size.Width}x{size.Height}, resizing to {targetSize.Width}x{targetSize.Height}"); HwndObject.GetWindowByTitle(window.Window.Title).Size = targetSize; continue; } Bitmap bitmap = new Bitmap(size.Width, size.Height); Graphics memoryGraphics = Graphics.FromImage(bitmap); IntPtr dc = memoryGraphics.GetHdc(); bool success = Win32.PrintWindow(window.Window.Hwnd, dc, 0); memoryGraphics.ReleaseHdc(dc); if (true) { RECT rect = new RECT(); if (Win32.GetWindowRect(window.Window.Hwnd, ref rect)) { int width = rect.right - rect.left; int height = rect.bottom - rect.top; bitmap = new Bitmap(width, height); Graphics graphics = Graphics.FromImage(bitmap); graphics.CopyFromScreen(rect.left, rect.top, 0, 0, new Size(width, height), CopyPixelOperation.SourceCopy); } } yield return(new WindowInfo { Room = window.Room, Title = window.Window.Title, TableName = window.TableName, Size = size, Bitmap = bitmap }); } } }
/// <summary> /// Tries once to get a HwndObject with the string "Paint". Returns whether any was found /// </summary> /// <param name="obj">The Hwnd object found</param> /// <returns></returns> static bool GetPaintHwnd(out HwndObject obj) { List <HwndObject> list = HwndObject.GetWindows(); foreach (HwndObject o in list) { if (o.Text.Contains("Paint") && !o.Text.ToLower().Contains("drawer")) { obj = o; return(true); } } obj = null; return(false); }
public IntPtr getHandleFromName(String inp) { List <HwndObject> p = HwndObject.GetWindows(); foreach (HwndObject o in p) { if (o.Title.Length > 0) { if (o.Title.ToLower() == inp.ToLower()) { return(o.Hwnd); } } } return(IntPtr.Zero); }
static void ShowSelf() { List <HwndObject> list = HwndObject.GetWindows(); foreach (HwndObject o in list) { if (o.Size.Width == 0 || o.Size.Height == 0 || o.Text.Length == 0) { continue; } if (o.ClassName.Equals("ConsoleWindowClass") || o.Title.Contains("PaintDrawer.exe")) { WindowScrape.Static.HwndInterface.ShowWindow(o.Hwnd, 3); } } }
public List <HwndObject> getProcesses() { List <HwndObject> procs = new List <HwndObject>(); List <HwndObject> p = HwndObject.GetWindows(); foreach (HwndObject o in p) { if (o.Title.Length > 0) { if (!o.Size.IsEmpty && o.Size.Height > 1 && o.Size.Width > 1) { procs.Add(o); } } } return(procs); }
private void ExecuteQuery() { HwndObject startWindow = HwndObject.GetForegroundWindow(); Input.PressKeyCombo(Input.KEY_ALT, Input.KEY_S); Stopwatch watch = Stopwatch.StartNew(); Thread.Sleep(500); HwndObject fetching = null; foreach (HwndObject o in HwndObject.GetWindows()) { List <HwndObject> list = o.GetChildren(); if (list.Count != 3) { continue; } if (list[1].Title.Equals("Please wait...") || list[1].Title.Equals("Fetching Data...")) { Stuff.WriteConsoleMessage("Parent: " + Stuff.GetHwndInfoString(o.GetParent())); fetching = list[0]; break; } } while (HwndObject.GetForegroundWindow() != startWindow) { Console.Write("Waiting... (" + watch.ElapsedMilliseconds + ")"); if (fetching != null) { Console.WriteLine(fetching.Text); } else { Console.WriteLine(); } Thread.Sleep(5000); } watch.Stop(); Stuff.WriteConsoleSuccess("Report Generated"); }
private void RecordPositions() { Logger.Debug($"Timer tick: Locked: {CurrentState.SystemLocked} ChangeDetected: {CurrentState.ChangeDetected}"); if (CurrentState.SystemLocked || CurrentState.ChangeDetected) { return; } lock (syncLock) { Logger.Debug("Recording Positions"); var windowPositions = new Dictionary <IntPtr, WindowPlacement>(); var currentConfig = GetCurrentScreenConfig(); foreach (var window in HwndObject.GetWindows()) { var state = window.WindowPlacement; var parent = window.GetParent(); if (parent.Hwnd == IntPtr.Zero && (state.ShowState == WindowShowStateEnum.Normal || state.ShowState == WindowShowStateEnum.Maximize) && !string.IsNullOrEmpty(window.Title) && window.IsVisible) { Logger.Debug("Saving position of " + window.Title + " as " + window.WindowPlacement); windowPositions[window.Hwnd] = state; } } var newConfig = GetCurrentScreenConfig(); //Make sure resolution didn't change mid-record if (newConfig.Equals(currentConfig)) { resolutionDictionary[currentConfig] = windowPositions; } else { Logger.Debug("Resolution changed mid-record, dropping record"); } } }
private static bool GetAxium(out HwndObject axiUm) { List <HwndObject> list = HwndObject.GetWindows(); foreach (HwndObject o in list) { if (o.Size.Width == 0 || o.Size.Height == 0 || o.Text.Length == 0) { continue; } if (o.Text.Contains("axiUm")) { axiUm = o; return(true); } } axiUm = null; return(false); /* * if (GetPaintHwnd(out obj)) * { * Console.ForegroundColor = Colors.Success; * Console.WriteLine("[Program] Paint Hwnd found! using: " + obj.Text); * obj.Activate(); * WindowScrape.Static.HwndInterface.ShowWindow(obj.Hwnd, 3); * } * else * { * Console.ForegroundColor = Colors.Message; * Console.WriteLine("[Program] Paint Hwnd not found."); * Input.OpenPaint(); * if (!ForceGetPaintHwnd(out obj)) * { * Console.ForegroundColor = Colors.Error; * Console.WriteLine("[Program] ERROR: Can't find Paint Hwnd. Process aborted."); * return; * } * } */ }
private string getValueControlByHandle(string title) { try { Process process = Process.GetProcessesByName("Openvpn-Gui")[0]; Process process2 = Process.GetProcessesByName("Openvpn")[0]; IntPtr dlgItem = GetDlgItem(process.MainWindowHandle, 0xa1); IntPtr ptr2 = FindWindowEx(process.MainWindowHandle, IntPtr.Zero, "Static", "Current State: Connecting"); IntPtr handle = process.Handle; StringBuilder lpString = new StringBuilder(0xffff); GetWindowText(dlgItem, lpString, 50); IntPtr mainWindowHandle = process2.MainWindowHandle; string mainWindowTitle = process.MainWindowTitle; List <HwndObject> children = HwndObject.GetWindows()[0].GetChildren(); return(HwndObject.GetWindowByTitle(title).Title); } catch (Exception) { return(""); } }
public static IEnumerable <WindowInfo> GetRawWindowList(Size screenSize, params string[] searchStrings) { foreach (string searchString in searchStrings) { foreach (HwndObject window in HwndObject.GetWindows().Where(w => w.Title.StartsWith(searchString))) { //Bitmap bitmap = new Bitmap(screenSize.Width, screenSize.Height); //Graphics memoryGraphics = Graphics.FromImage(bitmap); //IntPtr dc = memoryGraphics.GetHdc(); //bool success = Win32.PrintWindow(window.Hwnd, dc, 0); //memoryGraphics.ReleaseHdc(dc); yield return(new WindowInfo { Title = window.Title, Size = window.Size, //Bitmap = bitmap }); } } }
private void RestorePositions() { lock (syncLock) { if (!CurrentState.SystemLocked) { var currentConfig = GetCurrentScreenConfig(); if (!resolutionDictionary.ContainsKey(currentConfig)) { return; } var windowPositions = resolutionDictionary[currentConfig]; foreach (var window in HwndObject.GetWindows()) { if (windowPositions.ContainsKey(window.Hwnd)) { var newState = windowPositions[window.Hwnd]; Logger.Debug("Restoring position of " + window.Title + " to " + newState); var tempState = newState.Clone(); tempState.ShowState = WindowShowStateEnum.Normal; tempState.Position = newState.Position; window.WindowPlacement = tempState; window.WindowPlacement = newState; } } CurrentState.ChangeDetected = false; } else { _restoreTimer.Start(); } } }
private bool OpenColumnCondition(Point p, int numRetries = DEFAULT_RETRIES) { if (!EnoughRetries(numRetries)) { return(false); } Input.MoveTo(p); Thread.Sleep(500); Input.RegisterClick(); Thread.Sleep(2000); HwndObject conditions = null; foreach (HwndObject o in HwndObject.GetWindows()) { if (o.Title.Equals("Column Conditions")) { conditions = o; break; } } if (conditions == null) { Console.ForegroundColor = Colors.Error; Console.WriteLine("Unable to find Column Conditions box"); Console.WriteLine("Not enough time to find these windows. Trying once more..."); return(OpenColumnCondition(p, numRetries - 1)); } else { Console.ForegroundColor = Colors.Message; Console.WriteLine("Column Conditions box found"); conditions.Activate(); } return(true); }
private IntPtr GetValueControlByHandle(Process p, int ID) { try { int num2; IntPtr mainWindowHandle = p.MainWindowHandle; List <HwndObject> windows = HwndObject.GetWindows(); int num = -1; for (num2 = 0; num2 < windows.Count; num2++) { if (windows[num2].Hwnd == mainWindowHandle) { num = num2; break; } } List <HwndObject> children = windows[num].GetChildren(); IntPtr zero = IntPtr.Zero; int num3 = -1; for (num2 = 0; num2 < children.Count; num2++) { if (GetDlgCtrlID(children[num2].Hwnd) == ID) { num3 = num2; zero = children[num2].Hwnd; break; } } return(zero); } catch (Exception exception) { CtlError.WriteError("ErroLog", "setValueControlByHandle Loi khi set handle tren form", exception.Message); return(IntPtr.Zero); } }
protected bool LoadWindows() { HwndObject.CacheResetUsed(); Process proc = GetProcessFirstVisible(); List <HwndObject> hwndObjs = null; if (proc != null) { HwndObject hwndObject = HwndObject.GetInstance(proc.MainWindowHandle); hwndObjs = hwndObject.GetSiblings(); } else { hwndObjs = HwndObject.GetWindows(); } procCache.ResetUsed(); bool isChanged = false; AppData appData; foreach (var hwndObj in hwndObjs) { if (IsHwndSelectable(hwndObj)) { proc = procCache.Get(hwndObj.PID); if (IsProcSelectable(proc)) { appData = CreateOrGetAppData(proc); isChanged |= AddOrUpdateAppWinData(appData, hwndObj); } } } procCache.ClearUnUsed(); HwndObject.CacheClearUnUsed(); return(isChanged); }
private void ExportQuery() { Input.PressKeyCombo(Input.KEY_ALT, Input.KEY_A); Thread.Sleep(5000); HwndObject startWindow = HwndObject.GetForegroundWindow(); Input.PressKeyCombo(Input.KEY_ALT, Input.KEY_E); Thread.Sleep(1000); Input.MoveTo(new Point(870, 405)); Input.RegisterClick(); Thread.Sleep(500); Input.PressKeyCombo(Input.KEY_ALT, Input.KEY_O); Stopwatch watch = Stopwatch.StartNew(); Thread.Sleep(10000); HwndObject progress = null; foreach (HwndObject o in HwndObject.GetWindows()) { List <HwndObject> list = o.GetChildren(); if (list.Count <= 1) { continue; } if (list[1].Title.Equals("Processing")) { Stuff.WriteConsoleMessage(Stuff.GetHwndInfoString(list[0])); progress = list[0]; break; } } int excelWindowCount = HwndObject.GetWindows().FindAll(e => e.Title.Contains("Excel")).Count; while (true) { HwndObject window = HwndObject.GetForegroundWindow(); if (window.Title.Contains("Excel") && window.Title.StartsWith("Book")) { Stuff.WriteConsoleMessage("Found opened window"); break; } else if (HwndObject.GetWindows().FindAll(e => e.Title.Contains("Excel")).Count == (excelWindowCount + 1)) { Stuff.WriteConsoleMessage("Detected change in excel window counts"); break; } Console.Write("Waiting... (" + watch.ElapsedMilliseconds + ")"); if (progress != null) { Console.WriteLine(" " + progress.Text); } else { Console.WriteLine(); } Thread.Sleep(5000); } watch.Stop(); Stuff.WriteConsoleSuccess("Data exported"); }
public void SaveExcel(string path) { HwndObject window = HwndObject.GetForegroundWindow(); if (!window.Title.Contains("Excel") && !window.Title.StartsWith("Book")) { foreach (HwndObject o in HwndObject.GetWindows().FindAll(e => e.Title.Contains("Excel"))) { if (o.Title.StartsWith("Book")) { if (window == null) { window = o; } else if (Int32.TryParse(o.Title.Substring(4), out int number)) { if (number > Int32.Parse(window.Title.Substring(4))) { window = o; } } } } } if (window == null) { Console.ForegroundColor = Colors.Error; Console.WriteLine("Unable to export report from Axium"); return; } else { Console.ForegroundColor = Colors.Success; Console.WriteLine("Excel file opened: " + window.Title); } window.Activate(); Thread.Sleep(2000); window.Maximize(); Thread.Sleep(2000); Input.PressKeyCombo(Input.KEY_CONTROL, Input.KEY_S); Thread.Sleep(2000); Input.MoveTo(new Point(800, 635)); Thread.Sleep(500); Input.RegisterClick(); Thread.Sleep(500); Input.MoveTo(new Point(570, 195)); Thread.Sleep(500); Input.RegisterClick(); Thread.Sleep(500); HwndObject saveDialog = HwndObject.GetWindows().Find(e => e.Title.Contains("Save As")); Stuff.WriteConsoleMessage("Save dialog found!"); saveDialog.Activate(); Thread.Sleep(500); Input.KeyboardWrite(path, 100); Thread.Sleep(100); Input.PressKeyCombo(Input.KEY_ALT, Input.KEY_S); Thread.Sleep(2000); if (!File.Exists(path + ".xlsx")) { Stuff.WriteConsoleError("File was not saved...trying again"); } else { window.CloseWindow(); Stuff.WriteConsoleSuccess("File was saved to " + path); } }
private void SaveReport(string path, int numberRetries = 3) { if (!EnoughRetries(numberRetries)) { return; } Console.ForegroundColor = Colors.Message; Console.WriteLine("Saving Report to " + path); Input.MoveTo(new Point(15, 40)); Thread.Sleep(100); Input.RegisterClick(); Thread.Sleep(2000); HwndObject export = null; foreach (HwndObject o in HwndObject.GetWindows()) { if (o.Title.Equals("Export Report")) { export = o; } } if (export == null) { Console.ForegroundColor = Colors.Error; Console.WriteLine("Unable to find export dialog box"); Console.WriteLine("Not enough time to find these windows. Trying once more..."); SaveReport(path, numberRetries - 1); return; } else { Console.ForegroundColor = Colors.Message; Console.WriteLine("Export dialog box found"); export.Activate(); } Input.KeyboardWrite(path, 100); Input.PressKey(Input.KEY_TAB); Input.PressKey(Input.KEY_DOWN); Input.PressKey(Input.KEY_DOWN); Input.PressKey(Input.KEY_DOWN); Input.PressKey(Input.KEY_DOWN); Input.PressKey(Input.KEY_DOWN); Input.PressKey(Input.KEY_DOWN); Input.PressKey(Input.KEY_TAB); Input.PressKey(Input.KEY_ENTER); HwndObject confirm = null; Stopwatch watch = Stopwatch.StartNew(); while (watch.ElapsedMilliseconds < 60000) { Console.ForegroundColor = Colors.Message; Console.WriteLine("Saving... (" + watch.ElapsedMilliseconds + ")"); // Find confirmation window foreach (HwndObject o in HwndObject.GetWindows()) { if (o.Title.Equals("Export Report") && o.GetChildren().Count == 3) { confirm = o; break; } } if (confirm != null) { Thread.Sleep(500); confirm.Activate(); Input.PressKey(Input.KEY_ENTER); break; } else { Thread.Sleep(3000); } } watch.Stop(); if (!File.Exists(path + ".xlsx")) { Console.ForegroundColor = Colors.Error; Console.WriteLine("File was not saved...trying again"); SaveReport(path, numberRetries - 1); } else { Console.ForegroundColor = Colors.Success; Console.WriteLine("File was saved"); } }