获取鼠标坐标,鼠标所在窗体句柄
2008-12-26 15:36
471 查看
1.获取鼠标坐标
小持续没用hook
加了个timer
private void Form1_Load(object sender, EventArgs e)
{
this.timer1.Enabled = true;
this.timer1.Interval = 10;//timer控件的执行频率
}
为timer控件加代码
private void timer1_Tick(object sender, EventArgs e)
{
//显示鼠标坐标
//方法1:
textBox1.Text = Cursor.Position.ToString();
//textBox2.Text = Cursor.Position.Y.ToString();
//方法2:
//textBox1.Text = Control.MousePosition.X.ToString();
//textBox2.Text = Control.MousePosition.Y.ToString();
}
2.获取句柄与句柄标题
在获取坐标之后添加
// 显示鼠标所在句柄
IntPtr ptrWnd =(IntPtr)WindowFromPoint(Cursor.Position.X,Cursor.Position.Y);
textBox2.Text = "0x"+ptrWnd.ToString("x");
//显示所选句柄标题
int len = GetWindowTextLength(ptrWnd) + 1;
StringBuilder text = new StringBuilder(len);
GetWindowText(ptrWnd, text, len);
textBox3.Text = text.ToString();
api
[DllImport("user32.dll")]
public static extern int WindowFromPoint(int xPoint, int yPoint);
[DllImport("User32.dll")]
static extern int GetWindowText(IntPtr handle, StringBuilder text, int MaxLen);
[DllImport("User32.dll")]
static extern int GetWindowTextLength(IntPtr handle);
小持续没用hook
加了个timer
private void Form1_Load(object sender, EventArgs e)
{
this.timer1.Enabled = true;
this.timer1.Interval = 10;//timer控件的执行频率
}
为timer控件加代码
private void timer1_Tick(object sender, EventArgs e)
{
//显示鼠标坐标
//方法1:
textBox1.Text = Cursor.Position.ToString();
//textBox2.Text = Cursor.Position.Y.ToString();
//方法2:
//textBox1.Text = Control.MousePosition.X.ToString();
//textBox2.Text = Control.MousePosition.Y.ToString();
}
2.获取句柄与句柄标题
在获取坐标之后添加
// 显示鼠标所在句柄
IntPtr ptrWnd =(IntPtr)WindowFromPoint(Cursor.Position.X,Cursor.Position.Y);
textBox2.Text = "0x"+ptrWnd.ToString("x");
//显示所选句柄标题
int len = GetWindowTextLength(ptrWnd) + 1;
StringBuilder text = new StringBuilder(len);
GetWindowText(ptrWnd, text, len);
textBox3.Text = text.ToString();
api
[DllImport("user32.dll")]
public static extern int WindowFromPoint(int xPoint, int yPoint);
[DllImport("User32.dll")]
static extern int GetWindowText(IntPtr handle, StringBuilder text, int MaxLen);
[DllImport("User32.dll")]
static extern int GetWindowTextLength(IntPtr handle);
相关文章推荐
- 使用鼠标获取窗体句柄
- 获取鼠标所在窗体的PID
- Flex中通过获取鼠标所在的X、Y坐标进行事件分配
- 获取鼠标所在的坐标实例
- 鼠标获取窗体句柄
- DataGridView通过鼠标坐标,获取所在行索引
- js实时获取鼠标所在坐标
- jquery获取当前鼠标所在位置的坐标
- 鼠标移过获取控件句柄、类名、坐标
- js实时获取鼠标所在坐标
- 获取当前鼠标所在的坐标
- unity3d鼠标点击,获取世界坐标
- C++ 链表实现通讯录 (关于获取鼠标句柄后,清屏不能再次获取)
- 获取鼠标当前位置坐标的方法 - 回复 "ps8.0" 同学
- 取鼠标所在位置对应的窗口句柄
- VC 获取控制台窗体的句柄(hWnd)
- 小实例 敲击键盘是返回键盘上的unicode码 获取鼠标当前的坐标值
- 在页面中js获取光标/鼠标的坐标及光标的像素坐标
- C# 获取鼠标坐标
- DevExpress 获取gridview 鼠标位置所在单元格