窗口的parent和owner有什么区别

本文详细解析了Windows环境中Parent与Owner窗口的概念,阐述了两者在窗口层级结构中的作用与区别,包括它们对窗口绘制区域的影响及窗口销毁时的行为。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

CWnd* GetAncestor(UINT gaFlags) const 方法参数 gaFlags 可选值有GA_PARENT,GA_ROOT,GA_ROOTOWNER想请教各位, parentparent和owner有什么区别? 请举例说明,谢谢.

解决方案 »

  1.  
  2.  

    子窗口的parent和owner是同一个窗口,但是普通窗口的parent一般是NULL,owner是桌面

      

     

  3.  

    为什么会有这个区分,从概念上来讲,parent和owner的意义应该各是什么? 各自的责任又是什么?

      

     

  4.  

    一般的说, Parent指控件的父窗口,Owner指顶级窗口的父窗口

      

     

  5.  

    参考这两个api的区别
    GetParent()--
    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. If the window is a top-level unowned window or if the function fails, the return value is NULL. 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. cf.
    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.

      

     

  6.  

    谢谢各位的解释,从这些解释中已经能看出一些Parent 和 Owner 的区别了.同时希望还有人能对这两个概念有更精辟的阐述,MFC或其他框架的设计者对两者区别命名的意图是什么? 应该还有更为明确的分工吧? 希望各位不吝赐教.

      

     

  7.  

    具有父窗口的窗口被限制在父窗口的客户区内,但是被拥有的窗口可以被画在桌面上的任何位置。
    GetParent函数返回直接父窗口的指针。与此不同,GetParentOwner函数返回不是子窗口(不具有WS_CHILD风格)的最直接父窗口或拥有者窗口的指针。下面是MSDN中的解释:
    http://support.microsoft.com/default.aspx?scid=kb;en-us;84190SUMMARY
    In the Windows environment, the following two relationships can exist between windows: • Owner-owned relationship. The owner-owned relationship determines which other windows are automatically destroyed when a window is destroyed. When window A is destroyed, Windows automatically destroys all the windows that are owned by A.  • Parent-child relationship. The parent-child relationship determines where a window can be drawn on the screen. A child window (that is, a window that has a parent) is confined to its parent window's client area. This article discusses these relationships and some Windows functions that provide owner and parent information for a specified window.

      

     

  8.  

    谢谢laiyiling(◆陌生人·V2.0◆)〓优快云(●●) 的解释,非常清楚!

 

 

原文链接;http://www.debugease.com/vc/2480823.html

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值