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
- KerberosSecurityTokenProvider.cs
- _AutoWebProxyScriptWrapper.cs
- ObjectParameterCollection.cs
- PointCollection.cs
- ReadOnlyHierarchicalDataSource.cs
- MembershipUser.cs
- MemoryRecordBuffer.cs
- InsufficientMemoryException.cs
- CoTaskMemHandle.cs
- WebPartDesigner.cs
- TextDecorationCollectionConverter.cs
- PageBreakRecord.cs
- PieceNameHelper.cs
- DataListItem.cs
- TogglePatternIdentifiers.cs
- GeometryCollection.cs
- SafeRightsManagementEnvironmentHandle.cs
- WaitHandle.cs
- FileLogRecord.cs
- X509IssuerSerialKeyIdentifierClause.cs
- COM2EnumConverter.cs
- PropertyMapper.cs
- TemplateContentLoader.cs
- BlockingCollection.cs
- ConfigXmlWhitespace.cs
- XslException.cs
- WizardPanel.cs
- RuntimeConfigurationRecord.cs
- ProcessHostFactoryHelper.cs
- PropertyDescriptor.cs
- FastEncoder.cs
- SqlDataSourceView.cs
- SystemInformation.cs
- XpsException.cs
- ToolConsole.cs
- LocatorManager.cs
- X509CertificateChain.cs
- SimpleTextLine.cs
- SQLMoneyStorage.cs
- TreeViewBindingsEditor.cs
- PersistenceTypeAttribute.cs
- ObjectDataProvider.cs
- RefType.cs
- NativeMethods.cs
- _ListenerAsyncResult.cs
- glyphs.cs
- VectorAnimationBase.cs
- SecurityContextKeyIdentifierClause.cs
- GridEntryCollection.cs
- FormsAuthenticationTicket.cs
- UnsafeNativeMethods.cs
- DbConnectionPoolGroupProviderInfo.cs
- Section.cs
- WindowsIdentity.cs
- DrawingContextWalker.cs
- HostedHttpContext.cs
- MsmqIntegrationProcessProtocolHandler.cs
- DefaultParameterValueAttribute.cs
- MenuTracker.cs
- Color.cs
- Evaluator.cs
- WebPartDisplayModeCollection.cs
- AttributeProviderAttribute.cs
- DataGridViewColumnEventArgs.cs
- loginstatus.cs
- CodePropertyReferenceExpression.cs
- WorkflowIdleElement.cs
- _UriSyntax.cs
- TriggerCollection.cs
- DbProviderFactoriesConfigurationHandler.cs
- SchemaEntity.cs
- OverflowException.cs
- XPathNodeList.cs
- WebPartDisplayMode.cs
- DrawingServices.cs
- TextChangedEventArgs.cs
- JournalEntryStack.cs
- XmlNode.cs
- HwndHostAutomationPeer.cs
- ArrayHelper.cs
- ColumnMapVisitor.cs
- DelegatingConfigHost.cs
- HandlerWithFactory.cs
- ValueType.cs
- LazyTextWriterCreator.cs
- OleDbConnectionInternal.cs
- DeviceContext2.cs
- SmiMetaDataProperty.cs
- SocketPermission.cs
- newitemfactory.cs
- XmlSchemaAnnotated.cs
- SocketAddress.cs
- AbsoluteQuery.cs
- XmlNodeList.cs
- VectorCollectionValueSerializer.cs
- LogRestartAreaEnumerator.cs
- TextEncodedRawTextWriter.cs
- DebugViewWriter.cs
- PropertyGridCommands.cs
- OrthographicCamera.cs