Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / Orcas / QFE / wpf / src / 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. 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
- Dispatcher.cs
- GroupBox.cs
- input.cs
- InitializerFacet.cs
- StreamFormatter.cs
- HtmlHistory.cs
- WindowsPen.cs
- SqlDataRecord.cs
- InstanceHandleConflictException.cs
- DbReferenceCollection.cs
- SqlTopReducer.cs
- AuthenticationConfig.cs
- WebPartZone.cs
- relpropertyhelper.cs
- MailWebEventProvider.cs
- InvalidComObjectException.cs
- CallbackException.cs
- TextCompositionManager.cs
- UnsafeNativeMethods.cs
- InvalidAsynchronousStateException.cs
- EpmAttributeNameBuilder.cs
- TimeIntervalCollection.cs
- UIElement3D.cs
- NetMsmqBindingCollectionElement.cs
- CriticalHandle.cs
- AssemblyCache.cs
- ColumnBinding.cs
- _SSPIWrapper.cs
- SystemInformation.cs
- PerformanceCounterManager.cs
- WebPartEditorCancelVerb.cs
- BaseCollection.cs
- TypeExtensionConverter.cs
- Char.cs
- UdpRetransmissionSettings.cs
- NotCondition.cs
- wmiprovider.cs
- DisposableCollectionWrapper.cs
- Int32Storage.cs
- XmlAttributeOverrides.cs
- RemoveStoryboard.cs
- EntitySetRetriever.cs
- ContentPlaceHolderDesigner.cs
- ComboBox.cs
- SymbolEqualComparer.cs
- ReaderContextStackData.cs
- ValueHandle.cs
- HtmlInputReset.cs
- CodeSnippetStatement.cs
- URI.cs
- NamespaceListProperty.cs
- SwitchAttribute.cs
- OleDbRowUpdatedEvent.cs
- OptimalTextSource.cs
- UserControlCodeDomTreeGenerator.cs
- InputMethod.cs
- ValueSerializer.cs
- XmlSchemaSimpleContentRestriction.cs
- VerticalAlignConverter.cs
- InternalPermissions.cs
- BooleanKeyFrameCollection.cs
- _LoggingObject.cs
- KeyToListMap.cs
- StringCollection.cs
- SqlCharStream.cs
- AdornerHitTestResult.cs
- DataSpaceManager.cs
- DbProviderFactories.cs
- TypeReference.cs
- LoggedException.cs
- CollectionChangeEventArgs.cs
- HeaderCollection.cs
- Timer.cs
- ContextStack.cs
- CngProvider.cs
- DataGridViewCellValueEventArgs.cs
- MemoryStream.cs
- Animatable.cs
- PeerTransportListenAddressValidatorAttribute.cs
- HybridCollection.cs
- SelectionGlyphBase.cs
- SqlConnectionFactory.cs
- FormatterConverter.cs
- PenContext.cs
- SqlDataSourceSelectingEventArgs.cs
- SafeEventLogWriteHandle.cs
- CheckPair.cs
- XmlObjectSerializerContext.cs
- ComponentCollection.cs
- TransformerInfoCollection.cs
- BaseAsyncResult.cs
- ImmComposition.cs
- EdmSchemaError.cs
- cryptoapiTransform.cs
- BasePattern.cs
- CompilerParameters.cs
- QueueException.cs
- TraceLevelStore.cs
- WebBrowserUriTypeConverter.cs
- InvocationExpression.cs