Search code examples
win32gui

Why does a dialogue's parent window not have the dialogue as a child?


I've noticed that in most (if not all) applications in Windows, a dialogue doesn't have a bidirectional reference relative to its parent. I.e. The parent of the dialogue doesn't appear to have a reference to the dialogue in the child window list. I've noticed this before but now its really bugging me. Is this by design? Is there a way to get the handle to a window's dialogue(s) (one if modal, one or more if non-modal), given only the window's handle?


Solution

  • I think you might be confusing parent with owner. There is a distinction between a child window and an owned window. Both are established using either SetParent() or the hwndParent parameter of CreateWindow/Ex(), but the difference is that an owned window is a top-level overlapped/popup window that does not have the WS_CHILD style flag (except for a few top-level windows that are owned by the system). Child windows can be enumerated using EnumChildWindows(), whereas there is no single API to enumerate owned windows. You would have to use EnumWindows() to enumerate top-level windows, using GetParent()/GetWindow(GW_OWNER) to check if each window is owned by a specific owner.