CWnd* GetAncestor(UINT gaFlags) const 方法参数 gaFlags 可选值有GA_PARENT,GA_ROOT,GA_ROOTOWNER想请教各位, parentparent和owner有什么区别? 请举例说明,谢谢.
解决方案 »
-
子窗口的parent和owner是同一个窗口,但是普通窗口的parent一般是NULL,owner是桌面
-
为什么会有这个区分,从概念上来讲,parent和owner的意义应该各是什么? 各自的责任又是什么?
-
一般的说, Parent指控件的父窗口,Owner指顶级窗口的父窗口
-
参考这两个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. -
谢谢各位的解释,从这些解释中已经能看出一些Parent 和 Owner 的区别了.同时希望还有人能对这两个概念有更精辟的阐述,MFC或其他框架的设计者对两者区别命名的意图是什么? 应该还有更为明确的分工吧? 希望各位不吝赐教.
-
具有父窗口的窗口被限制在父窗口的客户区内,但是被拥有的窗口可以被画在桌面上的任何位置。
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. -
谢谢laiyiling(◆陌生人·V2.0◆)〓CSDN(●●) 的解释,非常清楚!