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
- EntityRecordInfo.cs
- EmptyEnumerator.cs
- ListViewDeletedEventArgs.cs
- CompilerState.cs
- bidPrivateBase.cs
- URLMembershipCondition.cs
- ComponentEditorPage.cs
- MsdtcClusterUtils.cs
- Attachment.cs
- CompositeKey.cs
- wgx_commands.cs
- MethodImplAttribute.cs
- WindowsNonControl.cs
- FixedSOMGroup.cs
- Transaction.cs
- objectquery_tresulttype.cs
- DoubleUtil.cs
- OleDbFactory.cs
- Multiply.cs
- CharacterHit.cs
- login.cs
- ContainerUtilities.cs
- APCustomTypeDescriptor.cs
- SqlError.cs
- EllipseGeometry.cs
- View.cs
- BaseServiceProvider.cs
- XmlWhitespace.cs
- Cursors.cs
- LambdaCompiler.Generated.cs
- DetailsViewModeEventArgs.cs
- RtfControls.cs
- RayHitTestParameters.cs
- SqlTriggerAttribute.cs
- URLMembershipCondition.cs
- TemplatePagerField.cs
- InternalCache.cs
- DesignerActionTextItem.cs
- GcSettings.cs
- DataSourceXmlSerializer.cs
- BypassElementCollection.cs
- Command.cs
- LinqDataSourceView.cs
- XmlExtensionFunction.cs
- SqlCachedBuffer.cs
- HtmlButton.cs
- FontConverter.cs
- StructuredProperty.cs
- CodeIterationStatement.cs
- TextSpanModifier.cs
- ConfigWriter.cs
- ServiceReference.cs
- XmlAnyElementAttribute.cs
- DbProviderFactory.cs
- VirtualDirectoryMapping.cs
- PrivateUnsafeNativeCompoundFileMethods.cs
- MarkupCompilePass1.cs
- TemplateControlParser.cs
- SQLMembershipProvider.cs
- LayoutTable.cs
- SystemIPGlobalStatistics.cs
- VerticalAlignConverter.cs
- securitycriticaldataClass.cs
- Oci.cs
- ModuleBuilderData.cs
- XamlReaderConstants.cs
- HelpPage.cs
- SplitContainer.cs
- ColorConverter.cs
- RectIndependentAnimationStorage.cs
- Deflater.cs
- OdbcConnection.cs
- IPipelineRuntime.cs
- _IPv6Address.cs
- EventLogPermission.cs
- AttachedPropertyMethodSelector.cs
- SQLByte.cs
- XPathSelectionIterator.cs
- C14NUtil.cs
- IERequestCache.cs
- KeyboardEventArgs.cs
- SQLDateTimeStorage.cs
- CommonObjectSecurity.cs
- ApplyTemplatesAction.cs
- SymbolType.cs
- Size3DConverter.cs
- PropertyMapper.cs
- UnsafeNativeMethods.cs
- OleStrCAMarshaler.cs
- MetadataCache.cs
- MouseCaptureWithinProperty.cs
- ServiceProviders.cs
- ToolStripDesigner.cs
- XmlDictionaryReader.cs
- ConfigurationManagerInternalFactory.cs
- CqlLexerHelpers.cs
- SqlRecordBuffer.cs
- VisualTarget.cs
- WinFormsSecurity.cs
- MasterPageParser.cs