I wrote the following functions, because I want to open a form2 from form1 and form2 I want to know if this is the child of form1.
Can anyone tell me what did I do wrong? Why does not work as I thought!
Thanks.
WinFiglio:=window with the focus
WinIpoteticoPadre:=Form1.Handle;
function TForm1.HandlePadreCoincide(WinFiglio: HWND; WinIpoteticoPadre: HWND): boolean;
var
H: THandle;
ret: boolean;
begin
ret:=FALSE;
H := FindWindow(nil,nil);
while not H=0 do
begin
if ((GetParent(H)=0) and (H=WinFiglio)) then
if (WinIpoteticoPadre=ProcIDFromWnd(WinFiglio)) then
begin
H:=0;
ret:=TRUE;
end;
if ret=FALSE then
H:=GetWindow(H, GW_HWNDNEXT);
end;
HandlePadreCoincide:=ret;
end;
function TForm1.ProcIDFromWnd(Myhwnd: THandle): THandle;
var
idProc: THandle;
begin
GetWindowThreadProcessId(Myhwnd, idProc);
ProcIDFromWnd := idProc;
end;