休眠后的Windows Aero玻璃背景被打破。我该如何解决这个问题?这个问题、我该、如何解决、背景

2023-09-07 10:34:22 作者:若隱若現要怎麼透

我正在开发的C#.NET 3.5的WPF程序。它工作在Windows XP,Windows Vista和Windows 7。在新的操作系统我wantet创建Aero的玻璃的背景。因此,这是唯一的一个特别的设计。休眠后,在挂起后或更改Windows Desings一个基本的设计和回AERO所有添加的玻璃后,将显示全黑的。

I am developing a program in C# .net 3.5 wpf. It has to work on windows xp, windows vista and windows 7. On the newer operation systems I wantet to create the background in Aero Glass. So this is only a special design. After hibernate, after suspending or after changing windows Desings to a basic design and back to aero all the added glass is displayed completely black.

我通过GlassHelper类显示器玻璃(可与谷歌中找到)。

I display Glass via the GlassHelper Class (can be found with Google).

其实我看到3种方式来解决这个问题。首先是,是啊,去解决它。但我读somwhere,这是管理的code中的Windows中的一个错误,所以我别无选择,来解答它。纠正我,如果我错了。

Actually I see 3 ways to solve this problem. The first is, yea to solve it. But i read somwhere, that this is a bug in the Windows Managed Code so I have no option to sovle it. Correct me, if I am wrong.

所以,我有想法关闭窗口每次,它最小化,并完全重建,在它那用于下一次。

So I had the idea to close the window everytime, it is minimized and to rebuild completely, when it s used next time.

这工作得很好。经过冬眠的窗口仍显示黑色的,但我没有退出应用程序,我仍然可以将其最小化并再次最大化。

That works quite well. After hibernate the window is still displayed black, but i do not have to quit the application, i can still minimize it and maximize again.

现在我看到的方式:

1)我关闭窗口每次,计算机暂停,休眠或更改设计。我再次打开它的窗口,当它是保存。但是,我怎么能处理呢?

1) I close the window everytime, the computer suspends, hibernates or changes the design. And I open it the window again, when it is save. But how can I handle this?

2)我同意,该窗口将显示为黑色,直到有人最大限度地减少它。 (不是我喜欢的),但后来我得到一个新的问题:在任务栏上的按钮。 (不是托盘图标)。我需要它来进行永久展示。在WinXP我需要它来打开的窗口,最小化时。特别是在WIN7我需要它,因为我想用一些Superbar的新优势! (在preVIEW由hoovering不会是窗口,这将是一个静态图象。)

2) I accept, that the window will be displayed in black, until someone minimizes it. (Not my favourite) But then I get a new Problem: The Button in The Taskbar. (Not the Tray Icon). I need it to be displayed permanently. On winxp i need it to open the window, when minimized. And especially on win7 I need it because I want to use some of the new Advantages of the Superbar! (the preview by hoovering will not be the window, it will be a static picture.)

谢谢大家,对我的帮助!

Thank you everyone, for helping me!

推荐答案

好了,谢谢大家!但我想我找到了我自己的解决方案!

Ok, thank you everyone! But I think I found my own solution!

我处理好消息:WM_DWMCOMPOSITIONCHANGED(0x031E)及WM_THEMECHANGED(0x031A)

I handle the Messages: WM_DWMCOMPOSITIONCHANGED (0x031E) & WM_THEMECHANGED (0x031A)

和上醒目的消息之一,我只是重新分配的玻璃或根据DwmIsCompositionEnabled()。

and on catching one of those messages I simply assign the glass again or a new background depending on DwmIsCompositionEnabled().

其实我也有类似下面的内容:

Actually I have something similar to the following:

const int WM_THEMECHANGED = 0x031A;
const int WM_DWMCOMPOSITIONCHANGED = 0x031E;

private static void ApplyTheme(IntPtr hwnd)
{
    if (DwmIsCompositionEnabled())
    {
        HwndSource.FromHwnd(hwnd).CompositionTarget.BackgroundColor = Colors.Transparent;
        MARGINS margins = new MARGINS(new Thickness(-1));
        DwmExtendFrameIntoClientArea(hwnd, ref margins);
    }
    else
    {
        HwndSource.FromHwnd(hwnd).CompositionTarget.BackgroundColor = SystemColors.ActiveCaptionBrush.Color;
    }
}

private static IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
{
    if (msg == WM_THEMECHANGED)
    {
        ApplyTheme(hwnd);
    }
    if (msg == WM_DWMCOMPOSITIONCHANGED)
    {
        ApplyTheme(hwnd);
    }
    return IntPtr.Zero;
}

我得到的HWND。

I get the hwnd.

我把它挂。

HwndSource.FromHwnd(hwnd).AddHook(new HwndSourceHook(WndProc));

我做WPF窗口背景透明的,因为后来,在WndProc的功能,我将只能够访问我的HWND背景的(Win32)。

I make the WPF Window Background transparent, because later, in the WndProc function I will only be able to access my hwnd Background (Win32).

window.Background = Brushes.Transparent;

而现在我只需要指定样式的第一次:

And now I only have to assign the style for the first time:

ApplyTheme(hwnd);

这就是它!作品完美的我(赢64家premium)后,我禁用或启用航空,不同的航空和非航空风格或休眠状态之间进行切换,因此正是,我一直在寻找。谢谢你,为你的伟大的想法!

Thats it! Works perfectly for me (Win 64 Home Premium) after I disable or enable aero, switch between different aero or non-aero styles or hibernate, so it is exactly, what I was looking for. Thank you, for your great ideas!