/// <summary> /// 如果Region是从AppWin中创建的,那么就以appwin的客户区为区域。 /// </summary> /// <param name="appWin"></param> public Region(Window appWin) { this.appWin = appWin; X1 = Y1 = 0; X2 = appWin.ClientSize.Width; Y2 = appWin.ClientSize.Height; }
public static void MyClassInitialize(TestContext testContext) { string pic = @"game.bmp"; app = Process.Start(@"C:\WINDOWS\system32\mspaint.exe",pic); Thread.Sleep(500); win = Window.FindWindow("game.bmp"); }
/// <summary> /// 绑定dm对象的构造函数 /// </summary> /// <param name="dm"></param> public IR(Window win) { this.win = win; }
public void Case_FindChildrenNotExisted() { Window win = new Window(0); List<Window> windows = win.FindChildren("flakfl;jfsaljf",option:FilterOption.Title); Assert.IsNull(windows); }
public void Case_FindChildrenExisted() { Window win = new Window(0); List<Window> windows = win.FindChildren("记事本"); Assert.AreNotEqual(windows.Count, 0); bool existed = false; foreach(var w in windows) { if(w.Title.Contains("记事本")) { existed = true; } } Assert.IsTrue(existed,"目标窗口不存在"); }
/// <summary> /// 获取子窗口,这个方法一般没什么用,即使有这方面需求也建议重新封装一个更具体的。 /// </summary> /// <param name="option">操作选项</param> /// <returns></returns> public Window GetWindow(Option option = Option.Parent) { Window win = new Window(dm.GetWindow(Hwnd, (int)option)); return win; }
/// <summary> /// 查找最符合类名或者标题名的顶层可见窗口 /// 例如:存在窗口 "大漠插件综合工具",那么查找"大漠"也能找到这个窗口 /// </summary> /// <param name="title">标题名</param> /// <param name="className">窗口类名</param> /// <param name="parent">父窗口</param> /// <returns>窗口</returns> public static Window FindWindow(string title, string className = "", Window parent = null) { int hwnd = 0; if (parent == null) { hwnd = Dm.Default.FindWindow(className, title); } else { hwnd = Dm.Default.FindWindowEx(parent.Hwnd, className, title); } return hwnd > 0 ? new Window(hwnd) : null; }
/// <summary> /// 根据指定条件,枚举系统中符合条件的窗口,可以枚举到按键自带的无法枚举到的窗口 /// </summary> /// <param name="paren">父窗口</param> /// <param name="title">标题</param> /// <param name="className">窗口类名</param> /// <param name="option">过滤</param> /// <returns>所有窗口</returns> public static List<Window> EnumWindow(Window paren, string title = "", string className = "", FilterOption option = FilterOption.Default) { string allHwnds = Dm.Default.EnumWindow(paren.Hwnd, title, className, (int)option); return HwndString2Window(allHwnds); }
/// <summary> /// 绑定dm对象的构造函数 /// </summary> /// <param name="dm"></param> public Ocr(Window win) { this.win = win; }
/// <summary> /// 找到窗口并绑定 /// </summary> /// <param name="title"></param> /// <param name="mode"></param> public void BindingWindow(string title, string mode) { appWin = Window.FindWindow(title); if (appWin == null) throw new Exception("Binding window fail.Can't find " + title); switch (mode) { case "Foreground": appWin.BindingDmsoft(BindingInfo.DefaultForeground); break; case "Background": appWin.BindingDmsoft(BindingInfo.DefaultBackground); break; } if (appWin.IsBinding == false) throw new Exception("Binding window fail.Can't bind mode " + mode); }
public void RunAndGetAppRegion(string exePath,string arguments="",string mode = "Foreground") { RunApp(exePath,arguments); Thread.Sleep(1000); appWin = new Window(app.MainWindowHandle.ToInt32()); switch (mode) { case "Foreground": appWin.BindingDmsoft(BindingInfo.DefaultForeground); break; case "Background": appWin.BindingDmsoft(BindingInfo.DefaultBackground); break; } if (appWin.IsBinding == false) throw new Exception("Binding window fail.Can't bind mode " + mode); }
/// <summary> /// 绑定dm对象的构造函数 /// </summary> /// <param name="dm"></param> public Keyboard(Window win) { this.win = win; }
public Mouse(Window win) { this.win = win; }