Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / wpf / src / Framework / MS / Win32 / UxThemeWrapper.cs / 1305600 / 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
- SolidColorBrush.cs
- PropVariant.cs
- ManagementObjectSearcher.cs
- TextPattern.cs
- ProxyWebPartConnectionCollection.cs
- _Rfc2616CacheValidators.cs
- CodeMemberMethod.cs
- HttpSocketManager.cs
- SQLBinary.cs
- MustUnderstandSoapException.cs
- OdbcConnectionOpen.cs
- DesignerDataColumn.cs
- ClientSponsor.cs
- ChtmlPageAdapter.cs
- XamlSerializer.cs
- TaskResultSetter.cs
- ImageSourceValueSerializer.cs
- AddInSegmentDirectoryNotFoundException.cs
- SelectedGridItemChangedEvent.cs
- TypeSystem.cs
- figurelengthconverter.cs
- Part.cs
- Pkcs7Recipient.cs
- CookielessHelper.cs
- ThemeDirectoryCompiler.cs
- XmlText.cs
- PointLight.cs
- MetadataPropertyCollection.cs
- PassportAuthenticationEventArgs.cs
- ToolZone.cs
- StoreItemCollection.Loader.cs
- Propagator.cs
- SerializationFieldInfo.cs
- RegexCaptureCollection.cs
- SignedInfo.cs
- TCPClient.cs
- DataSourceGroupCollection.cs
- MessageEnumerator.cs
- TaskFormBase.cs
- Encoding.cs
- X509RecipientCertificateServiceElement.cs
- Int32RectConverter.cs
- Stylesheet.cs
- EntityDataReader.cs
- AudioStateChangedEventArgs.cs
- DropShadowEffect.cs
- QuaternionIndependentAnimationStorage.cs
- HttpFileCollection.cs
- EndpointAddressProcessor.cs
- DataGridHeaderBorder.cs
- Int64.cs
- XmlTextAttribute.cs
- TailCallAnalyzer.cs
- NumberSubstitution.cs
- D3DImage.cs
- View.cs
- RootContext.cs
- Debugger.cs
- List.cs
- LinqDataSourceStatusEventArgs.cs
- EntityContainerEmitter.cs
- DateBoldEvent.cs
- IgnoreSection.cs
- RequestCache.cs
- PeerInvitationResponse.cs
- StylusCollection.cs
- SecureUICommand.cs
- RelativeSource.cs
- PersistencePipeline.cs
- ControlSerializer.cs
- DataControlField.cs
- AxisAngleRotation3D.cs
- CachedTypeface.cs
- WsatConfiguration.cs
- FontNamesConverter.cs
- X509CertificateRecipientServiceCredential.cs
- XamlHostingSectionGroup.cs
- FixedPageStructure.cs
- Header.cs
- LambdaCompiler.Logical.cs
- HierarchicalDataTemplate.cs
- CheckBoxRenderer.cs
- AttributeCollection.cs
- OutputScopeManager.cs
- ToolTip.cs
- PropertyInfoSet.cs
- ContentFileHelper.cs
- Predicate.cs
- ListParaClient.cs
- WorkflowWebService.cs
- SelectionEditor.cs
- ErrorHandlingAcceptor.cs
- MappingSource.cs
- ChangeDirector.cs
- Comparer.cs
- HttpListenerException.cs
- SignatureHelper.cs
- SizeValueSerializer.cs
- HostingEnvironmentException.cs
- PopupEventArgs.cs