Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / Orcas / SP / 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
- SqlDataRecord.cs
- entityreference_tresulttype.cs
- EdmToObjectNamespaceMap.cs
- DataGridViewCellCollection.cs
- ObfuscateAssemblyAttribute.cs
- ListBindableAttribute.cs
- xmlglyphRunInfo.cs
- HandoffBehavior.cs
- Vector3D.cs
- GridViewEditEventArgs.cs
- PropertyMapper.cs
- shaper.cs
- State.cs
- DNS.cs
- MarkupExtensionReturnTypeAttribute.cs
- SizeValueSerializer.cs
- CachedFontFamily.cs
- ImageSource.cs
- EditorAttribute.cs
- ByteStreamGeometryContext.cs
- ServiceAppDomainAssociationProvider.cs
- XmlLanguage.cs
- InvokeMethodActivityDesigner.cs
- ThicknessAnimation.cs
- BamlResourceSerializer.cs
- EncodingTable.cs
- DataSourceCache.cs
- Profiler.cs
- AsyncCallback.cs
- DocumentGridPage.cs
- EnumerableRowCollection.cs
- AssociationProvider.cs
- FrameworkPropertyMetadata.cs
- OleDbRowUpdatingEvent.cs
- DataColumnChangeEvent.cs
- QueryOpeningEnumerator.cs
- XPathChildIterator.cs
- SuppressMergeCheckAttribute.cs
- DeclaredTypeElement.cs
- HTTPAPI_VERSION.cs
- MDIControlStrip.cs
- NumericUpDownAccelerationCollection.cs
- ConfigurationCollectionAttribute.cs
- PageThemeParser.cs
- PreviousTrackingServiceAttribute.cs
- CommonXSendMessage.cs
- ProbeDuplexCD1AsyncResult.cs
- DependencyPropertyAttribute.cs
- FormViewModeEventArgs.cs
- ZoneButton.cs
- DesignerOptionService.cs
- BaseComponentEditor.cs
- CompensationToken.cs
- WebRequestModulesSection.cs
- NetPeerTcpBindingCollectionElement.cs
- ActivityExecutorSurrogate.cs
- WebRequestModulesSection.cs
- IncrementalReadDecoders.cs
- XmlRootAttribute.cs
- BulletDecorator.cs
- CompensationToken.cs
- DocumentViewerBaseAutomationPeer.cs
- FileChangeNotifier.cs
- DataGridItemCollection.cs
- HttpFileCollectionBase.cs
- WindowsPrincipal.cs
- TemplateBindingExpression.cs
- CompilerHelpers.cs
- KeyGesture.cs
- RNGCryptoServiceProvider.cs
- BindingExpressionUncommonField.cs
- RepeaterItemEventArgs.cs
- SerializationHelper.cs
- ContextMenuAutomationPeer.cs
- Int16AnimationBase.cs
- UndoEngine.cs
- Graph.cs
- CollectionChangedEventManager.cs
- UseAttributeSetsAction.cs
- GridLengthConverter.cs
- BlurBitmapEffect.cs
- TraceListeners.cs
- CellConstantDomain.cs
- OleDbException.cs
- KeyGestureConverter.cs
- DynamicILGenerator.cs
- SelectionItemPatternIdentifiers.cs
- LinqDataSourceView.cs
- InspectionWorker.cs
- Vector3DAnimation.cs
- EventTrigger.cs
- CodeThrowExceptionStatement.cs
- ExpressionBinding.cs
- DataServiceQuery.cs
- PersonalizationProvider.cs
- SqlFlattener.cs
- NoClickablePointException.cs
- WebBrowserNavigatedEventHandler.cs
- ClientTarget.cs
- Size3DConverter.cs