unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls; type TForm1 = class(TForm) Panel1: TPanel; Edit1: TEdit; Button1: TButton; Button2: TButton; Timer1: TTimer; procedure FormCreate(Sender: TObject); procedure Timer1Timer(Sender: TObject); procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); end; var Form1: TForm1; implementation {$R *.dfm} {这里主要是设置控件位置} procedure TForm1.FormCreate(Sender: TObject); begin Panel1.Align := alTop; Panel1.Height := 30; Edit1.Top := 4; Edit1.Left := 12; Edit1.Width := 72; Edit1.Clear; Button1.Top := Edit1.Top - 1; Button1.Left := Edit1.Left + Edit1.Width + 12; Button1.Caption := '确认捕获, 用回车键'; Button1.Width := Canvas.TextWidth(Button1.Caption) + 32; Button1.Default := True; Button2.Top := Button1.Top; Button2.Left := Panel1.ClientWidth - Button2.Width - 12; Button2.Anchors := [akRight]; Button2.Caption := '过来吧你'; Timer1.Interval := 100; end; {捕获窗口句柄, 显示在标题} procedure TForm1.Timer1Timer(Sender: TObject); var pt: TPoint; begin if Boolean(GetCursorPos(pt)) then Text := IntToStr(WindowFromPoint(pt)); end; {把确认的目标窗口的句柄显示在 Edit1} procedure TForm1.Button1Click(Sender: TObject); begin Edit1.Text := Self.Text; end; {捕获了干什么呢? 譬如让它当自己的"干儿子"吧} procedure TForm1.Button2Click(Sender: TObject); var h: HWND; {这是被捕捉窗口的句柄} r: TRect; {这是被捕捉窗口的矩形} pw,ph: Integer; {这是被捕捉窗口的宽度与高度} begin h := StrToInt(Edit1.Text); Windows.SetParent(h, Self.Handle); GetWindowRect(h,r); pw := r.Right - r.Left; ph := r.Bottom - r.Top; MoveWindow(h, 0, Panel1.Height, pw, ph, True); end; end.标签:鼠标,句柄,TObject,Edit1,Button2,Button1,窗体,procedure,Sender From: https://www.cnblogs.com/lucken2000/p/17397065.html