コード例 #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);
            }
        }
コード例 #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);
        }
コード例 #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);
 }
コード例 #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;
     }
 }
コード例 #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);
        }
コード例 #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);
        }
コード例 #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;
     }
 }
コード例 #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);
        }
コード例 #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();
        }
コード例 #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));
        }
コード例 #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);
            }
        }
コード例 #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;
                }
            }
        }
コード例 #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();
        }
コード例 #14
0
 protected virtual IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam)
 {
     return(NativeMethodsUltimate.DefWindowProc(hwnd, msg, wParam, lParam));
 }
コード例 #15
0
 private void SubclassWndProc()
 {
     this.wndProc = new NativeMethodsUltimate.WndProc(this.WndProc);
     NativeMethodsUltimate.SetWindowLong(this.handle, -4, Marshal.GetFunctionPointerForDelegate(this.wndProc));
 }