Code:
/ DotNET / DotNET / 8.0 / untmp / WIN_WINDOWS / lh_tools_devdiv_wpf / Windows / wcp / 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.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- DataColumn.cs
- COM2EnumConverter.cs
- FocusManager.cs
- WSDualHttpBindingElement.cs
- CFStream.cs
- XmlWrappingReader.cs
- SafeRightsManagementSessionHandle.cs
- Utils.cs
- Canvas.cs
- DataGridViewColumnHeaderCell.cs
- SqlWebEventProvider.cs
- Soap12ProtocolReflector.cs
- log.cs
- Root.cs
- AssemblyAttributesGoHere.cs
- AutoSizeComboBox.cs
- XmlLoader.cs
- NavigationProperty.cs
- SafeNativeMethodsMilCoreApi.cs
- WorkflowTerminatedException.cs
- DoWorkEventArgs.cs
- PageStatePersister.cs
- DataGridBoolColumn.cs
- TemplateBindingExpressionConverter.cs
- UriGenerator.cs
- FamilyMapCollection.cs
- HttpHandlerAction.cs
- WebScriptMetadataMessage.cs
- InitializerFacet.cs
- XslAst.cs
- HealthMonitoringSection.cs
- SqlWebEventProvider.cs
- DataGridViewAdvancedBorderStyle.cs
- TemplateKey.cs
- IdentityVerifier.cs
- SelectionHighlightInfo.cs
- SQLDouble.cs
- KeyInfo.cs
- xsdvalidator.cs
- NativeMethodsCLR.cs
- SmtpReplyReader.cs
- NativeMethods.cs
- ScriptingAuthenticationServiceSection.cs
- SharedPersonalizationStateInfo.cs
- StringConverter.cs
- NTAccount.cs
- AdobeCFFWrapper.cs
- DataGridCell.cs
- ValidationErrorCollection.cs
- _HeaderInfo.cs
- RectAnimationUsingKeyFrames.cs
- XmlQueryStaticData.cs
- TextTreeTextElementNode.cs
- PageThemeBuildProvider.cs
- IDispatchConstantAttribute.cs
- ObjectConverter.cs
- HtmlHistory.cs
- SaveFileDialogDesigner.cs
- CardSpacePolicyElement.cs
- WindowHideOrCloseTracker.cs
- ViewManagerAttribute.cs
- LowerCaseStringConverter.cs
- ColumnCollectionEditor.cs
- MsmqIntegrationAppDomainProtocolHandler.cs
- PageHandlerFactory.cs
- HttpWebRequest.cs
- DependencyPropertyDescriptor.cs
- UniformGrid.cs
- UnsettableComboBox.cs
- DateTimeOffsetStorage.cs
- PersonalizationEntry.cs
- RTLAwareMessageBox.cs
- ManagedCodeMarkers.cs
- ExceptionUtil.cs
- ColumnCollection.cs
- AssociatedControlConverter.cs
- FontSizeConverter.cs
- EpmCustomContentDeSerializer.cs
- CompiledXpathExpr.cs
- ReferenceConverter.cs
- ZoomPercentageConverter.cs
- DataGridViewRowHeightInfoNeededEventArgs.cs
- DesignerTextViewAdapter.cs
- NavigationWindowAutomationPeer.cs
- RtType.cs
- XamlStream.cs
- ResizeGrip.cs
- AutoGeneratedField.cs
- EmptyEnumerator.cs
- ContentIterators.cs
- DataGridRow.cs
- TextServicesManager.cs
- DSASignatureDeformatter.cs
- Form.cs
- AutomationPropertyInfo.cs
- AnonymousIdentificationSection.cs
- DesignTimeSiteMapProvider.cs
- securitymgrsite.cs
- SamlEvidence.cs
- AnnotationResource.cs