Children's window Z-Order

I see on MSDN, he said:

If the created window is a child window , its default position is at the bottom of the Z-order . If the created window is a top-level window, its default position is at the top of the Z-order (but below all upper windows, unless the created window is the topmost). ( http://msdn.microsoft.com/en-us/library/windows/desktop/ms632680(v=vs.85).aspx )

However, another documentation says: When an application creates a window, the system places it at the top of the z-order for windows of the same type ( http://msdn.microsoft.com/en-us/library/windows/desktop/ms632599 ( v = vs. 85) .aspx )

And as I tested it,

btn1 = ::CreateWindow(L"button", L"OK", WS_TABSTOP|BS_DEFPUSHBUTTON|WS_VISIBLE|WS_CHILD , 10, 10, 50, 30, hWnd, (HMENU)51, hInst, NULL); btn2 = ::CreateWindow(L"button", L"Cancel", WS_TABSTOP|WS_CHILD|BS_PUSHBUTTON|WS_VISIBLE , 20, 20, 70, 30, hWnd, (HMENU)52, hInst, NULL); 

a newly created child window (for example: I created two buttons in the window, and they overlapped, I see that the button created later closes the first created button)

This is the first statement in MSDN that contradicts my testing.

+4
source share
2 answers

The documentation is accurate. You are faced with another problem, you are allowing child windows to draw on top of other child windows. So now the order of coloring matters.

Fix this by adding the WS_CLIPSIBLINGS style flag to the CreateWindowEx call. Now you will 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 
+7
source

You should not rely heavily on how the child windows are displayed and which one is drawn last. If I run the sample code, I get the OK button, which is blocked by the Cancel button. If I hover over the buttons, the OK button will appear in the foreground and draw the Cancel button.

I once had problems with overlapping child controls. Then I found out that Microsoft says that overlapping controls are not supported by Windows .

By the way, if you really want to see the Z-order, use GetTopWindow and GetNextWindow . Or easier: run Microsoft Spy++ .

+2
source

Source: https://habr.com/ru/post/1492071/


All Articles