I have an application i am currently working on which uses Aero glass in some areas but the areas that don't have aero are shown in black.
I am trying to figure out why that is.
Code:
using System.Runtime.InteropServices;
using System.Windows.Interop;
using System.Windows.Media;
using System.Windows;
using System;
namespace Test
{
public partial class MainWindow
{
public const int WmDwmcompositionchanged = 0x031E;
[StructLayout(LayoutKind.Sequential)]
struct Margins
{
public int cxLeftWidth;
public int cxRightWidth;
public int cyTopHeight;
public int cyBottomHeight;
}
[DllImport("dwmapi.dll")]
static extern int DwmExtendFrameIntoClientArea(IntPtr hWnd, ref Margins pMarInset);
[DllImport("dwmapi.dll")]
extern static int DwmIsCompositionEnabled(ref int en);
private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
{
if (msg != WmDwmcompositionchanged) return IntPtr.Zero;
ExtendGlass(this, new Thickness(0,0,120,0));
handled = true;
return IntPtr.Zero;
}
public static void ExtendGlass(Window window, Thickness thikness)
{
try
{
var isGlassEnabled = 0;
DwmIsCompositionEnabled(ref isGlassEnabled);
if (Environment.OSVersion.Version.Major > 5 && isGlassEnabled > 0)
{
var helper = new WindowInteropHelper(window);
var mainWindowSrc = HwndSource.
FromHwnd(helper.Handle);
if (mainWindowSrc != null)
if (mainWindowSrc.CompositionTarget != null)
mainWindowSrc.CompositionTarget.BackgroundColor =
Colors.Transparent;
var margins = new Margins
{
cxLeftWidth = (int) (thikness.Left),
cxRightWidth = (int) (thikness.Right),
cyBottomHeight = (int) (thikness.Bottom),
cyTopHeight = (int) (thikness.Top)
};
window.Background = Brushes.Transparent;
if (mainWindowSrc != null)
{
DwmExtendFrameIntoClientArea(mainWindowSrc.Handle,
ref margins);
}
}
else
{
window.Background = SystemColors.WindowBrush;
}
}
catch (DllNotFoundException)
{
}
}
protected override void OnSourceInitialized(EventArgs e)
{
base.OnSourceInitialized(e);
ExtendGlass(this, new Thickness(50,0,0,0));
}
}
}
Preview:
http://i.imgur.com/dGmhdRp.png
Any help would be awesome, thanks.