Ejemplo n.º 1
0
        protected virtual void LoadWindowState()
        {
            if (_settings == null)
            {
                return;
            }
            _settings.Reload();

            if (_settings.Placement == null)
            {
                return;
            }

            try
            {
                var wp = _settings.Placement;

                wp.length  = Marshal.SizeOf(typeof(WINDOWPLACEMENT));
                wp.flags   = 0;
                wp.showCmd = (wp.showCmd == Constants.SW_SHOWMINIMIZED ? Constants.SW_SHOWNORMAL : wp.showCmd);
                var hwnd = new WindowInteropHelper(_window).Handle;
                NativeMethodsUltimate.SetWindowPlacement(hwnd, wp);
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Failed to load window state:\r\n{0}", ex);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// win10
        /// </summary>
        /// <param name="HWnd"></param>
        /// <param name="hasFrame"></param>
        public static void EnableBlur(IntPtr HWnd, bool hasFrame = true)
        {
            AccentPolicy accent = new AccentPolicy();

            accent.AccentState = AccentState.ACCENT_ENABLE_BLURBEHIND;
            if (hasFrame)
            {
                accent.AccentFlags = 0x20 | 0x40 | 0x80 | 0x100;
            }

            int accentStructSize = Marshal.SizeOf(accent);

            IntPtr accentPtr = Marshal.AllocHGlobal(accentStructSize);

            Marshal.StructureToPtr(accent, accentPtr, false);

            WindowCompositionAttributeData data = new WindowCompositionAttributeData();

            data.Attribute  = WindowCompositionAttribute.WCA_ACCENT_POLICY;
            data.SizeOfData = accentStructSize;
            data.Data       = accentPtr;

            NativeMethodsUltimate.SetWindowCompositionAttribute(HWnd, ref data);

            Marshal.FreeHGlobal(accentPtr);
        }
Ejemplo n.º 3
0
 public void Move(double deviceLeft, double deviceTop)
 {
     if (this.hwndSource == null)
     {
         return;
     }
     NativeMethodsUltimate.SetWindowPos(this.hwndSource.Handle, IntPtr.Zero, (int)deviceLeft, (int)deviceTop, 0, 0, 85);
 }
Ejemplo n.º 4
0
 protected virtual void DestroyWindowClassCore()
 {
     if (this.wndClassAtom != 0)
     {
         IntPtr moduleHandle = NativeMethodsUltimate.GetModuleHandle(null);
         NativeMethodsUltimate.UnregisterClass(new IntPtr((int)this.wndClassAtom), moduleHandle);
         this.wndClassAtom = 0;
     }
 }
Ejemplo n.º 5
0
        public void Show(UIElement parentElement)
        {
            HwndSource hwndSource = PresentationSource.FromVisual((Visual)parentElement) as HwndSource;

            this.EnsureWindow(hwndSource == null ? IntPtr.Zero : hwndSource.Handle);
            Point screen      = parentElement.PointToScreen(new Point(0.0, 0.0));
            Size  deviceUnits = parentElement.RenderSize.LogicalToDeviceUnits();

            NativeMethodsUltimate.SetWindowPos(this.hwndSource.Handle, IntPtr.Zero, (int)screen.X, (int)screen.Y, (int)deviceUnits.Width, (int)deviceUnits.Height, 84);
        }
Ejemplo n.º 6
0
        //Vista之后通用
        public static void EnableAero(IntPtr handle)
        {
            MARGINS mg = new MARGINS();

            mg.cyBottomHeight = -1;
            mg.cxLeftWidth    = -1;
            mg.cxRightWidth   = -1;
            mg.cyTopHeight    = -1;
            NativeMethodsUltimate.DwmExtendFrameIntoClientArea(handle, ref mg);
        }
Ejemplo n.º 7
0
 protected virtual void DestroyWindowCore()
 {
     if (this.handle != IntPtr.Zero)
     {
         if (!NativeMethodsUltimate.DestroyWindow(this.handle))
         {
             HwndWrapper.lastDestroyWindowError = Marshal.GetLastWin32Error();
             HwndWrapper.failedDestroyWindows  += 1L;
         }
         this.handle = IntPtr.Zero;
     }
 }
Ejemplo n.º 8
0
        internal static bool ModifyStyle(IntPtr hWnd, int styleToRemove, int styleToAdd)
        {
            int windowLong = NativeMethodsUltimate.GetWindowLong(hWnd, NativeMethodsUltimate.GWL.STYLE);
            int num        = (windowLong & ~styleToRemove) | styleToAdd;

            if (num == windowLong)
            {
                return(false);
            }
            NativeMethodsUltimate.SetWindowLong(hWnd, NativeMethodsUltimate.GWL.STYLE, num);
            return(true);
        }
Ejemplo n.º 9
0
        protected virtual void SaveWindowState()
        {
            if (_settings == null)
            {
                return;
            }
            WINDOWPLACEMENT wp;
            var             hwnd = new WindowInteropHelper(_window).Handle;

            wp = NativeMethodsUltimate.GetWindowPlacement(hwnd);
            _settings.Placement = wp;
            _settings.Save();
        }
Ejemplo n.º 10
0
        protected ushort RegisterClass(string className)
        {
            WNDCLASS wNDCLASS = default(WNDCLASS);

            wNDCLASS.cbClsExtra    = 0;
            wNDCLASS.cbWndExtra    = 0;
            wNDCLASS.hbrBackground = IntPtr.Zero;
            wNDCLASS.hCursor       = IntPtr.Zero;
            wNDCLASS.hIcon         = IntPtr.Zero;
            wNDCLASS.lpfnWndProc   = (this.wndProc = new NativeMethodsUltimate.WndProc(this.WndProc));
            wNDCLASS.lpszClassName = className;
            wNDCLASS.lpszMenuName  = null;
            wNDCLASS.style         = 0u;
            return(NativeMethodsUltimate.RegisterClass(ref wNDCLASS));
        }
Ejemplo n.º 11
0
        internal static void FindMonitorRectsFromPoint(System.Windows.Point point, out Rect monitorRect, out Rect workAreaRect)
        {
            IntPtr intPtr = NativeMethodsUltimate.MonitorFromPoint(new POINT
            {
                X = (int)point.X,
                Y = (int)point.Y
            }, 2);

            monitorRect  = new Rect(0.0, 0.0, 0.0, 0.0);
            workAreaRect = new Rect(0.0, 0.0, 0.0, 0.0);
            if (intPtr != IntPtr.Zero)
            {
                MONITORINFO mONITORINFO = default(MONITORINFO);
                mONITORINFO.cbSize = (uint)Marshal.SizeOf(typeof(MONITORINFO));
                NativeMethodsUltimate.GetMonitorInfo(intPtr, ref mONITORINFO);
                monitorRect  = new Rect(mONITORINFO.rcMonitor.Position, mONITORINFO.rcMonitor.Size);
                workAreaRect = new Rect(mONITORINFO.rcWork.Position, mONITORINFO.rcWork.Size);
            }
        }
Ejemplo n.º 12
0
        internal static void FindMaximumSingleMonitorRectangle(RECT windowRect, out RECT screenSubRect, out RECT monitorRect)
        {
            List <RECT> rects = new List <RECT>();

            NativeMethodsUltimate.EnumDisplayMonitors(IntPtr.Zero, IntPtr.Zero, delegate(IntPtr hMonitor, IntPtr hdcMonitor, ref RECT rect, IntPtr lpData)
            {
                MONITORINFO mONITORINFO = default(MONITORINFO);
                mONITORINFO.cbSize      = (uint)Marshal.SizeOf(typeof(MONITORINFO));
                NativeMethodsUltimate.GetMonitorInfo(hMonitor, ref mONITORINFO);
                rects.Add(mONITORINFO.rcWork);
                return(true);
            }, IntPtr.Zero);
            long num = 0L;

            screenSubRect = new RECT
            {
                Left   = 0,
                Right  = 0,
                Top    = 0,
                Bottom = 0
            };
            monitorRect = new RECT
            {
                Left   = 0,
                Right  = 0,
                Top    = 0,
                Bottom = 0
            };
            foreach (RECT current in rects)
            {
                RECT rECT = current;
                RECT rECT2;
                NativeMethodsUltimate.IntersectRect(out rECT2, ref rECT, ref windowRect);
                long num2 = (long)(rECT2.Width * rECT2.Height);
                if (num2 > num)
                {
                    screenSubRect = rECT2;
                    monitorRect   = current;
                    num           = num2;
                }
            }
        }
Ejemplo n.º 13
0
        static DpiHelper()
        {
            IntPtr dC = NativeMethodsUltimate.GetDC(IntPtr.Zero);

            if (dC != IntPtr.Zero)
            {
                DpiHelper.DeviceDpiX = (double)NativeMethodsUltimate.GetDeviceCaps(dC, 88);
                DpiHelper.DeviceDpiY = (double)NativeMethodsUltimate.GetDeviceCaps(dC, 90);
                NativeMethodsUltimate.ReleaseDC(IntPtr.Zero, dC);
            }
            else
            {
                DpiHelper.DeviceDpiX = 96.0;
                DpiHelper.DeviceDpiY = 96.0;
            }
            System.Windows.Media.Matrix identity  = System.Windows.Media.Matrix.Identity;
            System.Windows.Media.Matrix identity2 = System.Windows.Media.Matrix.Identity;
            identity.Scale(DpiHelper.DeviceDpiX / 96.0, DpiHelper.DeviceDpiY / 96.0);
            identity2.Scale(96.0 / DpiHelper.DeviceDpiX, 96.0 / DpiHelper.DeviceDpiY);
            DpiHelper.transformFromDevice = new MatrixTransform(identity2);
            DpiHelper.transformFromDevice.Freeze();
            DpiHelper.transformToDevice = new MatrixTransform(identity);
            DpiHelper.transformToDevice.Freeze();
        }
Ejemplo n.º 14
0
 protected virtual IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam)
 {
     return(NativeMethodsUltimate.DefWindowProc(hwnd, msg, wParam, lParam));
 }
Ejemplo n.º 15
0
 private void SubclassWndProc()
 {
     this.wndProc = new NativeMethodsUltimate.WndProc(this.WndProc);
     NativeMethodsUltimate.SetWindowLong(this.handle, -4, Marshal.GetFunctionPointerForDelegate(this.wndProc));
 }