5 out of 5 rated this helpful - Rate this topic

DwmExtendFrameIntoClientArea function

Applies to: desktop apps only

Extends the window frame into the client area.

Syntax

HRESULT WINAPI DwmExtendFrameIntoClientArea(
  HWND hWnd,
  __in  const MARGINS *pMarInset
);

Parameters

hWnd

The handle to the window in which the frame will be extended into the client area.

pMarInset [in]

A pointer to a MARGINS structure that describes the margins to use when extending the frame into the client area.

Return value

If this function succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.

Remarks

This function must be called whenever Desktop Window Manager (DWM) composition is toggled. Handle the WM_DWMCOMPOSITIONCHANGED message for composition change notification.

Use negative margin values to create the "sheet of glass" effect where the client area is rendered as a solid surface with no window border.

Examples

The following sample demonstrates how to extend the bottom margin, creating a large bottom frame.



HRESULT ExtendIntoClientBottom(HWND hwnd)
{
   // Set margins, extending the bottom margin
   MARGINS margins = {0,0,0,25};
   HRESULT hr = S_OK;

   // Extend frame on the bottom of client area
   hr = DwmExtendFrameIntoClientArea(hwnd,&margins);
   if (SUCCEEDED(hr))
   {
      // ...
   }
   return hr;
}

The following sample demonstrates the "sheet of glass" effect where the client area is rendered without a window border.



HRESULT ExtendIntoClientAll(HWND hwnd)
{
   // Negative margins have special meaning to DwmExtendFrameIntoClientArea.
   // Negative margins create the "sheet of glass" effect, where the client area
   // is rendered as a solid surface with no window border.
   MARGINS margins = {-1};
   HRESULT hr = S_OK;

   // Extend the frame across the entire window.
   hr = DwmExtendFrameIntoClientArea(hwnd,&margins);
   if (SUCCEEDED(hr))
   {
      // ...
   }
   return hr;
}

Requirements

Minimum supported client

Windows Vista

Minimum supported server

Windows Server 2008

Header

Dwmapi.h

Library

Dwmapi.lib

DLL

Dwmapi.dll

See also

DWM Blur Behind Overview

 

 

Send comments about this topic to Microsoft

Build date: 2/14/2012

Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
Tips. Vb.net
You can use "System.Drawing.Rectangle" if you lazy to create a new native structure Example : 'Api Calling <DllImport("dwmapi.dll", EntryPoint:="DwmExtendFrameIntoClientArea", SetLastError:=True)> Public Shared Function DwmExtendFrameIntoClientArea(ByVal hw nd As IntPtr, ByRef pMarInset As System.Drawing.Rectangle) As <MarshalAs(UnmanagedType.Error)> Int32 End Function Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load Me.BackColor = Color.Black NativeMethods.DwmExtendFrameIntoClientArea(Me.Handle, New Rectangle(-1, -1, -1, -1)) End Sub
Note about filling the entire client area

Note that if you want to extend the glass to fill the entire client area, you MUST specify -1 for ALL properties, not just the first; otherwise, DwmDefWindowProc will not function correctly.  When 0 is specified as the top value for DwmExtendFrameIntoClientArea and a custom frame is used, DwmDefWindowProc will not recognize the caption buttons, and DefWindowProc will default to Windows NT-style caption buttons, creating various interface problems.  This indicates that various portions of the DWM API test only single property of the inset margin for negative values, rather than all four, as documented.  As such, the sign of all properties should be consistent.  If one property is negative, all four MUST be negative, or different functions will handle the frame/client boundary differently.  Note that the code in the examples should be changed accordingly, as well as the notice stating that only one value must be negative.  Please see http://www.earth2me.com/development/dwm/ or more information.

Incorrect:

MARGINS mgMarInset = { -1 }; // Will not work: translates to { -1, 0, 0, 0 }
DwmExtendFrameIntoClientArea(hWnd, &mgMarInset);

Correct:

MARGINS mgMarInset = { -1, -1, -1, -1 }; // Correct
DwmExtendFrameIntoClientArea(hWnd, &mgMarInset);

C# syntax
[DllImport("dwmapi.dll")]
public static extern int DwmExtendFrameIntoClientArea(IntPtr hWnd, ref Margin pMarInset);
vb.net syntax
<DllImport("dwmapi.dll")> _
Public Shared Function DwmExtendFrameIntoClientArea(ByVal hWnd As IntPtr, ByRef pMarInset As Margin) As Integer
End Function