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后发生,因为李维的书上提到了这一点~