How to get the z-order in windows?
You can use the GetTopWindow function to search all child windows of a parent window and return a handle to the child window that is highest in z-order. The GetNextWindow function retrieves a handle to the next or previous window in z-order.
GetTopWindow: http://msdn.microsoft.com/en-us/library/ms633514(VS.85).aspx
GetNextWindow: http://msdn.microsoft.com/en-us/library/ms633509(VS.85).aspx
Child Window Z-Order
The documentation is accurate. You are being tripped up by another problem, you allow the child windows to draw themselves across other child windows. So now the painting order matters.
You fix that by adding the WS_CLIPSIBLINGS style flag to your CreateWindowEx call. You'll now see that the OK button is on top. Fix:
btn1 = ::CreateWindow(L"button", L"OK",
WS_TABSTOP|BS_DEFPUSHBUTTON|WS_VISIBLE|WS_CHILD|WS_CLIPSIBLINGS,
10, 10, 50, 30, hWnd, (HMENU)51, hInst, NULL);
// etc, use it as well on other child windows
How to get the second active window in z order?
Call GetWindow
passing GW_HWNDNEXT
.
Get handle of top window (Sort windows by Z index)
I'll help you out:
[DllImport("user32.dll", SetLastError = true)]
static extern IntPtr GetWindow(IntPtr hWnd, GetWindow_Cmd uCmd);
enum GetWindow_Cmd : uint
{
GW_HWNDFIRST = 0,
GW_HWNDLAST = 1,
GW_HWNDNEXT = 2,
GW_HWNDPREV = 3,
GW_OWNER = 4,
GW_CHILD = 5,
GW_ENABLEDPOPUP = 6
}
private IntPtr GetTopmostHwnd(List<IntPtr> hwnds)
{
var topmostHwnd = IntPtr.Zero;
if (hwnds != null && hwnds.Count > 0)
{
var hwnd = hwnds[0];
while (hwnd != IntPtr.Zero)
{
if (hwnds.Contains(hwnd))
{
topmostHwnd = hwnd;
}
hwnd = GetWindow(hwnd, GetWindow_Cmd.GW_HWNDPREV);
}
}
return topmostHwnd;
}
Related Topics
ASP.NET Core 6 How to Access Configuration During Startup
Copy Files from Resources/Streamingassets to Application.Persistentdatapath Upon Installation
A Method for Making Http Requests on Unity iOS
How to Request Administrator Permissions When the Program Starts
How to Work with Time Zones in ASP.NET
Does Java Have Something Like C#'s Ref and Out Keywords
Java Equivalents of C# String.Format() and String.Join()
Signalr(V2.2.0) Ondisconnected Set User Offline
Arkit Body Tracking Using Xamarin and C# Inaccurate
Does C# Have an Equivalent to JavaScript's Encodeuricomponent()
Does Java Have Something Similar to C# Properties
How to Read a .Net Guid into a Java Uuid
Handling Decimal Values in Newtonsoft.JSON
C# Webbrowser Control -- Get Document Elements After Ajax
Parsing Visual Studio Solution Files
Automatically Inotifypropertychanged
Dependent Dll Is Not Getting Copied to the Build Output Folder in Visual Studio