您的位置:首页 > 移动开发 > Objective-C

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

2015-08-21 18:39 597 查看
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 <> 0) and (GetWindowThreadProcessID(Handle, OwningProcess) <> 0) 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) <> 0) and
(OwningProcess = GetCurrentProcessID) then
Result := Pointer(SendMessage(Handle, RM_GetObjectInstance, 0, 0))
else
Result := nil;
end;


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

线索还是点击TButton后发生,因为李维的书上提到了这一点~
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: