{
  ---------------通过控件句柄获取控件实例--------------------------------------------
  ---------------原理详见 Classes.pas 单元,13045行 <Delphi7>------------------------
  ---------------原理详见 Classes.pas 单元,11613行 <Delphi2007>---------------------
  ---------------原理详见 Classes.pas 单元,13045行 <Delphi2010>---------------------
  ---------------原理详见 Classes.pas 单元,13512行 <DelphiXE>-----------------------
}
function GetInstanceFromhWnd(const hWnd: Cardinal): TWinControl;
type
  PObjectInstance = ^TObjectInstance;  TObjectInstance = packed record
    Code: Byte;            { 短跳转 $E8 }
    Offset: Integer;       { CalcJmpOffset(Instance, @Block^.Code); }
    Next: PObjectInstance; { MainWndProc 地址 }
    Self: Pointer;         { 控件对象地址 }
  end;
var
  wc: PObjectInstance;
begin
  Result := nil;
  wc     := Pointer(GetWindowLong(hWnd, GWL_WNDPROC));
  if wc <> nil then
  begin
    Result := wc.Self;
  end;
end;procedure TForm1.btn1Click(Sender: TObject);
begin
  btn1.Caption := TEdit(GetInstanceFromhWnd(edt1.Handle)).Text;
end;