Create a Delphi project, place a tedit and TButton, and enter some text in Edit1.
{---------------Gets the control instance through the control handle-----------------------------------------------------------principle, see Classes.pas Unit, 13045 line <Delphi7>---------------------------------------principles see Classes.pas Unit, 11613 lines <Delphi2007>-------- ----------------------------principle See Classes.pas Unit, 13045 lines <Delphi2010>------------------------------------principles See Classes.pas unit, 13512 rows <DelphiXE>-----------------------} function Getinstancefromhwnd (const hwnd:cardinal):
Twincontrol;
Type pobjectinstance = ^tobjectinstance; tobjectinstance = packed record code:byte;
{Short Jump $E 8} Offset:integer; {Calcjmpoffset (Instance, @Block ^. Code); } next:pobjectinstance;
{Mainwndproc Address} Self:pointer;
{Control object address} 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
See how we got the text in the Edit1. Very magical, understand the VCL code, it is not so magical.