登录 注册
当前位置:主页 > 资源下载 > 49 > ?获取VS2010 C#代码】用于获取鼠标当前位置关联的窗口句柄名称、文本内容及其位置

?获取VS2010 C#代码】用于获取鼠标当前位置关联的窗口句柄名称、文本内容及其位置

  • 更新:2024-09-24 12:08:26
  • 大小:42KB
  • 推荐:★★★★★
  • 来源:网友上传分享
  • 类别:C# - 后端
  • 格式:RAR

资源介绍

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;//最下坐标 }