SetLayeredWindowAttributes 和 WS_CHILD
对于使用 WS_CHILD 样式创建的窗口,如何获得与 SetLayeredWindowAttributes 相同的效果?有什么解决方法吗?来自 MSDN:
要创建分层窗口,请在调用CreateWindowEx函数时指定WS_EX_LAYERED扩展窗口样式,或者在窗口创建后调用SetWindowLong函数设置WS_EX_LAYERED。在 CreateWindowEx 调用之后,分层窗口将不会变得可见,直到为此窗口调用 SetLayeredWindowAttributes 或 UpdateLayeredWindow 函数。请注意,WS_EX_LAYERED 不能用于子窗口。
How can I get the same effect as SetLayeredWindowAttributes for windows created with WS_CHILD style? Is there any workaround? From MSDN:
To create a layered window, specify the WS_EX_LAYERED extended window style when calling the CreateWindowEx function, or call the SetWindowLong function to set WS_EX_LAYERED after the window has been created. After the CreateWindowEx call, the layered window will not become visible until the SetLayeredWindowAttributes or UpdateLayeredWindow function has been called for this window. Note that WS_EX_LAYERED cannot be used for child windows.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在设置子窗口的透明之前,请执行以下操作:
首先为其 MDI 主窗口设置 (
SetWindowLong
&SetLayeredWindowAttributes
),那么它将直接对孩子起作用。
Before you set transparent of child do it:
First set for the MDI Main window of it (
SetWindowLong
&SetLayeredWindowAttributes
),then it will work for the child directly .
子窗口不能分层 - 该样式仅对具有 WS_POPUP 样式的窗口有效。解决此问题的一种可能方法(不太优雅)是创建一个具有 WS_POPUP 样式的窗口,并在移动“父”窗口时同步其位置。
The child window cannot be layered - this style has effect for the windows with WS_POPUP style only. One possible way (not so elegeant) to resolve this problem is create a window with WS_POPUP style and syncronize its position when the "parent" window is being moved.
您可以将.manifest文件添加到您的Visual Studio解决方案中,但这仅支持Win8.1及更高版本。
您可以将以下内容保存到WindowLayer.manifest中,并包含在您的项目中,再次构建,CreateWindowEx with WS_EX_LAYERED with WS_CHILD 将工作,我对此进行了测试,它在我的win10计算机上工作。
you can add a .manifest file to your Visual Studio Solution, but this only support Win8.1 and later version.
You can save following content into WindowLayer.manifest, and include in your project, build again, CreateWindowEx with WS_EX_LAYERED with WS_CHILD will be work, i tested this, it worked on my win10 computer.