我如何强制 Aero 绘制一个无边框窗口,就像它处于活动状态一样,即使它不是活动的?

发布于 12-15 10:48 字数 1050 浏览 6 评论 0原文

我想要与 Windows 7 任务栏相同的效果。
我看过这个问题: 保持窗口处于活动状态
它工作得很好,但前提是窗口有非客户区。

我的窗口是无边框的,无论我做什么,它的内容(只是黑色背景)都会在不活动时呈现。

我已将窗口标志设置为 Windows 7 任务栏,但没有帮助。

我现在唯一的想法是用边框绘制它并剪掉它们,有没有更好的方法来实现我想要的?

编辑1:
剪切不起作用,剪切边框后,窗口内容呈现为非活动窗口。 Windows 7 任务栏到底是怎么工作的呢?

编辑2:
添加一些照片来更好地解释自己,以下窗口内容是黑色背景。

这是一个非活动窗口(内容呈现有点暗): 非活动窗口

这是一个活动窗口:
活动窗口

如果窗口没有客户区,则内容始终呈现为非活动窗口,但窗口任务栏始终呈现为活动窗口窗口并且它没有任何 NC 区域(至少根据间谍++)。这就是我试图模仿的。

编辑3:
分享我最近的发现。 explorer.exe 主窗口是无框的,并具有以下标志: 资源管理器图像参数

我深入研究了资源管理器的进程 dwmapi.dll 导出函数: Explorer dwmapi.dll导出函数

它使用DwmEnableBlurBehindWindow,就像我一样。
我检查了未记录的序数函数,它们都与将航空玻璃渲染为活动状态无关。

难道 DWM 规则不适用于资源管理器?

I'd like to have the same effect as the windows 7 taskbar.
I've looked in this question:
Keep Window Looking Active
It works great but only if the window has a non-client area.

My window is border-less and the content of it (just a black background) is rendered as it is inactive, no matter what I do.

I've set my window flags just as Windows 7 taskbar but it didn't help.

My only thought at the moment is to draw it with borders and just clip them, is there a better way to achieve what I want?

EDIT 1:
Clipping didn't work, after clipping the borders the window content was rendered as inactive window.
How the hell does windows 7 task-bar works then?

EDIT2:
Adding some photos to explain myself better, The following window content is a black background.

That's an inactive window (the content is rendered kinda dark):
Inactive window

That's an active window:
Active window

If the window has no client area the content is always rendered as inactive window however the windows Taskbar is always rendered as active window and it doesn't have any NC area (at least according to spy++). That's what I'm trying to mimic.

EDIT3:
Sharing my recent discoveries.
explorer.exe main window is frameless and has the following flags:
Explorer image parameters

I dived into the explorer's process dwmapi.dll exported functions:
Explorer dwmapi.dll exported functions

it uses DwmEnableBlurBehindWindow, just as I do.
I've checked the undocumented ordinal functions and none of them is related to rendering the aero glass as active.

Could it be the DWM rules don't apply to explorer?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

感悟人生的甜2024-12-22 10:48:09

棘手的一个..
使用“DwmSetWindowAttribute”API 将 NCRenderingPolicy 设置为启用。
http://msdn.microsoft。 com/en-us/library/windows/desktop/aa969524(v=vs.85).aspx

    [DllImport("dwmapi.dll", PreserveSig = false)]
    public static extern int DwmSetWindowAttribute(IntPtr hwnd, int attr, ref int attrValue, int attrSize);

    [Flags]
    public enum DwmWindowAttribute
    {
        NCRenderingEnabled = 1,
        NCRenderingPolicy,
        TransitionsForceDisabled,
        AllowNCPaint,
        CaptionButtonBounds,
        NonClientRtlLayout,
        ForceIconicRepresentation,
        Flip3DPolicy,
        ExtendedFrameBounds,
        HasIconicBitmap,
        DisallowPeek,
        ExcludedFromPeek,
        Last
    }

    [Flags]
    public enum DwmNCRenderingPolicy
    {
        UseWindowStyle,
        Disabled,
        Enabled,
        Last
    }

    public static bool SetNCRenderingActive(IntPtr Handle)
    {
        int renderPolicy = (int)DwmNCRenderingPolicy.Enabled;            
        return (DwmSetWindowAttribute(Handle, (int)DwmWindowAttribute.NCRenderingPolicy, ref renderPolicy, sizeof(int)  ) == 0);
    }

Tricky one..
set the NCRenderingPolicy to Enabled with the "DwmSetWindowAttribute" API.
http://msdn.microsoft.com/en-us/library/windows/desktop/aa969524(v=vs.85).aspx

    [DllImport("dwmapi.dll", PreserveSig = false)]
    public static extern int DwmSetWindowAttribute(IntPtr hwnd, int attr, ref int attrValue, int attrSize);

    [Flags]
    public enum DwmWindowAttribute
    {
        NCRenderingEnabled = 1,
        NCRenderingPolicy,
        TransitionsForceDisabled,
        AllowNCPaint,
        CaptionButtonBounds,
        NonClientRtlLayout,
        ForceIconicRepresentation,
        Flip3DPolicy,
        ExtendedFrameBounds,
        HasIconicBitmap,
        DisallowPeek,
        ExcludedFromPeek,
        Last
    }

    [Flags]
    public enum DwmNCRenderingPolicy
    {
        UseWindowStyle,
        Disabled,
        Enabled,
        Last
    }

    public static bool SetNCRenderingActive(IntPtr Handle)
    {
        int renderPolicy = (int)DwmNCRenderingPolicy.Enabled;            
        return (DwmSetWindowAttribute(Handle, (int)DwmWindowAttribute.NCRenderingPolicy, ref renderPolicy, sizeof(int)  ) == 0);
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文