窗口的parent和owner有什么区别

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◆)〓CSDN(●●) 的解释,非常清楚!

 

 

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

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
### 回答1: match_parent和wrap_content是Android中常用的布局属性,它们的作用是控制View的宽度和高度。 match_parent表示View的宽度或高度将填充父容器的宽度或高度,即View的大小与父容器相同。 wrap_content表示View的宽度或高度将根据View的内容自适应,即View的大小将根据内容自动调整。 因此,match_parent和wrap_content的区别在于它们控制View大小的方式不同。 ### 回答2: 在Android中,`match_parent`和`wrap_content`是用于定义视图宽度或高度的属性。 `match_parent`是指将视图的尺寸扩展到其父视图的尺寸。当设置一个视图的宽度或高度为`match_parent`时,视图将尽可能地填充整个父视图的可用空间,使其尺寸与父视图的尺寸相匹配。 `wrap_content`是指视图将根据其内容自动调整尺寸。当设置一个视图的宽度或高度为`wrap_content`时,视图将根据其内容的大小来调整自身的尺寸,以完全包含内容。 两者的区别在于`match_parent`会将视图的大小扩展到与父视图一致,而`wrap_content`会根据内容自动调整视图的大小。通常情况下,当我们希望视图充满整个父视图时,可以使用`match_parent`;当我们希望视图根据自身内容调整大小时,可以使用`wrap_content`。 需要注意的是,尽管在布局文件中`match_parent`被写作`match_parent`,在代码中使用`LayoutParams`时,需要使用`MATCH_PARENT`常量代替。同样,`wrap_content`在代码中使用`LayoutParams`时,需要使用`WRAP_CONTENT`常量代替。 ### 回答3: match_parent和wrap_parent是Android中布局属性的两个常用值。 1. match_parent:表示布局元素的尺寸将填充其父容器的剩余空间。也就是说,如果将一个控件的宽度或高度设置为match_parent,它将与父容器的宽度或高度相等。可以理解为控件会被拉伸至父容器的尺寸。 2. wrap_content:表示布局元素的尺寸将根据其内容进行调整。也就是说,控件的宽度或高度会根据内容的大小来自适应。wrap_content可以理解为控件的尺寸会根据内容的大小进行包裹。 区别: 1. match_parent会将控件的尺寸设置为与父容器相等,而wrap_content会根据内容的大小自适应尺寸。 2. match_parent会将控件拉伸至父容器的边界,而wrap_content会根据内容的大小进行包裹。 3. match_parent可以用于任何包含子元素的容器中,而wrap_content只有在子元素有明确的宽高度或内部尺寸大小时才有效。 4. 当父容器确定好自己的尺寸后,match_parent会根据父容器的尺寸进行计算,而wrap_content会先根据自身内容进行计算,然后再根据内容来设置具体尺寸,可能会影响布局的实际效果。 总之,match_parent主要用于充满父容器的情况,而wrap_content用于根据内容自适应尺寸。根据实际需求选择合适的属性可以更好地布局控件。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值