WPF Glass Windows?

Creating a glass window is as simple as calling DwmExtendFrameIntoClientArea in WPF, but that's only half the trick. If you disable aero and get an XP-like skin that starts the pain:

In XP (or disabled aero) you have to call DrawThemeBackground to get "transparent as a feeling", Internet explorer does this too at the very top, try disabling aero and see what.

I prepared an application that does just that, rollback gracefully when Aero is disabled in Windows.Forms.

Question: But to do it in WPF differently, OnRender (OnPaint equiv. In avalon), which gives you a DrawingContext, how to draw using the DrawThemeBackground WINAPI call?

+3
source share
1 answer

Well, you DrawThemeBackgroundneed a device context descriptor, which is a pure Win32 concept ... WPF does not use device contexts or window handles. However, the WPF application is hosted in a Win32 window, and you can get the HWND of this window:

using System.Windows.Interop;

...

IntPtr hwnd = new WindowInteropHelper(this).Handle;

Then you can get the DC for this window using the GetDC API:

[DllImport("user32.dll")]
static extern IntPtr GetDC(IntPtr hWnd);

...

IntPtr hdc = GetDC(hwnd);

Then you should use DrawThemeBackgroundDC with this.

Please note that this is all purely theoretical, I have not tested it ...

+2
source

Source: https://habr.com/ru/post/1719160/


All Articles