1. 首页
  2. 编程语言
  3. C#
  4. 【VS2010 C# 代码】获取鼠标所在位置的窗口句柄名称和文字及位置

【VS2010 C# 代码】获取鼠标所在位置的窗口句柄名称和文字及位置

上传者: 2018-12-07 15:35:54上传 RAR文件 41.82KB 热度 43次
Microsoft Visual Studio 2010做的C#获取鼠标所在位置的窗口句柄名称和文字及位置实例,主要代码: [StructLayout(LayoutKind.Sequential)]//定义与API相兼容结构体,实际上是一种内存转换 public struct POINTAPI { public int X; public int Y; } [DllImport("user32.dll", EntryPoint = "GetCursorPos")]//获取鼠标坐标 public static extern int GetCursorPos( ref POINTAPI lpPoint ); [DllImport("user32.dll", EntryPoint = "WindowFromPoint")]//指定坐标处窗体句柄 public static extern int WindowFromPoint( int xPoint, int yPoint ); [DllImport("user32.dll", EntryPoint = "GetWindowText")] public static extern int GetWindowText( int hWnd, StringBuilder lpString, int nMaxCount ); [DllImport("user32.dll", EntryPoint = "GetClassName")] public static extern int GetClassName( int hWnd, StringBuilder lpString, int nMaxCont ); [DllImport("user32.dll")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool GetWindowRect(IntPtr hWnd, ref RECT lpRect); [StructLayout(LayoutKind.Sequential)] public struct RECT { public int Left; //最左坐标 public int Top; //最上坐标 public int Right; //最右坐标 public int Bottom;//最下坐标 }
用户评论
码姐姐匿名网友 2018-12-07 15:35:54

无法实现窗口外的鼠标信息及内容获取。

码姐姐匿名网友 2018-12-07 15:35:54

挺好的,还可以的