Example #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);
        }
Example #2
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);
        }
Example #3
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));
        }
Example #4
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);
        }
Example #5
0
        /// <summary>
        /// 指定ウィンドウハンドルのウィンドウサイズを取得します。
        /// </summary>
        /// <param name="handle">ウィンドウハンドル</param>
        /// <returns>ウィンドウサイズ</returns>
        private static Rectangle GetWindowSize(IntPtr handle)
        {
            // Vista以降の場合、DWMでウィンドウサイズを取得
            var rect = new RECT();

            if (Environment.OSVersion.Version.Major >= 6)
            {
                if (Dwmapi.DwmGetWindowAttribute(handle, (int)DWMWA.EXTENDED_FRAME_BOUNDS, ref rect, Marshal.SizeOf(typeof(RECT))) == 0)
                {
                    var rectangle = new Rectangle(rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top);
                    if (rectangle.Width > 0 && rectangle.Height > 0)
                    {
                        return(rectangle);
                    }
                }
            }
            if (User32.GetWindowRect(handle, out rect))
            {
                return(new Rectangle(rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top));
            }
            return(Rectangle.Empty);
        }