这有点像金山词霸的屏幕取词。要获取当前鼠标位置的类名和句柄,只须通过 WindowFromPoint和GetClassName 这两个Win32函数就可以完成任务,不过,如果要获取当前鼠标位置的字符,可能要复杂得多。下面是很简单的范例,大家应该都可以轻易弄清楚的。 type
TForm1 = class(TForm)
NameLB: TLabel;
ClassLB: TLabel;
Timer1: TTimer;
procedure Timer1Timer(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
procedure GetMousePosHwndAndClassName(Sender : TPoint);
publicend;var
Form1: TForm1;implementation{$R *.DFM}procedure TForm1.Timer1Timer(Sender: TObject);
var
rPos: TPoint;
begin
if boolean(GetCursorPos(rPos)) then
GetMousePosHwndAndClassName(rPos);
end;procedure TForm1.GetMousePosHwndAndClassName(Sender: TPoint);
var
hWnd: THandle;
aName: array [0..255] of char;
begin
hWnd := WindowFromPoint(Sender);
NameLB.Caption := ’Handle : ’ + IntToStr(hWnd);if boolean(GetClassName(hWnd, aName, 256)) then
ClassLB.Caption := ’ClassName : ’ + string(aName)
elseClassLB.Caption := ’ClassName : not found’;
end;procedure TForm1.FormCreate(Sender: TObject);
begin
Form1.FormStyle := fsStayOnTop;
Timer1.Interval := 50;
end;

解决方案 »

  1.   

    Cursor.Position.X
    Cursor.Position.Y
      

  2.   

    Cursor.Position.X
    Cursor.Position.Y
    是在程序里鼠标的位置吧
      

  3.   

    Cursor.Position.X
    Cursor.Position.Y
      

  4.   

    是我误进了delpi板
    还是你误进了.net板
      

  5.   

    [DllImport("user32.dll")]
     static extern bool SetCursorPos(int X, int Y); [DllImport("user32.dll")]
     static extern bool GetCursorPos(out POINT lpPoint);
      

  6.   

    试了一下,用
    Cursor.Position.X
    Cursor.Position.Y
    可以
      

  7.   

    可以用Control类的一个静态属性MousePosition,获得的是鼠标的平面坐标.
      

  8.   

    Cursor.Position.X
    Cursor.Position.Y