示例#1
0
        internal unsafe void DrawBackground(Gdi32.HDC dc, Rectangle bounds, Rectangle clipRectangle, IntPtr hwnd)
        {
            if (bounds.Width < 0 || bounds.Height < 0 || clipRectangle.Width < 0 || clipRectangle.Height < 0)
            {
                return;
            }

            if (IntPtr.Zero != hwnd)
            {
                using var htheme = new UxTheme.OpenThemeDataScope(hwnd, Class);
                if (htheme.IsNull)
                {
                    throw new InvalidOperationException(SR.VisualStyleHandleCreationFailed);
                }
                RECT rect     = bounds;
                RECT clipRect = clipRectangle;
                _lastHResult = DrawThemeBackground(htheme, dc, Part, State, ref rect, &clipRect);
            }
            else
            {
                RECT rect     = bounds;
                RECT clipRect = clipRectangle;
                _lastHResult = DrawThemeBackground(this, dc, Part, State, ref rect, &clipRect);
            }
        }
示例#2
0
        internal unsafe Size GetPartSize(Gdi32.HDC dc, ThemeSizeType type, IntPtr hwnd = default)
        {
            // Valid values are 0x0 to 0x2
            SourceGenerated.EnumValidator.Validate(type, nameof(type));

            if (DpiHelper.IsPerMonitorV2Awareness && hwnd != IntPtr.Zero)
            {
                using var htheme = new UxTheme.OpenThemeDataScope(hwnd, Class);
                if (htheme.IsNull)
                {
                    throw new InvalidOperationException(SR.VisualStyleHandleCreationFailed);
                }
                _lastHResult = GetThemePartSize(htheme, dc, Part, State, null, type, out Size dpiSize);
                return(dpiSize);
            }

            _lastHResult = GetThemePartSize(this, dc, Part, State, null, type, out Size size);
            return(size);
        }
        internal unsafe Size GetPartSize(Gdi32.HDC dc, ThemeSizeType type, IntPtr hwnd = default)
        {
            // Valid values are 0x0 to 0x2
            if (!ClientUtils.IsEnumValid(type, (int)type, (int)ThemeSizeType.Minimum, (int)ThemeSizeType.Draw))
            {
                throw new InvalidEnumArgumentException(nameof(type), (int)type, typeof(ThemeSizeType));
            }

            if (DpiHelper.IsPerMonitorV2Awareness && hwnd != IntPtr.Zero)
            {
                using var htheme = new UxTheme.OpenThemeDataScope(hwnd, Class);
                if (htheme.IsNull)
                {
                    throw new InvalidOperationException(SR.VisualStyleHandleCreationFailed);
                }
                _lastHResult = GetThemePartSize(htheme, dc, Part, State, null, type, out Size dpiSize);
                return(dpiSize);
            }

            _lastHResult = GetThemePartSize(this, dc, Part, State, null, type, out Size size);
            return(size);
        }