FindControl什么时候才会使用ObjectFromHWnd函数呢?——VCL很难调试,加一个日志函数,记录时间

IsDelphiHandle
FindVCLWindow
function IsVCLControl(Handle: HWND): Boolean;
function FindControl(Handle: HWND): TWinControl;
function FindVCLWindow(const Pos: TPoint): TWinControl;

function FindControl(Handle: HWnd): TWinControl;
var
OwningProcess: DWORD;
begin
Result := nil;
if (Handle <> ) and (GetWindowThreadProcessID(Handle, OwningProcess) <> ) and
(OwningProcess = GetCurrentProcessId) then
begin
if GlobalFindAtom(PChar(ControlAtomString)) = ControlAtom then
Result := Pointer(GetProp(Handle, MakeIntAtom(ControlAtom)))
else
Result := ObjectFromHWnd(Handle);
end;
end; function ObjectFromHWnd(Handle: HWnd): TWinControl;
var
OwningProcess: DWORD;
begin
if (GetWindowThreadProcessID(Handle, OwningProcess) <> ) and
(OwningProcess = GetCurrentProcessID) then
Result := Pointer(SendMessage(Handle, RM_GetObjectInstance, , ))
else
Result := nil;
end;

我测了一下,无论是拖控件放到窗体上,还是动态生成的控件,都是通过GetProp方法取得Delphi对象的指针。那么什么时候会使用神乎其神的ObjectFromHWnd函数呢?

线索还是点击TButton后发生,因为李维的书上提到了这一点~

上一篇:同步or异步


下一篇:筛选实现C++实现筛选法