Delphi 根据窗口句柄获取空间对象

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;

测试

ShowMessage(TEdit(GetInstanceFromhWnd(Edit1.Handle)).Text);

需要相同版本的Delphi

 

posted @ 2022-02-13 21:36  只如初见o  阅读(251)  评论(0)    收藏  举报