Search code examples
delphiwinapidelphi-7

Find out if a window has a child window


I get a window handle using this code:

var h: THandle;
...
h := FindWindow('MozillaWindowClass', NIL);

h is valid (> 0).

How do I find out if this window has ANY children windows?

I cannot use FindWindowEx(), as it requires a class name.

What I want to accomplish here is to find out if the MozillaWindowClass window belongs to Thunderbird or Firefox. It looks like Thunderbird has a MozillaWindowClass without children, but Firefox not, so it would be a quick way to find out. (I cannot go about the process name using CreateToolhelp32Snapshot(), because my code needs to run also on Windows 2000).


Solution

  • The simplest way to determine whether or not a window has any children is to call GetWindow passing GW_CHILD.

    function HasChildren(Window: HWND): Boolean;
    begin
      Result := GetWindow(Window, GW_CHILD)<>0;
    end;