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
- GridViewHeaderRowPresenter.cs
- PropertyItemInternal.cs
- StaticSiteMapProvider.cs
- TypeSystem.cs
- ConnectionProviderAttribute.cs
- CellTreeNodeVisitors.cs
- IPEndPoint.cs
- PersonalizableTypeEntry.cs
- InputLanguageCollection.cs
- RegexCode.cs
- RichListBox.cs
- UntypedNullExpression.cs
- Dump.cs
- CustomErrorCollection.cs
- Types.cs
- _ListenerRequestStream.cs
- CryptoStream.cs
- DbMetaDataColumnNames.cs
- XslCompiledTransform.cs
- FilterEventArgs.cs
- DSASignatureDeformatter.cs
- LocalizedNameDescriptionPair.cs
- ServiceDesigner.xaml.cs
- BasePattern.cs
- _Connection.cs
- GeneralTransform3DGroup.cs
- FileBasedResourceGroveler.cs
- XomlCompilerError.cs
- ButtonField.cs
- QilName.cs
- StringPropertyBuilder.cs
- StopRoutingHandler.cs
- SaveFileDialog.cs
- StatusBarAutomationPeer.cs
- PerformanceCounterPermissionEntryCollection.cs
- ListManagerBindingsCollection.cs
- Selection.cs
- DataGridViewCellValidatingEventArgs.cs
- QueuePathEditor.cs
- FeatureSupport.cs
- DocumentViewerAutomationPeer.cs
- HtmlElement.cs
- ToolStripSeparatorRenderEventArgs.cs
- ClassHandlersStore.cs
- UriTemplateDispatchFormatter.cs
- ScriptResourceDefinition.cs
- WeakReferenceList.cs
- SchemaSetCompiler.cs
- TimeSpanStorage.cs
- LayoutEditorPart.cs
- MetaTable.cs
- BoundField.cs
- Scripts.cs
- LinqMaximalSubtreeNominator.cs
- CollectionContainer.cs
- ExtensionCollection.cs
- figurelengthconverter.cs
- MenuItem.cs
- DesignerVerb.cs
- BookmarkWorkItem.cs
- DispatchChannelSink.cs
- SoapIgnoreAttribute.cs
- XXXOnTypeBuilderInstantiation.cs
- X509Chain.cs
- EventMappingSettings.cs
- WebPartZone.cs
- BuildResult.cs
- QueryCacheKey.cs
- TextBox.cs
- ActivityWithResultValueSerializer.cs
- DependencyPropertyValueSerializer.cs
- ActivityTypeResolver.xaml.cs
- Viewport2DVisual3D.cs
- XmlSchemaChoice.cs
- PaperSize.cs
- EventLogException.cs
- RuntimeConfig.cs
- MenuItemStyleCollection.cs
- ItemMap.cs
- SecurityUtils.cs
- QilXmlWriter.cs
- SimpleTypeResolver.cs
- _TLSstream.cs
- MouseDevice.cs
- ProfileManager.cs
- AssemblyUtil.cs
- CreateSequenceResponse.cs
- CollectionViewSource.cs
- DirectoryInfo.cs
- RefreshPropertiesAttribute.cs
- StateDesigner.cs
- InputScopeConverter.cs
- TraceSource.cs
- BidPrivateBase.cs
- OdbcConnectionOpen.cs
- FormatterConverter.cs
- SqlCharStream.cs
- DataGridViewColumnEventArgs.cs
- TextServicesContext.cs
- SplitContainer.cs