예제 #1
0
        public IntPtr?GetThemeBitmap(int partId, int stateId, int propertyId)
        {
            HResult hr = UxThemeExNativeMethods.UxGetThemeBitmap(
                themeFile, theme, partId, stateId, propertyId, GBF.GBF_DIRECT, out IntPtr value);

            return(hr.Succeeded() ? value : (IntPtr?)null);
        }
예제 #2
0
        public LOGFONT GetThemeSysFont(int propertyId)
        {
            var     value = new LOGFONT();
            HResult hr    = UxThemeExNativeMethods.GetThemeSysFont(theme, propertyId, value);

            return(Found(hr) ? value : null);
        }
예제 #3
0
        public int?GetThemeSysInt(int propertyId)
        {
            HResult hr = UxThemeExNativeMethods.GetThemeSysInt(
                theme, propertyId, out int value);

            return(Found(hr) ? value : (int?)null);
        }
예제 #4
0
        public int?GetThemeEnumValue(int partId, int stateId, int propertyId)
        {
            HResult hr = UxThemeExNativeMethods.UxGetThemeEnumValue(
                themeFile, theme, partId, stateId, propertyId, out int value);

            return(Found(hr) ? value : (int?)null);
        }
예제 #5
0
        public bool?GetThemeBool(int partId, int stateId, int propertyId)
        {
            HResult hr = UxThemeExNativeMethods.UxGetThemeBool(
                themeFile, theme, partId, stateId, propertyId, out var value);

            return(Found(hr) ? value : (bool?)null);
        }
예제 #6
0
        public Color?GetThemeColor(int partId, int stateId, int propertyId)
        {
            HResult hr = UxThemeExNativeMethods.UxGetThemeColor(
                themeFile, theme, partId, stateId, propertyId, out int value);

            return(Found(hr) ? ThemeExtensions.ColorFromArgb(value) : (Color?)null);
        }
예제 #7
0
        public RECT?GetThemeRect(int partId, int stateId, int propertyId)
        {
            HResult hr = UxThemeExNativeMethods.UxGetThemeRect(
                themeFile, theme, partId, stateId, propertyId, out RECT value);

            return(Found(hr) ? value : (RECT?)null);
        }
예제 #8
0
        public SIZE?GetThemePartSize(int partId, int stateId, ThemeSize themeSize)
        {
            HResult hr = UxThemeExNativeMethods.UxGetThemePartSize(
                themeFile, theme, IntPtr.Zero, partId, stateId, null, themeSize, out SIZE value);

            return(Found(hr) ? value : (SIZE?)null);
        }
예제 #9
0
        public POINT?GetThemePosition(int partId, int stateId, int propertyId)
        {
            HResult hr = UxThemeExNativeMethods.UxGetThemePosition(
                themeFile, theme, partId, stateId, propertyId, out POINT value);

            return(Found(hr) ? value : (POINT?)null);
        }
예제 #10
0
        public MARGINS?GetThemeMargins(int partId, int stateId, int propertyId)
        {
            HResult hr = UxThemeExNativeMethods.UxGetThemeMargins(
                themeFile, theme, IntPtr.Zero, partId, stateId, propertyId, null, out MARGINS value);

            return(Found(hr) ? value : (MARGINS?)null);
        }
예제 #11
0
        public PropertyOrigin GetThemePropertyOrigin(
            int partId, int stateId, int propertyId)
        {
            HResult hr = UxThemeExNativeMethods.UxGetThemePropertyOrigin(
                themeFile, theme, partId, stateId, propertyId, out PropertyOrigin origin);

            return(hr.Succeeded() ? origin : PropertyOrigin.NotFound);
        }
예제 #12
0
        public INTLIST GetThemeIntList(int partId, int stateId, int propertyId)
        {
            var     value = new INTLIST();
            HResult hr    = UxThemeExNativeMethods.UxGetThemeIntList(
                themeFile, theme, partId, stateId, propertyId, value);

            return(Found(hr) ? value : null);
        }
예제 #13
0
        public LOGFONT GetThemeFont(int partId, int stateId, int propertyId)
        {
            var     value = new LOGFONT();
            HResult hr    = UxThemeExNativeMethods.UxGetThemeFont(
                themeFile, theme, IntPtr.Zero, partId, stateId, propertyId, value);

            return(Found(hr) ? value : null);
        }
예제 #14
0
        public string GetThemeFilename(int partId, int stateId, int propertyId)
        {
            var     filename = new StringBuilder(512);
            HResult hr       = UxThemeExNativeMethods.UxGetThemeFilename(
                themeFile, theme, partId, stateId, propertyId, filename, filename.Capacity);

            return(Found(hr) ? filename.ToString() : null);
        }
예제 #15
0
        public string GetThemeSysString(int propertyId)
        {
            var     value = new StringBuilder(512);
            HResult hr    = UxThemeExNativeMethods.GetThemeSysString(
                theme, propertyId, value, value.Capacity);

            return(Found(hr) ? value.ToString() : null);
        }
