# [win32 API/c++] Problems controlling z order of child windows

## Recommended Posts

sipickles    240
Hi, I am trying to layer videos over each other. Imagine I have one big video playing which fills the whole window, then am playing short small clips over the top. I am using the WMPSDK, and can get a video playing on top of another, based on the sample code WMPHost. The videos are all child windows of the application window, the root. I am creating instances of the CWMPHost class from the sample. My problem is I don't seem to be able to order the windows, top to bottom. Here are my attempts, all useless!
//HWND bg; // handle to background video/jpg
// HWND vid; // handle to clip I am trying to overlay

// ignore x and y stuff
SetWindowPos( vid, bg, x, y, w, h, 0 );

SetWindowPos( vid, HWND_TOPMOST, x, y, w, h, 0 );

SetWindowPos( vid, HWND_TOP, x, y, w, h, 0 );
SetWindowPos( bg, HWND_NOTOPMOST, x, y, w, h, 0 );

SetWindowPos( vid, HWND_TOP, x, y, w, h, 0 );
SetWindowPos( bg, HWND_BOTTOM, x, y, w, h, 0 );


I know my handles are good since this works:
// Show video
SetWindowPos(vid, NULL, m_x, m_y, m_w, m_h, SWP_NOREPOSITION | SWP_NOSIZE | SWP_NOZORDER | SWP_SHOWWINDOW );

// Hide video
SetWindowPos(vid, NULL, m_x, m_y, m_w, m_h, SWP_NOREPOSITION | SWP_NOSIZE | SWP_NOZORDER | SWP_HIDEWINDOW );


The ordering of layers seems to be pretty undefined :( Anyone shed any light on this for me? Thank you [Edited by - sipickles on July 8, 2007 11:31:06 AM]

##### Share on other sites
Have you seen this? Window Features

Maybe this is an issue?

Quote:
 To create a layered window, specify the WS_EX_LAYERED extended window style when calling the CreateWindowEx function, or call the SetWindowLong function to set WS_EX_LAYERED after the window has been created. After the CreateWindowEx call, the layered window will not become visible until the SetLayeredWindowAttributes or UpdateLayeredWindow function has been called for this window. Note that WS_EX_LAYERED cannot be used for child windows.

Here's more from that link regarding z-order.

Quote:
 When an application creates a window, the system puts it at the top of the z-order for windows of the same type. You can use the BringWindowToTop function to bring a window to the top of the z-order for windows of the same type. You can rearrange the z-order by using the SetWindowPos and DeferWindowPos functions.

Here is an account of how windows manages it's z-ordering that might be helpful

10 Things I Hate About Win32: Confusing Z ordering

##### Share on other sites
Endurion    5408
Did you try to use the HWND in the second SetWindowPos parameter?

Something like this:

SetWindowPos( bg, HWND_NOTOPMOST, x, y, w, h, 0 );
SetWindowPos( vid, bg, x, y, w, h, 0 );