SetLayeredWindowAttributes 和 WS_CHILD

发布于 2024-11-05 01:07:41 字数 336 浏览 0 评论 0原文

对于使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

无所谓啦 2024-11-12 01:07:41

在设置子窗口的透明之前,请执行以下操作:

首先为其 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 .

本宫微胖 2024-11-12 01:07:41

子窗口不能分层 - 该样式仅对具有 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.

千纸鹤 2024-11-12 01:07:41

您可以将.manifest文件添加到您的Visual Studio解决方案中,但这仅支持Win8.1及更高版本。

您可以将以下内容保存到WindowLayer.manifest中,并包含在您的项目中,再次构建,CreateWindowEx with WS_EX_LAYERED with WS_CHILD 将工作,我对此进行了测试,它在我的win10计算机上工作。

<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
  <compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1"> 
    <application>
        <!--The ID below indicates application support for Windows Developer Preview -->
        <supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}"/>
    </application>
  </compatibility>
  <dependency>
    <dependentAssembly>
        <assemblyIdentity
            type="win32"
            name="Microsoft.Windows.Common-Controls"
            version="6.0.0.0"
            processorArchitecture="*"
            publicKeyToken="6595b64144ccf1df"
            language="*"
        />
    </dependentAssembly>
  </dependency>
</assembly>

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.

<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
  <compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1"> 
    <application>
        <!--The ID below indicates application support for Windows Developer Preview -->
        <supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}"/>
    </application>
  </compatibility>
  <dependency>
    <dependentAssembly>
        <assemblyIdentity
            type="win32"
            name="Microsoft.Windows.Common-Controls"
            version="6.0.0.0"
            processorArchitecture="*"
            publicKeyToken="6595b64144ccf1df"
            language="*"
        />
    </dependentAssembly>
  </dependency>
</assembly>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文