private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled) { if (msg == (int)WM.NCHITTEST && this.canResize) { var ptScreen = lParam.ToPoint(); var ptClient = this.PointFromScreen(ptScreen); var rectTarget = new Rect(0, 0, this.ActualWidth, this.ActualHeight); if (rectTarget.Contains(ptClient)) { handled = true; return (IntPtr)HitTestValues.HTBOTTOMRIGHT; } } return IntPtr.Zero; }
private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled) { if (msg == (int)WM.MOUSEACTIVATE) { handled = true; return new IntPtr(3); } if (msg == (int)WM.LBUTTONDOWN) { var ptScreen = lParam.ToPoint(); User32.PostMessage( this.ownerHandle, (uint)WM.NCLBUTTONDOWN, (IntPtr)this.processor.GetHitTestValue(ptScreen, this.ActualWidth, this.ActualHeight), IntPtr.Zero); } if (msg == (int)WM.NCHITTEST) { var ptScreen = lParam.ToPoint(); var ptClient = this.PointFromScreen(ptScreen); this.Cursor = this.processor.GetCursor(ptClient, this.ActualWidth, this.ActualHeight); } return IntPtr.Zero; }
private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled) { if (msg == (int)WM.MOUSEACTIVATE) { handled = true; return new IntPtr(3); } if (msg == (int)WM.LBUTTONDOWN) { if (!this.owner.IsActive) { this.owner.Activate(); } var ptScreen = lParam.ToPoint(); NativeMethods.PostMessage( this.ownerHandle, (uint)WM.NCLBUTTONDOWN, (IntPtr)this.processor.GetHitTestValue(ptScreen, this.ActualWidth, this.ActualHeight), IntPtr.Zero); } if (msg == (int)WM.NCHITTEST) { var ptScreen = lParam.ToPoint(); var ptClient = this.PointFromScreen(ptScreen); this.Cursor = this.processor.GetCursor(ptClient, this.ActualWidth, this.ActualHeight); } if (msg == (int)WM.LBUTTONDBLCLK) { if (this.processor.GetType() == typeof(GlowWindowProcessorTop)) { NativeMethods.SendMessage(this.ownerHandle, WM.NCLBUTTONDBLCLK, (IntPtr)HitTestValues.HTTOP, IntPtr.Zero); } else if (this.processor.GetType() == typeof(GlowWindowProcessorBottom)) { NativeMethods.SendMessage(this.ownerHandle, WM.NCLBUTTONDBLCLK, (IntPtr)HitTestValues.HTBOTTOM, IntPtr.Zero); } } return IntPtr.Zero; }
IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled) { IntPtr retVal = IntPtr.Zero; if (!handled) { var wmsg = (WindowMessage)msg; //Debug.WriteLine(wmsg); switch (wmsg) { //case WindowMessage.WM_SETTEXT: //case WindowMessage.WM_SETICON: // var changed = User32Ex.ModifyStyle(hwnd, WindowStyles.WS_VISIBLE, WindowStyles.WS_OVERLAPPED); // retVal = User32.DefWindowProc(hwnd, (uint)msg, wParam, lParam); // if (changed) { User32Ex.ModifyStyle(hwnd, WindowStyles.WS_OVERLAPPED, WindowStyles.WS_VISIBLE); } // handled = true; // break; case WindowMessage.WM_NCUAHDRAWCAPTION: case WindowMessage.WM_NCUAHDRAWFRAME: // undocumented stuff for lame non-dwm themes that will sometimes draw old control buttons handled = true; break; case WindowMessage.WM_NCHITTEST: retVal = new IntPtr((int)HandleNcHitTest(lParam.ToPoint())); handled = true; break; case WindowMessage.WM_NCRBUTTONDOWN: case WindowMessage.WM_NCMBUTTONDOWN: case WindowMessage.WM_NCRBUTTONDBLCLK: case WindowMessage.WM_NCMBUTTONDBLCLK: case WindowMessage.WM_RBUTTONDBLCLK: case WindowMessage.WM_MBUTTONDBLCLK: case WindowMessage.WM_LBUTTONDBLCLK: handled = true; if (_contentWindow != null) _contentWindow.Activate(); break; case WindowMessage.WM_NCLBUTTONDOWN: case WindowMessage.WM_NCLBUTTONDBLCLK: Debug.WriteLine("Got border LButton down"); handled = true; // pass resizer msg to the content window instead if (_contentWindow != null) { _contentWindow.Activate(); var cwHwnd = new WindowInteropHelper(_contentWindow).Handle; User32.SendMessage(cwHwnd, (uint)msg, wParam, IntPtr.Zero); } break; case WindowMessage.WM_MOUSEACTIVATE: var lowword = 0xffff & lParam.ToInt32(); var hchit = (NcHitTest)lowword; // in case of non-resizable window eat this msg if (hchit == NcHitTest.HTCLIENT) { retVal = new IntPtr((int)MouseActivate.MA_NOACTIVATEANDEAT); } else { retVal = new IntPtr((int)MouseActivate.MA_NOACTIVATE); } handled = true; break; case WindowMessage.WM_ERASEBKGND: // prevent more flickers handled = true; break; case WindowMessage.WM_GETMINMAXINFO: HandleMinMaxInfo(lParam); break; } } return retVal; }
private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled) { if (msg == (int)WM.NCHITTEST) { if (this.ResizeMode == ResizeMode.CanResizeWithGrip && this.WindowState == WindowState.Normal && this.resizeGrip != null) { var ptScreen = lParam.ToPoint(); var ptClient = this.resizeGrip.PointFromScreen(ptScreen); var rectTarget = new Rect(0, 0, this.resizeGrip.ActualWidth, this.resizeGrip.ActualHeight); if (rectTarget.Contains(ptClient)) { handled = true; return (IntPtr)HitTestValues.HTBOTTOMRIGHT; } } } else if (msg == (int)WM.DPICHANGED) { var dpiX = wParam.ToLoWord(); var dpiY = wParam.ToHiWord(); this.ChangeDpi(new Dpi(dpiX, dpiY)); handled = true; } return IntPtr.Zero; }
IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled) { IntPtr retVal = IntPtr.Zero; if (!handled) { var wmsg = (WindowMessage)msg; //Debug.WriteLine(wmsg); switch (wmsg) { case WindowMessage.WM_NCCALCSIZE: handled = true; break; case WindowMessage.WM_NCHITTEST: NcHitTest res = NcHitTest.HTBORDER; if (_manager.ContentWindow.ResizeMode == ResizeMode.CanResizeWithGrip || _manager.ContentWindow.ResizeMode == ResizeMode.CanResize) { var pt = PointFromScreen(lParam.ToPoint()); int diagSize = (int)(2 * PadSize); switch (Side) { case BorderSide.Left: if (pt.Y <= diagSize) { res = NcHitTest.HTTOPLEFT; } else if (pt.Y >= Height - diagSize) { res = NcHitTest.HTBOTTOMLEFT; } else { res = NcHitTest.HTLEFT; } break; case BorderSide.Top: if (pt.X <= diagSize) { res = NcHitTest.HTTOPLEFT; } else if (pt.X >= Width - diagSize) { res = NcHitTest.HTTOPRIGHT; } else { res = NcHitTest.HTTOP; } break; case BorderSide.Right: if (pt.Y <= diagSize) { res = NcHitTest.HTTOPRIGHT; } else if (pt.Y >= Height - diagSize) { res = NcHitTest.HTBOTTOMRIGHT; } else { res = NcHitTest.HTRIGHT; } break; case BorderSide.Bottom: if (pt.X <= diagSize) { res = NcHitTest.HTBOTTOMLEFT; } else if (pt.X >= Width - diagSize) { res = NcHitTest.HTBOTTOMRIGHT; } else { res = NcHitTest.HTBOTTOM; } break; } } retVal = new IntPtr((int)res); handled = true; break; case WindowMessage.WM_NCRBUTTONDOWN: case WindowMessage.WM_NCMBUTTONDOWN: case WindowMessage.WM_NCRBUTTONDBLCLK: case WindowMessage.WM_NCMBUTTONDBLCLK: case WindowMessage.WM_RBUTTONDBLCLK: case WindowMessage.WM_MBUTTONDBLCLK: case WindowMessage.WM_LBUTTONDBLCLK: handled = true; User32.SetForegroundWindow(_manager.hWndContent); break; case WindowMessage.WM_NCLBUTTONDOWN: case WindowMessage.WM_NCLBUTTONDBLCLK: handled = true; // pass resizer msg to the content window instead User32.SetForegroundWindow(_manager.hWndContent); User32.SendMessage(_manager.hWndContent, (uint)msg, wParam, lParam); break; case WindowMessage.WM_MOUSEACTIVATE: var lowword = 0xffff & lParam.ToInt32(); var hchit = (NcHitTest)lowword; // in case of non-resizable window eat this msg if (hchit == NcHitTest.HTCLIENT) { retVal = new IntPtr((int)MouseActivate.MA_NOACTIVATEANDEAT); } else { retVal = new IntPtr((int)MouseActivate.MA_NOACTIVATE); } handled = true; break; case WindowMessage.WM_GETMINMAXINFO: // overridden so max size = normal max + resize border (for when content window is max size without maximizing) var thick = 2 * (int)PadSize; MINMAXINFO para = (MINMAXINFO)Marshal.PtrToStructure(lParam, typeof(MINMAXINFO)); var orig = para.ptMaxTrackSize; orig.x += thick; orig.y += thick; para.ptMaxTrackSize = orig; Marshal.StructureToPtr(para, lParam, true); break; } } return retVal; }
private NcHitTest HandleNcHitTest(IntPtr hWnd, IntPtr lParam) { Point screenPoint = lParam.ToPoint(); Point windowPoint = ContentWindow.PointFromScreen(screenPoint); var capH = (double)WindowCaptionHeightConverter.Instance.Convert(Chrome.GetCaptionHeight(ContentWindow), typeof(Double), null, CultureInfo.CurrentCulture); //double capH = (windowCapH > -1 ? windowCapH : ContentWindow.ActualHeight); NcHitTest location = NcHitTest.HTCLIENT; var hitTest = ContentWindow.InputHitTest(windowPoint); if (hitTest != null && (windowPoint.Y <= capH || Chrome.GetIsCaption(hitTest)) && !Chrome.GetIsHitTestVisible(hitTest)) { location = NcHitTest.HTCAPTION; if (windowPoint.Y <= 40) { // check for sysmenu style if (((WindowStyles)User32.GetWindowLong(hWndContent, CommonWin32.WindowClasses.WindowLong.GWL_STYLE)).HasFlag(WindowStyles.WS_SYSMENU)) { if (ContentWindow.FlowDirection == System.Windows.FlowDirection.LeftToRight) { if (windowPoint.X <= 40) { location = NcHitTest.HTSYSMENU; } } else if (windowPoint.X >= (ContentWindow.ActualWidth - 40)) { location = NcHitTest.HTSYSMENU; } } } } if (_resizeGrip != null && _resizeGrip.Visibility == System.Windows.Visibility.Visible && VisualTreeHelper.HitTest(_resizeGrip, _resizeGrip.PointFromScreen(screenPoint)) != null) { location = _resizeGrip.FlowDirection == System.Windows.FlowDirection.LeftToRight ? NcHitTest.HTBOTTOMRIGHT : NcHitTest.HTBOTTOMLEFT; } //Debug.WriteLine(location); return location; }
private NcHitTest HandleNcHitTest(IntPtr lParam) { Point windowPoint = ContentWindow.PointFromScreen(lParam.ToPoint()); var capH = SystemParameters.CaptionHeight;// (double)WindowCaptionHeightConverter.Instance.Convert(GetCaptionHeight(_contentWindow), typeof(Double), null, CultureInfo.CurrentCulture); //double capH = (windowCapH > -1 ? windowCapH : _contentWindow.ActualHeight); NcHitTest location = NcHitTest.HTCLIENT; var hitTest = ContentWindow.InputHitTest(windowPoint); if (hitTest != null && (windowPoint.Y <= capH))// || GetIsCaption(hitTest)) && !GetIsHitTestVisible(hitTest)) { location = NcHitTest.HTCAPTION; if (windowPoint.Y <= 40) { if (ContentWindow.FlowDirection == System.Windows.FlowDirection.LeftToRight) { if (windowPoint.X <= 40) { location = NcHitTest.HTSYSMENU; } } else if (windowPoint.X >= (ContentWindow.ActualWidth - 40)) { location = NcHitTest.HTSYSMENU; } } } //if (_resizeGrip != null && _resizeGrip.Visibility == System.Windows.Visibility.Visible && // VisualTreeHelper.HitTest(_resizeGrip, _resizeGrip.PointFromScreen(screenPoint)) != null) //{ // location = _resizeGrip.FlowDirection == System.Windows.FlowDirection.LeftToRight ? // NcHitTest.HTBOTTOMRIGHT : NcHitTest.HTBOTTOMLEFT; //} //Debug.WriteLine(location); return location; }
/// <summary> /// Handles Win32 window messages for this window. /// </summary> /// <param name="hwnd">The window handle.</param> /// <param name="msg">The message ID.</param> /// <param name="wParam">The message's wParam value.</param> /// <param name="lParam">The message's lParam value.</param> /// <param name="handled">A value that indicates whether the message was handled. Set the value to /// true if the message was handled; otherwise, false.</param> /// <returns></returns> IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled) { IntPtr retVal = IntPtr.Zero; if (!handled) { var wmsg = (WindowMessage)msg; //Debug.WriteLine(wmsg); switch (wmsg) { case WindowMessage.WM_MOUSEHWHEEL: // do our own horizontal wheel event var element = Mouse.DirectlyOver; if (element != null) { var delta = wParam.ToInt32() >> 16; var arg = new MouseWheelEventArgs(InputManager.Current.PrimaryMouseDevice, Environment.TickCount, delta) { RoutedEvent = MouseEvents.PreviewMouseHWheelEvent }; element.RaiseEvent(arg); if (!arg.Handled) { arg.RoutedEvent = MouseEvents.MouseHWheelEvent; arg.Handled = false; element.RaiseEvent(arg); handled = arg.Handled; } } break; //case WindowMessage.WM_SETTEXT: //case WindowMessage.WM_SETICON: // var changed = User32Ex.ModifyStyle(hwnd, WindowStyles.WS_VISIBLE, WindowStyles.WS_OVERLAPPED); // retVal = User32.DefWindowProc(hwnd, (uint)msg, wParam, lParam); // if (changed) { User32Ex.ModifyStyle(hwnd, WindowStyles.WS_OVERLAPPED, WindowStyles.WS_VISIBLE); } // handled = true; // break; case WindowMessage.WM_NCUAHDRAWCAPTION: case WindowMessage.WM_NCUAHDRAWFRAME: // undocumented stuff for non-dwm themes that will sometimes draw old control buttons handled = true; break; case WindowMessage.WM_NCCALCSIZE: //remove non-client borders completely HandleNcCalcSize(hwnd, wParam, lParam); handled = true; break; case WindowMessage.WM_NCPAINT: // prevent non-dwm flicker handled = !Dwmapi.IsCompositionEnabled; break; case WindowMessage.WM_NCACTIVATE: // handled to prevent default non-client border from showing in classic mode // wParam False means draw inactive title bar (which we do nothing). retVal = HandleNcActivate(hwnd, msg, wParam, retVal); handled = true; break; case WindowMessage.WM_NCHITTEST: retVal = new IntPtr((int)HandleNcHitTest(lParam.ToPoint())); handled = true; break; case WindowMessage.WM_NCRBUTTONDOWN: switch ((NcHitTest)wParam.ToInt32()) { case NcHitTest.HTCAPTION: case NcHitTest.HTSYSMENU: // display sys menu User32.PostMessage(hwnd, (uint)WindowMessage.WM_POPUPSYSTEMMENU, IntPtr.Zero, lParam); handled = true; break; } break; case WindowMessage.WM_WINDOWPOSCHANGED: HandleWindowPosChanged(hwnd, lParam); break; case WindowMessage.WM_DWMCOMPOSITIONCHANGED: SetRegion(hwnd, 0, 0, true); break; case WindowMessage.WM_ERASEBKGND: // prevent more flickers? handled = true; break; } } return retVal; }