子窗口 Z 顺序 [英] Child Window Z-Order

查看:29
本文介绍了子窗口 Z 顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 MSDN 上看到,它说:

I see in MSDN, it said:

如果创建的窗口是子窗口,其默认位置在Z-order的底部.如果创建的窗口是一个顶层窗口,它的默认位置是在 Z 顺序的顶部(但在所有最顶层的窗口之下,除非创建的窗口本身是最顶层的).(http://msdn.microsoft.com/en-us/library/windows/desktop/ms632680(v=vs.85).aspx)

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 beneath all topmost windows unless the created window is itself topmost). (http://msdn.microsoft.com/en-us/library/windows/desktop/ms632680(v=vs.85).aspx)

然而,另一个文档说:当应用程序创建一个窗口时,系统将它放在相同类型窗口的 z 顺序的顶部(http://msdn.microsoft.com/en-us/library/windows/desktop/ms632599(v=vs.85).aspx)

However, another documentation said: When an application creates a window, the system puts 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)

当我这样测试时,

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);

新创建的子窗口(例如:我在一个窗口中创建了两个按钮并且它们重叠,可以看到后面创建的按钮覆盖了创建的第一个按钮)

the new created child window(for example: I created two buttons in a window and they overlapped, I can see that the button created later is covering the first button created)

MSDN 中的第一条语句是否与我的测试相矛盾.

Is the first statement in MSDN contradictory to my testing.

推荐答案

文档准确.你被另一个问题绊倒了,你允许子窗口在其他子窗口上绘制自己.所以现在绘画顺序很重要.

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.

您可以通过向 CreateWindowEx 调用添加 WS_CLIPSIBLINGS 样式标志来解决该问题.您现在将看到确定按钮位于顶部.修复:

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

这篇关于子窗口 Z 顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