文件名称:【VS2010 C# 代码】获取鼠标所在位置的窗口句柄名称和文字及位置
文件大小:42KB
文件格式:RAR
更新时间:2020-10-08 10:50:11
VS2010 窗口
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;//最下坐标 }
【文件预览】:
demo_windowpos
----demo_windowpos()
--------demo_windowpos.csproj(4KB)
--------Form1.cs(3KB)
--------bin()
--------obj()
--------Properties()
--------Program.cs(495B)
--------Form1.Designer.cs(3KB)
--------Form1.resx(6KB)
----demo_windowpos.suo(19KB)
----demo_windowpos.sln(884B)