/// <summary> /// The window proc. /// </summary> /// <param name="hwnd"> /// The hwnd. /// </param> /// <param name="umsg"> /// The umsg. /// </param> /// <param name="wParam"> /// The w param. /// </param> /// <param name="lParam"> /// The l param. /// </param> /// <returns> /// The <see cref="IntPtr"/>. /// </returns> private IntPtr WindowProc(IntPtr hwnd, uint umsg, IntPtr wParam, IntPtr lParam) { var msg = (WM)umsg; switch (msg) { case WM.ACTIVATE: { if (_hostConfig.HostPlacement.Frameless) { var frameSizeY = User32Methods.GetSystemMetrics(SystemMetrics.SM_CYFRAME); var frameSizeX = User32Methods.GetSystemMetrics(SystemMetrics.SM_CXFRAME); var frameMargins = new Margins(frameSizeX, frameSizeX, frameSizeY, frameSizeY); DwmApiMethods.DwmExtendFrameIntoClientArea(Handle, ref frameMargins); User32Methods.SetWindowPos(hwnd, IntPtr.Zero, 0, 0, 0, 0, WindowPositionFlags.SWP_NOZORDER | WindowPositionFlags.SWP_NOOWNERZORDER | WindowPositionFlags.SWP_NOMOVE | WindowPositionFlags.SWP_NOSIZE | WindowPositionFlags.SWP_FRAMECHANGED); } break; } case WM.CREATE: { Handle = hwnd; var size = GetClientSize(); OnCreate(hwnd, size.Width, size.Height); break; } case WM.ERASEBKGND: return(new IntPtr(1)); case WM.SIZE: { var size = GetClientSize(); OnSize(size.Width, size.Height); break; } case WM.CLOSE: { OnExit(); Exit(); Environment.Exit(0); break; } case WM.NCHITTEST: if (_hostConfig.HostPlacement.Frameless) { return((IntPtr)NativeMethods.HT_CAPTION); } break; } return(User32Methods.DefWindowProc(hwnd, umsg, wParam, lParam)); }
public virtual void ApplyDwmConfig() { var window = this.m_window; var policy = (int)DwmNCRenderingPolicy.DWMNCRP_ENABLED; DwmApiHelpers.DwmSetWindowAttribute(window.Handle, DwmWindowAttributeType.DWMWA_NCRENDERING_POLICY, ref policy); var dwmMargins = this.GetDwmMargins(); DwmApiMethods.DwmExtendFrameIntoClientArea(window.Handle, ref dwmMargins); if (this.BlurBehindEnabled) { User32ExperimentalHelpers.EnableBlurBehind(window.Handle); } }
/// <summary> /// The window proc. /// </summary> /// <param name="hwnd"> /// The hwnd. /// </param> /// <param name="umsg"> /// The umsg. /// </param> /// <param name="wParam"> /// The w param. /// </param> /// <param name="lParam"> /// The l param. /// </param> /// <returns> /// The <see cref="IntPtr"/>. /// </returns> private IntPtr WindowProc(IntPtr hwnd, uint umsg, IntPtr wParam, IntPtr lParam) { var msg = (WM)umsg; switch (msg) { case WM.ACTIVATE: { if (mHostConfig.HostFrameless) { Margins frameMargins = new Margins(7, 7, 27, 7); DwmApiMethods.DwmExtendFrameIntoClientArea(Handle, ref frameMargins); User32Methods.SetWindowPos(hwnd, IntPtr.Zero, 0, 0, 0, 0, WindowPositionFlags.SWP_NOZORDER | WindowPositionFlags.SWP_NOOWNERZORDER | WindowPositionFlags.SWP_NOMOVE | WindowPositionFlags.SWP_NOSIZE | WindowPositionFlags.SWP_FRAMECHANGED); } break; } case WM.CREATE: { Handle = hwnd; var size = GetClientSize(); OnCreate(hwnd, size.Width, size.Height); break; } case WM.ERASEBKGND: return(new IntPtr(1)); case WM.SIZE: { var size = GetClientSize(); OnSize(size.Width, size.Height); break; } case WM.CLOSE: { OnExit(); Exit(); Environment.Exit(0); break; } case WM.NCCALCSIZE: { if (mHostConfig.HostFrameless) { return(IntPtr.Zero); } break; } case WM.NCHITTEST: { if (mHostConfig.HostFrameless) { // This might be a bit redundant to perform and should find another way // to pass the return value rather than performing a hit test again. var lRet = HitTestNCA(hwnd, wParam, lParam); return(lRet); } break; } } return(User32Methods.DefWindowProc(hwnd, umsg, wParam, lParam)); }