这有点像金山词霸的屏幕取词。要获取当前鼠标位置的类名和句柄,只须通过 WindowFromPoint
和GetClassName 这两个Win32函数就可以完成任务,不过,如果要获取当前鼠标位置的字符,可能要复杂得多。
下面是很简单的范例,大家应该都可以轻易弄清楚的。
typeTForm1 = class(TForm)NameLB: TLabel;ClassLB: TLabel;Timer1: TTimer;procedure Timer1Timer(Sender: TObject);procedure FormCreate(Sender: TObject);privateprocedure GetMousePosHwndAndClassName(Sender : TPoint);publicend;varForm1: TForm1;implementation{$R *.DFM}procedure TForm1.Timer1Timer(Sender: TObject);varrPos: TPoint;beginif boolean(GetCursorPos(rPos)) thenGetMousePosHwndAndClassName(rPos);end;procedure TForm1.GetMousePosHwndAndClassName(Sender: TPoint);varhWnd: THandle;aName: array [0..255] of char;beginhWnd := WindowFromPoint(Sender);NameLB.Caption := ’Handle : ’ + IntToStr(hWnd);if boolean(GetClassName(hWnd, aName, 256)) thenClassLB.Caption := ’ClassName : ’ + string(aName)else
ClassLB.Caption := ’ClassName : not found’;end;procedure TForm1.FormCreate(Sender: TObject);beginForm1.FormStyle := fsStayOnTop;Timer1.Interval := 50;end;
Copyright @ 2007-2012 敏韬网(敏而好学,文韬武略--MinTao.Net)(学习笔记) Inc All Rights Reserved. 闵涛 E_mail:admin@mintao.net(欢迎提供学习资源)
鄂公网安备 42011102001154号
站长:MinTao ICP备案号:鄂ICP备11006601号-18