The scenario is that I have a list of window windows for top-level windows, and I want to move them so that they are ordered in z order of my choice. I started by repeating the list (with the window on which I want to end up from above), calling SetForegroundWindow on each of them. This seems to have worked for a while, but not always, improved a bit when I paused a little between each call.
Is there a better way to do this?
Edit:
It looks like the BeginDeferWindowPos / DeferWindowPos / EndDeferWindowPos is the way to go. However, I cannot get it to work with multiple windows at the same time. When I limit the list of windows to one window, it works correctly. When a list has several windows, it seems to be only one of them. Here is the pseudo-code of what I am doing:
HWND[] windows; HWND lastWindowHandle = 0; HDWP positionStructure = BeginDeferWindowPos(windows.length); for (int i = 0; i < windows.length; i++) { positionStructure = DeferWindowPos(positionStructure, windows[i], lastWindowHandle, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE); } EndDeferWindowPos(positionStructure);
I am sure that this is something small / obvious, I am missing here, but I just do not see it.
windows winapi z-order
Greg shackles
source share