Recent

Author Topic: Child windows of other windows  (Read 2886 times)

xinyiman

  • Hero Member
  • *****
  • Posts: 2256
    • Lazarus and Free Pascal italian community
Child windows of other windows
« on: April 29, 2011, 09:48:34 am »
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;   
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

 

TinyPortal © 2005-2018