Example #1
0
        public IntPtr PreviewWindowMessage(IntPtr hWindow, int message, IntPtr wParam, IntPtr lParam, ref bool handled)
        {
            switch (message)
            {
            case DwmWindowHelper.WmCompositionchanged:
                this.NotifyCompositionChanged();
                return(IntPtr.Zero);

            case DwmWindowHelper.WmNccalcsize:
                if (this.DwmIsCompositionEnabled)
                {
                    if (this.nonClientAreaDrawingEnabled &&
                        wParam != IntPtr.Zero /*TRUE*/)
                    {
                        //no nonclient frame
                        handled = true;
                        return(IntPtr.Zero);
                    }
                    else
                    {
                        return(IntPtr.Zero);
                    }
                }
                else
                {
                    // Support client drawing only when Dwm is enabled. Otherwise non client drawing is too complicated ;-)
                    return(IntPtr.Zero);
                }

            case DwmWindowHelper.WmNchittest:
                // Hit test non client area
                IntPtr Result = IntPtr.Zero;
                if (this.DwmIsCompositionEnabled)
                {
                    // if Dwm is enabled,first let DWM hit test for window buttons
                    handled = DwmApi.DwmDefWindowProc(hWindow, message, wParam, lParam, out Result);
                }
                if (handled == false)
                {
                    // hit test for non client areas in the window layout
                    uint Coordinates;
                    checked
                    {
                        Coordinates = (uint)lParam.ToInt32();
                    }

                    NonClientArea NonClientArea = this.nonClientHitTest(Coordinates.GetLoUShort(), Coordinates.GetHiUShort());
                    if (NonClientArea != NonClientArea.HTNOWHERE)
                    {
                        Result  = new IntPtr((int)NonClientArea);
                        handled = true;
                    }
                }
                return(Result);

            default:
                return(IntPtr.Zero);
            }
        }
Example #2
0
 public static bool IsCompositionEnabled()
 {
     try
     {
         return(DwmApi.DwmIsCompositionEnabled());
     }
     catch (DllNotFoundException)
     {
         return(false);
     }
 }
Example #3
0
 internal DwmWindowHelper(IntPtr windowHandle, DwmApi.Margins margins, bool blurClientArea, bool nonClientAreaDrawingEnabled, Action notifyDwmCompositionChanged, Func <ushort, ushort, NonClientArea> nonClientHitTest)
 {
     this.WindowHandle            = windowHandle;
     this.DwmIsCompositionEnabled = DwmApi.IsCompositionEnabled();
     this.margins        = margins;
     this.blurClientArea = blurClientArea;
     this.notifyDwmCompositionChanged = notifyDwmCompositionChanged;
     this.UpdateGlassEffect();
     this.UpdateNonClientArea();
     this.nonClientAreaDrawingEnabled = nonClientAreaDrawingEnabled;
     this.nonClientHitTest            = nonClientHitTest;
     this.UpdateNonClientArea();
 }
Example #4
0
 public static void EnableBlurBehindWindow(IntPtr windowHandle, bool enable)
 {
     try
     {
         if (DwmApi.DwmIsCompositionEnabled())
         {
             BlurBehindInformation BlurBehindInformation = new BlurBehindInformation(enable, IntPtr.Zero);
             DwmApi.DwmEnableBlurBehindWindow(windowHandle, ref BlurBehindInformation);
             return;
         }
         else
         {
             //Glass effect is not enabled -> do nothing
             return;
         }
     }
     catch (DllNotFoundException)
     {
         return;
     }
 }
Example #5
0
        internal static void EnableGlassEffect(IntPtr windowHandle, Margins margins)
        {
            try
            {
                if (DwmApi.DwmIsCompositionEnabled())
                {
                    IntPtr Handle = windowHandle;

                    DwmApi.DwmExtendFrameIntoClientArea(Handle, ref margins);
                    return;
                }
                else
                {
                    //Glass effect is not enabled -> do nothing
                    return;
                }
            }
            catch (DllNotFoundException)
            {
                return;
            }
        }
Example #6
0
 protected void NotifyCompositionChanged()
 {
     this.DwmIsCompositionEnabled = DwmApi.IsCompositionEnabled();
     this.UpdateGlassEffect();
     this.notifyDwmCompositionChanged();
 }
Example #7
0
 private void UpdateGlassEffect()
 {
     DwmApi.EnableGlassEffect(this.WindowHandle, this.margins);
     DwmApi.EnableBlurBehindWindow(this.WindowHandle, this.blurClientArea);
 }
Example #8
0
 private void UpdateNonClientArea()
 {
     DwmApi.SetWindowPos(this.WindowHandle, IntPtr.Zero, 0, 0, 0, 0, 0x27 /*SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED*/);
 }