The background of Windows Aero Glass is broken after hibernation. How can i solve this?

I am developing a program in C # .net 3.5 wpf. It should work on Windows XP, Windows Vista and Windows 7. On new operating systems, I want to create a background in Aero Glass. So this is just a special design. After hibernation, after pausing, or after changing windows. Turning to the basic design and back to the aero, all added glass is displayed completely black.

I am showing Glass through the GlassHelper class (can be found on Google).

In fact, I see three ways to solve this problem. First, yes, to solve this. But I read somwhere that this is a bug in Windows-driven code, so I have no way to resolve it. Correct me if I am wrong.

Therefore, I had the idea to close the window every time, it was minimized and fully restored when it was used the next time.

It works very well. After hibernation, the window is still displayed in black, but I do not need to leave the application, but I can still minimize it and increase it again.

Now I see the ways:

1) I close the window every time the computer pauses, hibernates or changes the design. And I again open this window when it is saved. But how can I handle this?

2) I accept that the window will be displayed in black until someone minimizes it. (Not my favorite) But then I have a new problem: a button on the taskbar. (Not a tray icon). I need it to display forever. In winxp, I need to open a window when it is minimized. And especially on win7, I need this because I want to use some of the new advantages of Superbar! (Previewing with hoovering will not be a window, it will be a static image.)

Thanks everyone for the help!

0
source share
3 answers

Ok, thanks everyone! But I think I found my solution!

I process messages: WM_DWMCOMPOSITIONCHANGED (0x031E) and WM_THEMECHANGED (0x031A)

and when one of these messages is detected, 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; } 

I get hwnd.

I plug it in.

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

I am making the WPF background background transparent, because later, in the WndProc function, I can access my hwnd (Win32) background.

 window.Background = Brushes.Transparent; 

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

 ApplyTheme(hwnd); 

Here it is! Works great for me (Win 64 Home Premium) after I turned off or on aero, switched between different types of aerons or non-aerosons, or hibernate, so this is exactly what I was looking for. Thanks for the great ideas!

+1
source

Try to process the WM_NCCALCSIZE message and reduce the client area (NCCALCSIZE_PARAMS.rgrc0) by one pixel. I'm serious. I found that this solution is used in Google Chrome and it works great for me.

+1
source

You can take a look at the WPF Shell integration library . I can recall that there were problems with this library due to an error in the Window Window Manager in Windows 7. The library has its source, so you can see how they deal with it.

0
source

All Articles