Esempio n. 1
0
        /// <summary>
        /// FrameThickness
        /// Extends the Frame(Non Client Area) of the Window/Form into client area
        /// </summary>
        /// <param name="left">Left margin to which extent the frame needs to be extended from left side</param>
        /// <param name="right">Right margin to which extent the frame needs to be extended from right side</param>
        /// <param name="top">Top margin to which extent the frame needs to be extended from top side</param>
        /// <param name="bottom">Bottom margin to which extent the frame needs to be extended from bottom side</param>
        /// <param name="windowHandle">Handle to client window/form</param>
        /// <returns>0 for Success</returns>
        internal static int FrameThickness(int left, int right, int top, int bottom, IntPtr windowHandle)
        {
            // We only enable to set FrameThickness if DWM Composition is enabled.
            if (!UnsafeNativeMethods.DwmIsCompositionEnabled())
                return -1;

            // Create a margin structure
            SafeNativeMethods.MARGINS margins = new SafeNativeMethods.MARGINS();
            margins.cxLeftWidth = left;
            margins.cxRightWidth = right;
            margins.cyTopHeight = top;
            margins.cyBottomHeight = bottom;

            // Extend the Frame into client area
            return UnsafeNativeMethods.DwmExtendFrameIntoClientArea(windowHandle, ref margins); 
        }
Esempio n. 2
0
 internal static extern int DwmExtendFrameIntoClientArea(
     IntPtr hwnd,
     ref SafeNativeMethods.MARGINS m);
Esempio n. 3
0
        void ActivateGlass()
        {
            PresentationSource p = PresentationSource.FromVisual(this);
            HwndSource s_hwndSource = p as HwndSource;

            if (s_hwndSource != null)
            {
                s_hwndSource.CompositionTarget.BackgroundColor = Color.FromArgb(0, 0, 0, 0);
                handle = s_hwndSource.Handle;
            }


            SafeNativeMethods.RECT r = new SafeNativeMethods.RECT();

            UnsafeNativeMethods.GetClientRect(handle, ref r);

            IntPtr hrgn = UnsafeNativeMethods.CreateRectRgn(0, 0, 1, 1);

            SafeNativeMethods.DWM_BLURBEHIND bb = new SafeNativeMethods.DWM_BLURBEHIND();
            bb.dwFlags = SafeNativeMethods.DwmBlurBehindDwFlags.DWM_BB_ENABLE | SafeNativeMethods.DwmBlurBehindDwFlags.DWM_BB_BLURREGION;
            bb.fEnable = true;
            bb.hRgnBlur = hrgn;

            UnsafeNativeMethods.DwmEnableBlurBehindWindow(handle, ref bb);

            SafeNativeMethods.MARGINS mar = new SafeNativeMethods.MARGINS();

            mar.cyTopHeight = 37;

            UnsafeNativeMethods.DwmExtendFrameIntoClientArea(handle, ref mar);

            //Need to make the Window size dirty.
            this.WindowState = WindowState.Minimized;
            this.WindowState = WindowState.Normal;
        }