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); } }
public static bool IsCompositionEnabled() { try { return(DwmApi.DwmIsCompositionEnabled()); } catch (DllNotFoundException) { return(false); } }
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(); }
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; } }
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; } }
protected void NotifyCompositionChanged() { this.DwmIsCompositionEnabled = DwmApi.IsCompositionEnabled(); this.UpdateGlassEffect(); this.notifyDwmCompositionChanged(); }
private void UpdateGlassEffect() { DwmApi.EnableGlassEffect(this.WindowHandle, this.margins); DwmApi.EnableBlurBehindWindow(this.WindowHandle, this.blurClientArea); }
private void UpdateNonClientArea() { DwmApi.SetWindowPos(this.WindowHandle, IntPtr.Zero, 0, 0, 0, 0, 0x27 /*SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED*/); }