Win32 Window Owner vs. Parent Window?

In Win32 programming, what is the difference between a window parent and window owner? I thought I understood if I understood this code:

SetWindowLong(handle, GWL_HWNDPARENT, foo); 

This actually sets the owner of the window, not the parent - despite using GWL_HWNDPARENT. Are the terms parent / owner interchangeable, or is there a difference?

+44
winapi parent window
Feb 03 '09 at 16:30
source share
5 answers

The owner is the window * responsible for the management or dialogue (for example, responsible for creating / destroying the window).

The parent is the next major window * for control or dialogue in the window chain, but is not really responsible for it (it does not necessarily care about its life cycle, etc.). The parent of the window can also be its owner.

* Window against the window: the window is the actual window displayed on the screen; window - any object with HWND (including buttons, panels, etc.).

+17
Feb 03 '09 at 16:47
source share
— -

Ownership is the relationship between two top-level windows, while Parent is the relationship between the upper level and WS_CHILD, or WS_CHILD and another WS_CHILD.

The button's parent is the form in which it is included, and the message box belongs to the form that displayed it.

Read this article from the Microsoft Win32 Hierarchy and Window Styles for a clearer picture of ownership, parent, ZOrder, SetWindowLong, GetWindow, and all the other nasty bits of the Win32 api for creating window relationships.

EDIT: It looks like Microsoft has brought down this content, here is another reasonable summary of Ownershiphip / Parenting .

+23
Mar 05 '09 at 17:23
source share
+16
Mar 16 '11 at 13:14
source share

Explained fully in msdn

+6
Jul 01 '10 at 13:00
source share

Chen's blog post is the one to read. The key point for me is that the WS_CHILD style should be used in the child window. You can try to create a child window and pass the parent handle to CreateWindow (), but if you do not have the WS_CHILD style set, the two windows will have an owner relationship, not a parent / child relationship.

0
Jan 18 '15 at 17:12
source share



All Articles