窗口的parent 和 owner 区别

Q: What is a top-level window?
A : A  top-level window  is a window that is not  child , i.e. it has not WS_CHILD style set.
Notes
  • unlike the child windows, a top-level window can be displayed anywhere in the screen;
  • many definitions state that a top-level window is "a window that has no parent"
    that is correct but can lead in a confusion: many people think that every window which is created passing a valid hWndParent in CreateWindow(Ex) "has a parent" then, according to the definition it is not top-level
    in fact hWndParent may be either a handle to parent or owner window; 
    if hWndParent is a valid window handle and WS_CHILD style is not set, then we have a top-level owned window;
  • top-level window can or can not be owned but is never a child; further we can say that it can have an owner but never has aparent.
  • top-level windows can be either overlapped windows (having WS_OVERLAPPED style and generally used as application main window) or popup windows (having WS_POPUP style, usually temporary windows like message boxes and dialogs);
  • the coordinates used in CreateWindow(Ex), MoveWindow, SetWindowPos, and so on are always scren coordinates (relative to top-left corner of the screen).
Examples
Code:
// create a top-level window (not owned)
HWND hWnd = CreateWindow(szWindowClass, szTitle, 
              WS_OVERLAPPED, // WS_CHILD style is not set, so it's a top-level window.
              CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, 
              NULL,          // no handle to the owner, so it's not owned.
              NULL, hInstance, NULL);
Code:
// create a top-level window (owned)
HWND hWnd = CreateWindow(szWindowClass, szTitle, 
              WS_OVERLAPPED, // WS_CHILD style is not set, so it's a top-level window
              CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, 
              hWndParent,    // handle to the owner, so it's an owned window
              NULL, hInstance, NULL);

child window

A window that has the WS_CHILD style. A child window always appears within the client area of its parent window. 


GetParent  

The GetParent function retrieves a handle to the specified window's parent or owner. 

If the window is a child window, the return value is a handle to the parent window. If the window is a top-level window, the return value is a handle to the owner window


CWnd::GetOwner

Retrieves a pointer to the owner of the window. If the window has no owner, then a pointer to the parent window object is returned by default. Note that the relationship between the owner and the owned differs from the parent-child aspect in several important aspects. For example, a window with a parent is confined to its parent window’s client area. Owned windows can be drawn at any location on the desktop. 



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值