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 IntPtr PreviewWindowMessage(IntPtr hWindow, int message, IntPtr wParam, IntPtr lParam, ref bool handled) { switch (message) { case WM_COMPOSITIONCHANGED: this.NotifyCompositionChanged(); return(IntPtr.Zero); case WM_NCCALCSIZE: if (this.firstTimeNonClientCalc) { // Suppress first time, otherwise glass effect will be messed up.. this.firstTimeNonClientCalc = false; return(IntPtr.Zero); } else { if (this.nonClientAreaDrawingEnabled && wParam != IntPtr.Zero) //TRUE { //no nonclient frame handled = true; return(IntPtr.Zero); } else { return(IntPtr.Zero); } } case WM_NCHITTEST: IntPtr Result = IntPtr.Zero; if (this.dwmIsCompositionEnabled) { handled = DwmAPI.DwmDefWindowProc(hWindow, message, wParam, lParam, out Result); } if (handled == false) { 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); } }
private NonClientArea NonClientHitTest(ushort x, ushort y) { Point Coordinate = this.PointFromScreen(new Point(x, y)); HitTestResult HitTest = VisualTreeHelper.HitTest(this, Coordinate); if (HitTest?.VisualHit != null) { NonClientArea Area = NonClientAreaRegion.GetNonClientAreaType(HitTest.VisualHit); return(Area); } else { return(NonClientArea.HTNOWHERE); } }
/// <summary> /// sets the nonclient area type that controls how the window manager reacts on user interaction with the NC area /// </summary> public static void SetNonClientAreaType(DependencyObject d, NonClientArea value) { d.SetValue(NonClientAreaRegion.NonClientAreaTypeProperty, value); }