예제 #16
0
        public static SafeThemeFileHandle LoadTheme(
            string path, UxThemeLoadParams loadParams = null)
        {
            UxThemeExNativeMethods.UxOpenThemeFileEx(
                path,
                loadParams?.IsHighContrast ?? false,
                loadParams?.CustomColors,
                out var themeFile).ThrowIfFailed();

            return(themeFile);
        }
예제 #17
0
        public async Task SetThemeAsync(string path, UxThemeLoadParams loadParams = null)
        {
            if (path != null)
            {
                SetNativeTheme(await Task.Run(() => LoadTheme(path, loadParams)));
            }
            else
            {
                SetNativeTheme(SafeThemeFileHandle.Zero);
            }

            CurrentOverride = path;
            UxThemeExNativeMethods.UxBroadcastThemeChange();
        }
예제 #18
0
 public async Task SetPresentationFrameworkTheme(Dispatcher dispatcher, Uri resourceUri)
 {
     await dispatcher.InvokeAsync(() => {
         if (resourceUri != null)
         {
             ThemeManager.SetPresentationFrameworkTheme(resourceUri);
         }
         else
         {
             ThemeManager.ClearPresentationFrameworkTheme();
         }
         UxThemeExNativeMethods.UxBroadcastThemeChange();
     }, DispatcherPriority.ContextIdle);
 }
예제 #19
0
        private void SetNativeTheme(SafeThemeFileHandle newTheme)
        {
            var oldTheme = theme;

            if (newTheme != null && !newTheme.IsInvalid && !newTheme.IsClosed)
            {
                UxThemeExNativeMethods.UxOverrideTheme(newTheme).ThrowIfFailed();
                UxThemeExNativeMethods.UxHook().ThrowIfFailed();
                theme = newTheme;
            }
            else
            {
                theme = null;
                UxThemeExNativeMethods.UxUnhook().ThrowIfFailed();
                UxThemeExNativeMethods.UxOverrideTheme(SafeThemeFileHandle.Zero).ThrowIfFailed();
            }

            oldTheme?.Dispose();
        }
예제 #20
0
        public ThemeFile LoadTheme()
        {
            var themeFile = new ThemeFile(filePath, neutralModule, muiModule);

            themeFile.Version = GetVersion();
            var classNames = ReadClassMap();
            var vmap       = ReadVariantMap();
            var bcmap      = ReadBaseClassMap();

            themeFile.VariantMap = vmap;
            themeFile.ClassNames = classNames;
            UxThemeExNativeMethods.UxOpenThemeFile(filePath, isHighContrast, out var themeFileHandle).ThrowIfFailed();
            themeFile.NativeThemeFile = themeFileHandle;

            ReadProperties(themeFile, "RMAP", "RMAP");
            ReadProperties(themeFile, "VARIANT", vmap.Name);

            foreach (var @class in themeFile.Classes)
            {
                AddKnownPartsAndStates(@class);
            }

            var classMap    = themeFile.Classes.ToDictionary(x => x.Name);
            var classNames2 = themeFile.ClassNames.Skip(4).ToList();

            foreach (var entry in bcmap.Map)
            {
                var className     = classNames2[entry.Key];
                var baseClassName = classNames2[entry.Value];

                if (classMap.TryGetValue(className, out ThemeClass @class) &&
                    classMap.TryGetValue(baseClassName, out ThemeClass baseClass))
                {
                    @class.BaseClass = baseClass;
                }
            }

            themeFile.Sort();

            return(themeFile);
        }
예제 #21
0
        public unsafe Stream GetThemeStream(
            int partId, int stateId, int propertyId, SafeModuleHandle instance)
        {
            HResult hr = UxThemeExNativeMethods.UxGetThemeStream(
                themeFile, theme, partId, stateId, propertyId, out IntPtr stream,
                out uint length, instance);

            if (!Found(hr) || stream == IntPtr.Zero)
            {
                return(null);
            }

            var buffer = new byte[length];

            if (length > 0)
            {
                Marshal.Copy(stream, buffer, 0, buffer.Length);
            }
            return(new UnmanagedMemoryStream(
                       (byte *)stream.ToPointer(), 0, length, FileAccess.Read));
        }
 protected override bool ReleaseHandle()
 {
     return(UxThemeExNativeMethods.UxCloseThemeFile(handle) >= 0);
 }
예제 #23
0
 public HResult GetThemeTransitionDuration(
     int partId, int stateFrom, int stateTo, int propertyId, out uint duration)
 {
     return(UxThemeExNativeMethods.UxGetThemeTransitionDuration(
                themeFile, theme, partId, stateFrom, stateTo, propertyId, out duration));
 }
예제 #24
0
 public bool GetThemeSysBool(int propertyId)
 {
     return(UxThemeExNativeMethods.GetThemeSysBool(theme, propertyId));
 }
예제 #25
0
        public Color GetThemeSysColor(int propertyId)
        {
            int value = UxThemeExNativeMethods.GetThemeSysColor(theme, propertyId);

            return(ThemeExtensions.ColorFromArgb(value));
        }
예제 #26
0
 public static UxThemeExData Open(
     SafeThemeFileHandle themeFile, IntPtr hwnd, string classList)
 {
     return(new UxThemeExData(
                themeFile, UxThemeExNativeMethods.UxOpenThemeData(themeFile, hwnd, classList)));
 }