Code:
/ DotNET / DotNET / 8.0 / untmp / WIN_WINDOWS / lh_tools_devdiv_wpf / Windows / wcp / Framework / MS / Win32 / UxThemeWrapper.cs / 1 / UxThemeWrapper.cs
using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Runtime.InteropServices; using System.Security; using System.Windows; using System.Windows.Media; using System.Text; using MS.Win32; using MS.Internal; namespace MS.Win32 { ////// Wrapper class for loading UxTheme system theme data /// internal static class UxThemeWrapper { static UxThemeWrapper() { _isActive = SafeNativeMethods.IsUxThemeActive(); } internal static bool IsActive { get { return _isActive; } } internal static string ThemeName { get { if (IsActive) { if (_themeName == null) { EnsureThemeName(); } return _themeName; } else { return "classic"; } } } internal static string ThemeColor { get { Debug.Assert(IsActive, "Queried ThemeColor while UxTheme is not active."); if (_themeColor == null) { EnsureThemeName(); } return _themeColor; } } ////// Critical - as this code performs an elevation to get current theme name /// TreatAsSafe - the "critical data" is transformed into "safe data" /// all the info stored is the currrent theme name and current color - e.g. "Luna", "NormalColor" /// Does not contain a path - considered safe. /// [SecurityCritical, SecurityTreatAsSafe] private static void EnsureThemeName() { StringBuilder themeName = new StringBuilder(Win32.NativeMethods.MAX_PATH); StringBuilder themeColor = new StringBuilder(Win32.NativeMethods.MAX_PATH); if (UnsafeNativeMethods.GetCurrentThemeName(themeName, themeName.Capacity, themeColor, themeColor.Capacity, null, 0) == 0) { // Success _themeName = themeName.ToString(); _themeName = Path.GetFileNameWithoutExtension(_themeName); _themeColor = themeColor.ToString(); } else { // Failed to retrieve the name _themeName = _themeColor = String.Empty; } } internal static void OnThemeChanged() { _isActive = SafeNativeMethods.IsUxThemeActive(); _themeName = null; _themeColor = null; } private static bool _isActive; private static string _themeName; private static string _themeColor; } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- HeaderedItemsControl.cs
- DbConnectionPoolIdentity.cs
- ExtendedProperty.cs
- RequiredFieldValidator.cs
- SqlProvider.cs
- Socket.cs
- DesignerMetadata.cs
- DataListItem.cs
- WebPartVerbsEventArgs.cs
- Point3DAnimation.cs
- ParameterCollection.cs
- DPCustomTypeDescriptor.cs
- AccessDataSourceWizardForm.cs
- DependencyPropertyValueSerializer.cs
- BasicSecurityProfileVersion.cs
- StopStoryboard.cs
- XmlSchemaInfo.cs
- ReflectEventDescriptor.cs
- WebPartsPersonalizationAuthorization.cs
- Privilege.cs
- Figure.cs
- FormatControl.cs
- ParameterBuilder.cs
- OverrideMode.cs
- ReadOnlyDictionary.cs
- Decimal.cs
- Module.cs
- MappingMetadataHelper.cs
- Assign.cs
- SecurityTokenAuthenticator.cs
- CompilerInfo.cs
- ValidationHelper.cs
- TreeViewEvent.cs
- IfAction.cs
- mediaclock.cs
- KerberosSecurityTokenProvider.cs
- ScalarConstant.cs
- IndexedString.cs
- WmlLabelAdapter.cs
- RestHandlerFactory.cs
- Dump.cs
- IdentityModelDictionary.cs
- TraceContextEventArgs.cs
- ScriptingRoleServiceSection.cs
- WebPartChrome.cs
- HtmlEmptyTagControlBuilder.cs
- StoreItemCollection.Loader.cs
- JsonFormatMapping.cs
- OleDragDropHandler.cs
- CodeDefaultValueExpression.cs
- RuntimeResourceSet.cs
- HwndMouseInputProvider.cs
- CurrencyWrapper.cs
- ILGen.cs
- BaseServiceProvider.cs
- CodeStatement.cs
- __ConsoleStream.cs
- StringFormat.cs
- GeneralTransformGroup.cs
- Attributes.cs
- GeometryHitTestParameters.cs
- Script.cs
- HostProtectionException.cs
- ReadOnlyHierarchicalDataSourceView.cs
- serverconfig.cs
- SettingsPropertyNotFoundException.cs
- DoubleLinkList.cs
- XamlPathDataSerializer.cs
- PropertyOverridesDialog.cs
- ProxyRpc.cs
- RoleManagerEventArgs.cs
- CallbackHandler.cs
- DropSource.cs
- GridToolTip.cs
- WindowsListViewSubItem.cs
- ListBoxItem.cs
- RelationshipNavigation.cs
- JavascriptCallbackMessageInspector.cs
- CaseInsensitiveComparer.cs
- HwndSourceParameters.cs
- DirectionalLight.cs
- SafeSystemMetrics.cs
- StateChangeEvent.cs
- Compiler.cs
- TypeInitializationException.cs
- MediaElement.cs
- BaseConfigurationRecord.cs
- AnnotationResource.cs
- EntityWrapper.cs
- DbConnectionPoolIdentity.cs
- XmlArrayAttribute.cs
- KeyedCollection.cs
- TextTreeTextBlock.cs
- SynchronizedInputAdaptor.cs
- UnsettableComboBox.cs
- ShaderEffect.cs
- FieldToken.cs
- TableCell.cs
- ConfigurationStrings.cs
- SqlDuplicator.cs