procedure TForm1.Timer1Timer(Sender: TObject); var H:HWND; arr:array[0..254] of char; Rt:TRect; pt:TPoint; ca:TCanvas; begin ca:=TCanvas.Create ; ca.Handle :=GetDc(0); if GetCursorPos(pt) then begin //将鼠标位置写入pt label1.Caption :='鼠标位置:'+inttostr(pt.x)+','+inttostr(pt.y); h:=WindowFromPoint(pt); //获取鼠标所位置控件的句柄 GetClassName(h,arr,length(arr)); //取类名 labelededit1.Text :=inttostr(h); labelededit2.Text :=arr; GetWindowRect(h,Rt); //取坐标 RedrawWindow(0, screen.DesktopRect, 0, RDW_ERASE or RDW_INVALIDATE or RDW_ALLCHILDREN); // sendmessage(h,wm_setredraw,0,0); Sleep(110); ca.Pen.Color :=clBlue; ca.Pen.Width :=5; ca.polyline([ rt.TopLeft, point(rt.Right,rt.top), rt.BottomRight, point(rt.Left,rt.Bottom), rt.TopLeft ]); label3.Caption :=inttostr(rt.top)+','+inttostr(rt.Right ); oldrt:=rt; end; ca.Free; end;