--- title: "Extend Glass Frame Into a WPF app" titleSuffix: "" description: Learn about how to Extend Glass Frame into a WPF app. ms.date: "03/30/2017" ms.custom: devdivchpfy22 dev_langs: - "csharp" - "vb" helpviewer_keywords: - "applications [WPF], extending glass frames into" - "graphics [WPF], extending glass frames into applications" - "extending glass frames into applications [WPF]" - "glass frames [WPF], extending into applications" ms.assetid: 74388a3a-4b69-4a9d-ba1f-e107636bd660 --- # Extend Glass Frame Into a WPF Application This topic demonstrates how to extend the Windows Vista glass frame into the client area of a Windows Presentation Foundation (WPF) application. > [!NOTE] > This example will only work on a Windows Vista machine running the Desktop Window Manager (DWM) with glass enabled. Windows Vista Home Basic edition does not support the transparent glass effect. Areas that would typically render with the transparent glass effect on other editions of Windows Vista are rendered opaque. ## Extended Glass Frame in an address bar The following image illustrates the glass frame extended into the address bar of Internet Explorer 7: ![Screenshot showing glass frame extended behind IE7 address bar.](./media/extend-glass-frame-into-a-wpf-application/internet-explorer-glass-frame-extended-address-bar.png) To extend the glass frame on a WPF application, access to unmanaged API is needed. The following code example does a Platform Invoke (pinvoke) for the two API needed to extend the frame into the client area. Each of these API are declared in a class called **NonClientRegionAPI**. ```csharp [StructLayout(LayoutKind.Sequential)] public struct MARGINS { public int cxLeftWidth; // width of left border that retains its size public int cxRightWidth; // width of right border that retains its size public int cyTopHeight; // height of top border that retains its size public int cyBottomHeight; // height of bottom border that retains its size }; [DllImport("DwmApi.dll")] public static extern int DwmExtendFrameIntoClientArea( IntPtr hwnd, ref MARGINS pMarInset); ``` ```vb Public Structure MARGINS Public cxLeftWidth As Integer ' width of left border that retains its size Public cxRightWidth As Integer ' width of right border that retains its size Public cyTopHeight As Integer ' height of top border that retains its size Public cyBottomHeight As Integer ' height of bottom border that retains its size End Structure Public Shared Function DwmExtendFrameIntoClientArea(ByVal hwnd As IntPtr, ByRef pMarInset As MARGINS) As Integer End Function ``` [DwmExtendFrameIntoClientArea](/windows/desktop/api/dwmapi/nf-dwmapi-dwmextendframeintoclientarea) is the DWM function that extends the frame into the client area. It takes two parameters; a window handle and a [MARGINS](/windows/win32/api/uxtheme/ns-uxtheme-margins) structure. [MARGINS](/windows/win32/api/uxtheme/ns-uxtheme-margins) is used to tell the DWM how much extra the frame should be extended into the client area. ## Extended Glass Frame on the Loaded event To use the [DwmExtendFrameIntoClientArea](/windows/desktop/api/dwmapi/nf-dwmapi-dwmextendframeintoclientarea) function, a window handle must be obtained. In WPF, the window handle can be obtained from the property of an . In the following example, the frame is extended into the client area on the event of the window. ```csharp void OnLoaded(object sender, RoutedEventArgs e) { try { // Obtain the window handle for WPF application IntPtr mainWindowPtr = new WindowInteropHelper(this).Handle; HwndSource mainWindowSrc = HwndSource.FromHwnd(mainWindowPtr); mainWindowSrc.CompositionTarget.BackgroundColor = Color.FromArgb(0, 0, 0, 0); // Get System Dpi System.Drawing.Graphics desktop = System.Drawing.Graphics.FromHwnd(mainWindowPtr); float DesktopDpiX = desktop.DpiX; float DesktopDpiY = desktop.DpiY; // Set Margins NonClientRegionAPI.MARGINS margins = new NonClientRegionAPI.MARGINS(); // Extend glass frame into client area // Note that the default desktop Dpi is 96dpi. The margins are // adjusted for the system Dpi. margins.cxLeftWidth = Convert.ToInt32(5 * (DesktopDpiX / 96)); margins.cxRightWidth = Convert.ToInt32(5 * (DesktopDpiX / 96)); margins.cyTopHeight = Convert.ToInt32(((int)topBar.ActualHeight + 5) * (DesktopDpiX / 96)); margins.cyBottomHeight = Convert.ToInt32(5 * (DesktopDpiX / 96)); int hr = NonClientRegionAPI.DwmExtendFrameIntoClientArea(mainWindowSrc.Handle, ref margins); // if (hr < 0) { //DwmExtendFrameIntoClientArea Failed } } // If not Vista, paint background white. catch (DllNotFoundException) { Application.Current.MainWindow.Background = Brushes.White; } } ``` ## Extended Glass Frame in client area The following example shows a simple window in which the frame is extended into the client area. The frame is extended behind the top border that contains the two objects. ```xaml Path Search ``` The following image illustrates the glass frame extended into a WPF application: ![Screenshot showing a glass frame extended into a WPF application.](./media/extend-glass-frame-into-a-wpf-application/glass-frame-extended-wpf-application.png) ## See also - [Desktop Window Manager Overview](/windows/desktop/dwm/dwm-overview) - [Desktop Window Manager Blur Overview](/windows/desktop/dwm/blur-ovw) - [DwmExtendFrameIntoClientArea](/windows/desktop/api/dwmapi/nf-dwmapi-dwmextendframeintoclientarea)