[Qt Records] Windows Window Hierarchy (Z-order)

Function: The software has a prompt pop-up window, I hope it will always be on the top to ensure that the window will not be blocked under any circumstances.

Based on the above question, I found the corresponding api and found SetWindowPos().

Before talking about this function, understand the following concepts:

Z-order (Z order)

In fact, it is better to translate this thing into the Z axis .

First of all, for the display, the upper left corner is the coordinate origin, the right is the x-axis, and the downward is the y-axis. In addition, from the inside to the outside is the z-axis, which is the so-called Z-order.

top of the Z order: The topmost layer of the Z axis, although it is the topmost in the Z order, it is not necessarily the topmost.

According to the order of the Z axis, from outside to inside, they are: top window - top window - sub window . The top window has TOPMOST style.

We are constantly changing the Z sequence while clicking to use different windows. Because the system will place the window you click (active window) on top of the same kind of windows in the Z sequence (top-level window). When a window becomes a top-level window, its child windows also become top-level windows.

Finally, to sum up, the order of sorting is: TOPMOST window—top-level window—non-top-level window

SetWindowPos() function:

BOOL SetWindowPos (
    HWND hWnd, //窗口句柄
    HWND hWndInsertAfter,  //原本可以是定位的窗口之前的窗口的句柄,但是主要使用的是一些参数。
    int X,
    int Y, //窗口左上角的x,y
    int cx,
    int cy, //窗口的宽度和高度
    UINT uFlags //窗口大小和位置标志,也是一些参数,具体参数比较多,详见MSDN。
);

Mainly explain the second parameter: hWndInsertAfter
Please add a picture description
above cut from MSDN, explain:

  • HWND_BOTTOM: Places the window at the bottom of the Z order.
  • HWND_NOTOPMOST: Positions the window above all non-topmost windows (that is, behind all topmost windows).
  • HWND_TOP: Puts the window at the top of the Z order.
  • HWND_TOPMOST: Position the window above all topmost windows. Even if the window is disabled, the window will maintain its topmost position.

From top to bottom, getting closer to the front, TOPMOST is the top window.

Ps: I found an error in the explanation on the MSDN official website. The first sentence of Meaning after HWND_TOPMOST should be: Places the window above all topmost windows. It’s too bad.

MSDN address: https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-setwindowpos

Guess you like

Origin blog.csdn.net/qq_41214278/article/details/128160589