To read this description, it seems GetAncestor(hwnd, GA_ROOT) just
calls GetParent(hwnd) to retrieve the parent window. On the other
hand, GetAncestor(hwnd, GA_ROOTOWNER) calls GetParent(hwnd) and calls
GetWindow(hwnd, GW_OWNER) if GetParent(hwnd) returns NULL. To read
through the MSDN document (*1) which writes differences between an
owned window and a child window, a dialog created with CreateDialog()
is usually an owned window but it is not a child window. So, we need
to use GetAncestor(hwnd, GA_ROOTOWNER) when we need to get the
top-level window from a dialog? (I'm not so confident of my opinion,
though.)
(*1) <http://msdn.microsoft.com/en-us/library/ms632599(VS.85).aspx>.
Best regards,
Hironori Bono
E-mail: hb...@chromium.org
> --
> Chromium Developers mailing list: chromi...@chromium.org
> View archives, change email options, or unsubscribe:
> http://groups.google.com/a/chromium.org/group/chromium-dev
>
Greetings Marshall,
To read this description, it seems GetAncestor(hwnd, GA_ROOT) just
calls GetParent(hwnd) to retrieve the parent window. On the other
hand, GetAncestor(hwnd, GA_ROOTOWNER) calls GetParent(hwnd) and calls
GetWindow(hwnd, GW_OWNER) if GetParent(hwnd) returns NULL. To read
through the MSDN document (*1) which writes differences between an
owned window and a child window, a dialog created with CreateDialog()
is usually an owned window but it is not a child window. So, we need
to use GetAncestor(hwnd, GA_ROOTOWNER) when we need to get the
top-level window from a dialog? (I'm not so confident of my opinion,
though.)
All of this indicates the following:
1. GetAncestor(hwnd, GA_ROOTOWNER) walks the child hierarchy using GetParent() to reach the top-level window.
2. GetAncestor(hwnd, GA_ROOT) returns the current dialog window.
So, in conclusion, if the intent is to retrieve the top-level window we should be using GetAncestor(hwnd, GA_ROOTOWNER) and if the intent is to return the current dialog window we should be using GetAncestor(hwnd, GA_ROOT).
I can't comment on _proper_ usage, but I can comment that in all code I've written and read I've used GA_ROOT, and I never even knew GA_ROOTOWNER existed.I bet this is a case of copy and pasting (on both sides) without understanding. A close reading of MSDN plus fixing all our code to do the right thing everywhere might be good.
PK
To make the usage clearer for the future what do you think about adding new functions to win_util and using those functions instead of calling GetAncestor() directly?
/* Returns the root ancestor window closest to |hwnd|. Root windows have style
WS_OVERLAPPED or WS_POPUP. If |hwnd| is a root window then |hwnd| will
be returned. If |hwnd| has style WS_CHILD then the closest root ancestor window
will usually be the top-level dialog that contains |hwnd|. */
HWND GetClosestRootAncestor(HWND hwnd) {
return ::GetAncestor(hwnd, GA_ROOT);
}
/* Returns the root ancestor window furthest from |hwnd|. Root windows have style
WS_OVERLAPPED or WS_POPUP. The furthest root ancestor window will
usually be the main application window. */
HWND GetFurthestRootAncestor(HWND hwnd) {
return ::GetAncestor(hwnd, GA_ROOTOWNER);
}
PK
Thank you for your experiment. It's awesome.
Best regards,
Hironori Bono
E-mail: hb...@chromium.org
2010/2/17 Marshall Greenblatt <magree...@gmail.com>: