Professional UI Solutions
Site Map   /  Register
 
 

Forum

Please Log In to post a new message or reply to an existing one. If you are not registered, please register.

NOTE: Some forums may be read-only if you are not currently subscribed to our technical support services.

Forums » Prof-UIS Tech Support » How to find the Z-Order of CWnd? Collapse All
Subject Author Date
Chun Pong Lau Jul 18, 2008 - 2:26 AM

Dear support team,

This question is not really related to PROF-UIS. Just see if you can give us an easy answer.

Z-order in windows application determines the order of window arranged vertically on desktop.

The question is how to find out the z-order of a specific window (CWnd)?

Thanks a lot.

Regards,
Chun Pong

Chun Pong Lau Jul 18, 2008 - 1:02 PM

Thank you for your kind response. It really helps.

Technical Support Jul 18, 2008 - 6:42 AM

All the windows on the desktop are organized into tree layout. This is related both for popup and child window. If you have some HWND window handle or CWnd* pointer, then you can start navigate window tree:

1) You can get parent window using ::GetParent() Win32 API or CWnd::GetParent() method.

2) You can get first sibling window (first window on the same level) using ::GetNextWindow() Win32 API or CWnd::GetNextWindow() method with GW_HWNDFIRST parameter. For example, first sibling window for OK button in some dialog is the first dialog control.

3) You can get last sibling window (last window on the same level) using ::GetNextWindow() Win32 API or CWnd::GetNextWindow() method with GW_HWNDLAST parameter.

4) You can get previous sibling window (previous window on the same level) using ::GetNextWindow() Win32 API or CWnd::GetNextWindow() method with GW_HWNDPREV parameter.

5) You can get next sibling window (next window on the same level) using ::GetNextWindow() Win32 API or CWnd::GetNextWindow() method with GW_HWNDNEXT parameter.

6) You can get first child window using ::GetNextWindow() Win32 API or CWnd::GetNextWindow() method with GW_CHILD parameter.

7) You can last first child window using two invocations of the ::GetNextWindow() Win32 API or CWnd::GetNextWindow() method: first invocation with GW_CHILD parameter will return first child window and second invocation with GW_HWNDLAST parameter will return last sibling window of first child window.

As you can see, the children windows of each window are organized into linked list (similar to CList in MFC or std::list in STL). So, It’s not possible to get child window by its index. You should walk through list of child windows instead.

Of course windows ca be created and destroyed anytime at run-time. If you need to save reference to some window, then please save its HWND window handle and not use CWnd* pointers because these pointers can be temporarily. You can use the ::IsWindow() Win32 API for detecting whether the specified HWND handle is valid window handle. The CWnd::FromHandlePermanent() and CWnd::FromHandle() methods (see MSDN for details) should be used for conversion from HWND window handle into CWnd* pointer.