/// <devdoc> /// </devdoc> /// <internalonly/> private void SetWindowRgn() { IntPtr rgn1 = IntPtr.Zero; IntPtr rgn2 = IntPtr.Zero; NativeMethods.RECT rect = new NativeMethods.RECT(); CreateParams cp = CreateParams; SafeNativeMethods.AdjustWindowRectEx(ref rect, cp.Style, false, cp.ExStyle); Rectangle bounds = Bounds; rgn1 = SafeNativeMethods.CreateRectRgn(0, 0, bounds.Width, bounds.Height); try { rgn2 = SafeNativeMethods.CreateRectRgn(-rect.left, -rect.top, bounds.Width - rect.right, bounds.Height - rect.bottom); try { if (rgn1 == IntPtr.Zero || rgn2 == IntPtr.Zero) { throw new InvalidOperationException(SR.GetString(SR.ErrorSettingWindowRegion)); } if (SafeNativeMethods.CombineRgn(new HandleRef(null, rgn1), new HandleRef(null, rgn1), new HandleRef(null, rgn2), NativeMethods.RGN_DIFF) == 0) { throw new InvalidOperationException(SR.GetString(SR.ErrorSettingWindowRegion)); } if (UnsafeNativeMethods.SetWindowRgn(new HandleRef(this, Handle), new HandleRef(null, rgn1), true) == 0) { throw new InvalidOperationException(SR.GetString(SR.ErrorSettingWindowRegion)); } else { // The hwnd now owns the region. rgn1 = IntPtr.Zero; } } finally { if (rgn2 != IntPtr.Zero) { SafeNativeMethods.DeleteObject(new HandleRef(null, rgn2)); } } } finally { if (rgn1 != IntPtr.Zero) { SafeNativeMethods.DeleteObject(new HandleRef(null, rgn1)); } } }