FindWindow

Image 1 介绍 有很多项目在市场上像间谍+ +或屏幕捕获程序,允许用户查找和选择一个特定的窗口或车窗控制按钮,编辑等。 这个项目的目标是编写一个简单的界面,用于寻找窗口句柄。 启动应用程序后,开始拖着牛眼象征“查找程序工具”(1)将“查找程序工具”符号移到所需的windowStop放鼠标光标移动如果你想信息底层windowThe信息选择窗口所示对话框的属性(2) 背景 我有编程这样的搜索工具在c++ .Now 多年;我用这个在c#中,so 我把我的旧c++代码转化为c#代码。 使用的代码 有两个重要的方法,找到并选择窗口: 函数“MainForm:: ChildWindowFromPoint”参数:在屏幕上点是全球点(通常鼠标光标)返回:从发现窗口处理 隐藏,收缩,复制Codestatic IntPtr ChildWindowFromPoint(点) { IntPtr WindowPoint = ApiWrapper.Window.WindowFromPoint(点); 如果(WindowPoint = = IntPtr.Zero) 返回IntPtr.Zero; 如果(ApiWrapper.Window。ScreenToClient (WindowPoint参考点)= = false) 抛出新的异常(“ScreenToClient失败”); IntPtr窗口= ApiWrapper.Window.ChildWindowFromPointEx (WindowPoint点0); 如果(窗口= = IntPtr.Zero) 返回WindowPoint; 如果(ApiWrapper.Window。ClientToScreen (WindowPoint参考点)= = false) 抛出新的异常(“ClientToScreen失败”); 如果(ApiWrapper.Window.IsChild (ApiWrapper.Window.GetParent(窗口),窗口)= = false) 返回窗口; / /创建一个列表来容纳下所有的孩子 ArrayList WindowList = new ArrayList (); 而(窗口! = IntPtr.Zero) { 矩形矩形= ApiWrapper.Window.GetWindowRect(窗口); 如果(rect.Contains(点)) WindowList.Add(窗口); 窗口= ApiWrapper.Window.GetWindow (窗口,(单位)ApiWrapper.Window.GetWindow_Cmd.GW_HWNDNEXT); } / /搜索最小的窗口列表 int MinPixel = GetSystemMetrics ((int) GetSystem_Metrics.SM_CXFULLSCREEN) * GetSystemMetrics ((int) GetSystem_Metrics.SM_CYFULLSCREEN); for (int i = 0;我& lt;WindowList.Count;+ + i) { 矩形矩形= ApiWrapper.Window.GetWindowRect ((IntPtr) WindowList[我]); int ChildPixel = rect.Width * rect.Height; 如果(ChildPixel & lt;MinPixel) { MinPixel = ChildPixel; 窗口= (IntPtr) WindowList[我]; } } 返回窗口; } 函数“MainForm:: ShowInvertRectTracker”参数:窗口显示/隐藏选定的矩形 隐藏,收缩,复制Codestatic空白ShowInvertRectTracker (IntPtr窗口) { 如果(窗口! = IntPtr.Zero) { / /获取坐标从窗口在屏幕上 矩形WindowRect = ApiWrapper.Window.GetWindowRect(窗口); / /获取窗口的设备上下文 IntPtr dc = ApiWrapper.Window.GetWindowDC(窗口); / /创建一个逆笔的大小窗口边界 ApiWrapper.Gdi。SetROP2(直流,(int) ApiWrapper.Gdi.RopMode.R2_NOT); 颜色=颜色。FromArgb (0 255 0); IntPtr笔= ApiWrapper.Gdi.CreatePen ((int) ApiWrapper.Gdi.PenStyles。PS_INSIDEFRAME 3 * GetSystemMetrics ((int) GetSystem_Metrics.SM_CXBORDER), (单位)color.ToArgb ()); / /画周围的矩形窗口 IntPtr OldPen = ApiWrapper.Gdi。SelectObject(直流、笔); IntPtr OldBrush = ApiWrapper.Gdi.SelectObject (直流,ApiWrapper.Gdi.GetStockObject ((int) ApiWrapper.Gdi.StockObjects.NULL_BRUSH)); ApiWrapper.Gdi。矩形(0,0,WindowRect.Width, WindowRect.Height); ApiWrapper.Gdi。SelectObject(直流,OldBrush); ApiWrapper.Gdi。SelectObject(直流,OldPen); / /释放设备上下文,并摧毁钢笔 ApiWrapper.Window。ReleaseDC(窗口特区); ApiWrapper.Gdi.DeleteObject(笔); } } 文件 MainForm.cs 显示了FindWindow对话框。处理鼠标事件(下降-移动)和显示结果信息。 GdiApiWrapper。cs, WinApiWrapper.cs 基本功能MainForm: ChildWindowFromPoint和MainForm:: ShowInvertRectTracker广泛使用基地赢得API。赢的签名API中列出这些文件。functions 列表并不完整。我只是实现功能,我需要这个工具。 历史 2009年4月3日:初始版本 本文转载于:http://www.diyabc.com/frontweb/news5408.html

原文地址:https://www.cnblogs.com/Dincat/p/13462909.html