What can lead to the parent window not knowing that it has a child dialog?

In my native Windows mobile app, I have a window that creates a dialog. Let's say my window handle is hMainWnd

.

I am creating a dialog using DialogBoxParam()

and passing hMainWnd

as the parent of the dialog:

DialogBoxParam(_,_,hMainWnd,_,_);

      

Let's say a handle to a dialog hDlgWnd

. The dialog GetParent()

returns hMainWnd

as expected:

//We're inside the dialog created above
HWND hParent = GetParent(hDlgWnd); //hParent == hMainWnd

      

Here's a weird thing calling GetWindow()

to find children hMainWnd

is returning NULL

which means it has no children. I expect the function to returnhDlgWnd

//We're inside the main window    
HWND hChild = GetWindow(hMainWnd, GW_CHILD); //hChild == NULL

      

How can a child know his parent when the parent does not know his child?

0


a source to share


2 answers


GetWindow

c GW_CHILD

doesn't seem to fetch streams of descendants, but only child windows. From MSDN :

The resulting handle identifies the child window at the top of the Z order if the specified window is the parent window; otherwise, the found handle is NULL. The function considers only child windows of the specified window. It does not consider descendant streams



What is the difference between a child and a child? I do not know, but EnumChildWindows

can get you what you need.

+3


a source


The window is either a child window (in the WS_CHILD style) or a top-level window.

Top-level windows do not have a parent window, but they can have an owner window. Child windows have a parent but no owner.



The GetParent () function returns the parent of the child window or the owner of the top-level window. Therefore, this is a misnomer - it should be called GetParentOrOwner ().

So what happens is you get the owner of the top-level window from GetParent (), but since it is not a parent, hDlgWnd is not a child of hMainWnd.

0


a source







All Articles