获取鼠标句柄
(1)引用
using System.Runtime.InteropServices;
(2)調(diào)用方法
1、獲取窗口標題
[DllImport( "user32.dll" )]
public static extern int GetWindowText( IntPtr hWnd, StringBuilder lpString,int nMaxCount );
注:hWnd 窗口句柄 lpString 窗口標題 nMaxCount 最大值
2、獲取類名
[DllImport( "user32.dll" )]
public static extern int GetClassName( IntPtr hWnd, StringBuilder lpString,int nMaxCount );
注:hWnd 句柄 lpString 類名 nMaxCount 最大值
3、根據(jù)坐標獲取窗口句柄
[DllImport( "user32.dll" )]
public static extern IntPtr WindowFromPoint(Point point);
注:point 坐標
二、顯示數(shù)據(jù)
(1) 獲取鼠標坐標
int x = Cursor.Position.X;
int y = Cursor.Position.Y;
this.textBox4.Text = string.Format( "({0},{1})" , x, y);
(2) 獲取句柄
Point p = new Point(x,y);
IntPtr formHandle = WindowFromPoint(p);
this.textBox1.Text = formHandle.ToString();
(3) 得到窗口標題
GetWindowText(formHandle,title,title.Capacity);
this.textBox2.Text = title.ToString();
(4)得到窗體的類名
StringBuilder cllassName = new StringBuilder();
GetClassName(formHandle,cllassName,cllassName.Capacity);
this.textBox3.Text = cllassName.ToString();
(5)Load事件
this.timer1.Enabled = !this.timer1.Enabled;
注:動態(tài)顯示信息
轉(zhuǎn)載于:https://www.cnblogs.com/edangame/p/7637543.html
總結(jié)
- 上一篇: 转录组差异表达分析工具Ballgown
- 下一篇: 雷鸟html签名设置,thunderbi