Exemplo n.º 1
0
        void InitBorders()
        {
            _left = new BorderWindow(this)
            {
                Side = BorderSide.Left
            };
            _top = new BorderWindow(this)
            {
                Side = BorderSide.Top
            };
            _right = new BorderWindow(this)
            {
                Side = BorderSide.Right
            };
            _bottom = new BorderWindow(this)
            {
                Side = BorderSide.Bottom
            };

            SetRegion(hWndContent, 0, 0, true);

            var hSrc = HwndSource.FromHwnd(hWndContent);

            hSrc.AddHook(WndProc);


            //Calculate the effective DPI used by WPF;
            _wpfDPI = 96.0 * hSrc.CompositionTarget.TransformToDevice.M11;
            //Get the Current DPI of the monitor of the window.
            _monitorDPI = Shcore.GetDpiForWindow(hSrc.Handle);
            //Calculate the scale factor used to modify window size, graphics and text
            _dpiScaleFactor       = _monitorDPI / _wpfDPI;
            ContentWindow.Width  *= _dpiScaleFactor;
            ContentWindow.Height *= _dpiScaleFactor;
            RescaleForDpi();

            // SWP_DRAWFRAME makes window bg really transparent (visible during resize) and not black
            User32.SetWindowPos(hWndContent, IntPtr.Zero, 0, 0, 0, 0,
                                SetWindowPosOptions.SWP_NOOWNERZORDER |
                                SetWindowPosOptions.SWP_DRAWFRAME |
                                SetWindowPosOptions.SWP_NOACTIVATE |
                                SetWindowPosOptions.SWP_NOZORDER |
                                SetWindowPosOptions.SWP_NOMOVE |
                                SetWindowPosOptions.SWP_NOSIZE);
        }
Exemplo n.º 2
0
        private static void HookupDpiMessage(Window win, IntPtr hwnd)
        {
            var hSrc = HwndSource.FromHwnd(hwnd);

            hSrc.AddHook(WndProc);

            //Calculate the effective DPI used by WPF;
            var wpfDPI = 96.0 * hSrc.CompositionTarget.TransformToDevice.M11;
            //Get the Current DPI of the monitor of the window.
            var monitorDPI = Shcore.GetDpiForWindow(hSrc.Handle);

            SetWindowDpi(win, monitorDPI);
            //Calculate the scale factor used to modify window size, graphics and text
            var dpiScaleFactor = monitorDPI / wpfDPI;

            SetWindowDpiScale(win, dpiScaleFactor);
            win.Width  *= dpiScaleFactor;
            win.Height *= dpiScaleFactor;
            RescaleForDpi(win);
        }