Ejemplo n.º 1
0
        private bool IsCloakedApplication(IntPtr hWnd)
        {
            var mainResult = IntPtr.Zero;
            var hResult    = Dwmapi.DwmGetWindowAttribute(hWnd, (int)DWMWINDOWATTRIBUTE.DWMWA_CLOAKED, out mainResult, Marshal.SizeOf(typeof(uint)));

            return(hResult > 0 || (DWMATTR)mainResult != 0);
        }
Ejemplo n.º 2
0
        private static bool IsValidWindow(IntPtr hWnd)
        {
            // ウィンドウハンドルであるか
            if (!User32.IsWindow(hWnd))
            {
                return(false);
            }

            // 見えるか
            if (!User32.IsWindowVisible(hWnd))
            {
                return(false);
            }

            // シェル ウィンドウでないか
            if (NativeMethods.GetShellWindow() == hWnd)
            {
                return(false);
            }

            // 親ウィンドウであるか
            if (NativeMethods.GetAncestor(hWnd, 2 /* GA_ROOT */) != hWnd)
            {
                return(false);
            }

            // 見えないウィンドウでないか
            if (WindowsVersion.Is8OrGreater && Dwmapi.DwmGetCloaked(hWnd))
            {
                return(false);
            }

            return(true);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// When the window's state (maximized, minimized, or restored) changes, this sets the size of the non-client area at the top of the window properly so
        /// that the tabs can be displayed.
        /// </summary>
        protected void SetFrameSize()
        {
            if (TabRenderer == null || WindowState == FormWindowState.Minimized)
            {
                return;
            }

            int topPadding;

            if (WindowState == FormWindowState.Maximized || TabRenderer.RendersEntireTitleBar)
            {
                topPadding = TabRenderer.TabHeight - TabRenderer.TopPadding - SystemInformation.CaptionHeight;
            }

            else
            {
                topPadding = TabRenderer.TabHeight - SystemInformation.CaptionHeight;
            }

            if (!TabRenderer.IsWindows10 && WindowState == FormWindowState.Maximized)
            {
                topPadding += 1;
            }

            Padding = new Padding(
                Padding.Left, topPadding > 0
                                        ? topPadding
                                        : 0, Padding.Right, Padding.Bottom);

            if (!TabRenderer.IsWindows10)
            {
                // Set the margins and extend the frame into the client area
                MARGINS margins = new MARGINS
                {
                    cxLeftWidth    = 1,
                    cxRightWidth   = 1,
                    cyBottomHeight = 1,
                    cyTopHeight    = topPadding > 0
                                                                                  ? topPadding
                                                                                  : 0
                };

                Dwmapi.DwmExtendFrameIntoClientArea(Handle, ref margins);
            }

            _nonClientAreaHeight = SystemInformation.CaptionHeight + (topPadding > 0
                                ? topPadding
                                : 0);

            if (AeroPeekEnabled)
            {
                foreach (
                    TabbedThumbnail preview in
                    Tabs.Select(tab => TaskbarManager.Instance.TabbedThumbnail.GetThumbnailPreview(tab.Content)).Where(preview => preview != null))
                {
                    preview.PeekOffset = new Vector(Padding.Left, Padding.Top - 1);
                }
            }
        }
Ejemplo n.º 4
0
        public static bool GetExtendedFrameBounds(IntPtr handle, out Rectangle rectangle)
        {
            int result = Dwmapi.DwmGetWindowAttribute(handle, (int)DwmWindowAttribute.ExtendedFrameBounds, out RECT rect,
                                                      Marshal.SizeOf(typeof(RECT)));

            rectangle = rect;
            return(result == 0);
        }
Ejemplo n.º 5
0
 private static RECT GetWindowRect(IntPtr hWnd)
 {
     try
     {
         return(Dwmapi.DwmGetExtendedFrameBounds(hWnd));
     }
     catch (COMException)
     {
         return(User32.GetWindowRect(hWnd));
     }
 }
Ejemplo n.º 6
0
        public static void AeroGlassForVistaAndSeven(IntPtr hWnd, bool enable)
        {
            var blurBehind = new DWM_BLURBEHIND()
            {
                dwFlags  = DWM_BB.Enable,
                fEnable  = enable,
                hRgnBlur = IntPtr.Zero,
                fTransitionOnMaximized = false
            };

            Dwmapi.DwmEnableBlurBehindWindow(hWnd, ref blurBehind);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// When the window's state (maximized, minimized, or restored) changes, this sets the size of the non-client area at the top of the window properly so
        /// that the tabs can be displayed.
        /// </summary>
        protected void SetFrameSize()
        {
            if (TabRenderer == null || WindowState == FormWindowState.Minimized)
            {
                return;
            }

            int topPadding;

            if (WindowState == FormWindowState.Maximized)
            {
                //topPadding = TabRenderer.TabHeight - SystemInformation.CaptionHeight;
                topPadding = TabRenderer.TabHeight - SystemInformation.CaptionHeight + TabRenderer.MaximizedWindowTabTopOffset + 1; // Todo figure out 1 fudge factor
            }

            else
            {
                //topPadding = (TabRenderer.TabHeight + SystemInformation.CaptionButtonSize.Height) - SystemInformation.CaptionHeight;
                topPadding = TabRenderer.TabHeight - SystemInformation.CaptionHeight + TabRenderer.WindowTabTopOffset - 7; // Todo figure out 5 fudge factor
            }

            Padding = new Padding(
                Padding.Left, topPadding > 0
                                        ? topPadding
                                        : 0, Padding.Right, Padding.Bottom);

            // Set the margins and extend the frame into the client area
            MARGINS margins = new MARGINS
            {
                cxLeftWidth    = 0,
                cxRightWidth   = 0,
                cyBottomHeight = 0,
                cyTopHeight    = topPadding > 0
                                                                          ? topPadding
                                                                          : 0
            };

            Dwmapi.DwmExtendFrameIntoClientArea(Handle, ref margins);

            _nonClientAreaHeight = SystemInformation.CaptionHeight + (topPadding > 0
                                ? topPadding
                                : 0);

            if (AeroPeekEnabled)
            {
                foreach (
                    TabbedThumbnail preview in
                    Tabs.Select(tab => TaskbarManager.Instance.TabbedThumbnail.GetThumbnailPreview(tab.Content)).Where(preview => preview != null))
                {
                    preview.PeekOffset = new Vector(Padding.Left, Padding.Top - 1);
                }
            }
        }
Ejemplo n.º 8
0
        private Rect GetExtendFrameBounds()
        {
            RECT frameBounds;

            Dwmapi.DwmGetWindowAttribute(this.Handle, DWMWINDOWATTRIBUTE.DWMWA_EXTENDED_FRAME_BOUNDS, out frameBounds, Marshal.SizeOf(typeof(RECT)));

            var dpi = PerMonitorDpi.GetDpi(this.Handle);
            var l   = frameBounds.Left * (1 / dpi.ScaleX);
            var t   = frameBounds.Top * (1 / dpi.ScaleY);
            var w   = (frameBounds.Right - frameBounds.Left) * (1 / dpi.ScaleX);
            var h   = (frameBounds.Bottom - frameBounds.Top) * (1 / dpi.ScaleY);

            return(new Rect(l, t, w, h));
        }
Ejemplo n.º 9
0
        private Rect GetSizeWithMargins()
        {
            Rect size;

            if (Environment.OSVersion.Version.Major < 6)
            {
                GetWindowRect(Handle, out size);
            }
            else if (Dwmapi.DwmGetWindowAttribute(Handle, DWMWA_EXTENDED_FRAME_BOUNDS, out size, Marshal.SizeOf(typeof(Rect))) != 0)
            {
                GetWindowRect(Handle, out size);
            }
            return(size);
        }
Ejemplo n.º 10
0
 /// <summary>Determines if the composition is currently enabled for the desktop.</summary>
 /// <returns>The <see cref="bool" />.</returns>
 public static bool IsCompositionEnabled()
 {
     // Desktop composition is only available on Vista upwards
     if (Environment.OSVersion.Version.Major < 6)
     {
         return(false);
     }
     else
     {
         // Ask the desktop window manager is composition is currently enabled
         bool compositionEnabled;
         Dwmapi.DwmIsCompositionEnabled(out compositionEnabled);
         return(compositionEnabled);
     }
 }
Ejemplo n.º 11
0
        internal override Color GetValue()
        {
            const string keyName   = @"HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\DWM";
            const string valueName = "ColorizationColor";
            int          color;

            if (Registry.GetValue(keyName, valueName, null) is int colorizationColor)
            {
                color = colorizationColor;
            }
            else
            {
                Dwmapi.DwmGetColorizationColor(out color, out _);
            }

            return(ColorHelper.GetColorFromInt64(color));
        }
        protected override Color GetValue()
        {
            const string keyName   = @"HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\DWM";
            const string valueName = "ColorizationColor";
            uint         color;

            var colorizationColor = Registry.GetValue(keyName, valueName, null) as int?;

            if (colorizationColor != null)
            {
                color = (uint)colorizationColor.Value;
            }
            else
            {
                // Note: return the modified value on Windows Vista & 7
                Dwmapi.DwmGetColorizationColor(out color, out _);
            }

            return(ColorHelper.GetColorFromUInt32(color));
        }
Ejemplo n.º 13
0
 public static bool IsDwmEnabled()
 {
     return(Environment.OSVersion.Version.Major >= 6 && Dwmapi.DwmIsCompositionEnabled());
 }
Ejemplo n.º 14
0
        public static void ExtendFrameIntoClient(IntPtr hWnd, int x, int y, int width, int height)
        {
            var margins = new Margins(x, y, width, height);

            Dwmapi.DwmExtendFrameIntoClientArea(hWnd, ref margins);
        }