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
- XamlStyleSerializer.cs
- Int16Converter.cs
- Int16Animation.cs
- TransformerTypeCollection.cs
- XmlSerializableWriter.cs
- DbProviderServices.cs
- UntrustedRecipientException.cs
- GcSettings.cs
- SectionVisual.cs
- ParallelActivityDesigner.cs
- KeySpline.cs
- DocumentViewerHelper.cs
- ManipulationLogic.cs
- securitymgrsite.cs
- SurrogateSelector.cs
- AutomationIdentifierGuids.cs
- XmlTextReader.cs
- WebFaultClientMessageInspector.cs
- RegisteredDisposeScript.cs
- ScrollViewer.cs
- ValueConversionAttribute.cs
- VectorConverter.cs
- DataServiceProcessingPipeline.cs
- BinaryObjectReader.cs
- PathStreamGeometryContext.cs
- UpdateRecord.cs
- assertwrapper.cs
- ManagementClass.cs
- RadioButtonBaseAdapter.cs
- XmlIlGenerator.cs
- BitmapEffectInput.cs
- DatePickerAutomationPeer.cs
- WebPartEditorOkVerb.cs
- IPipelineRuntime.cs
- DeclaredTypeElementCollection.cs
- XmlObjectSerializerWriteContextComplex.cs
- X509SecurityToken.cs
- WebPartAddingEventArgs.cs
- FormsAuthenticationModule.cs
- GridViewHeaderRowPresenter.cs
- columnmapfactory.cs
- OleDbConnectionFactory.cs
- QueryOperationResponseOfT.cs
- WebPartMenuStyle.cs
- LayoutSettings.cs
- EmptyQuery.cs
- WebPartConnectionsCancelVerb.cs
- DataGridLengthConverter.cs
- TableColumn.cs
- XmlQueryTypeFactory.cs
- Literal.cs
- ThemeableAttribute.cs
- PasswordBoxAutomationPeer.cs
- IListConverters.cs
- MenuScrollingVisibilityConverter.cs
- XmlChildNodes.cs
- ListBindingConverter.cs
- AttachmentCollection.cs
- HttpListenerRequest.cs
- Inline.cs
- CommentEmitter.cs
- RNGCryptoServiceProvider.cs
- ResourceProviderFactory.cs
- isolationinterop.cs
- GenericIdentity.cs
- RegexNode.cs
- CqlErrorHelper.cs
- LineGeometry.cs
- SqlBulkCopy.cs
- InternalTypeHelper.cs
- View.cs
- HtmlForm.cs
- XamlTemplateSerializer.cs
- TemplatedWizardStep.cs
- FragmentQueryKB.cs
- _NegotiateClient.cs
- XmlConverter.cs
- Single.cs
- SortDescriptionCollection.cs
- FieldNameLookup.cs
- RegistryExceptionHelper.cs
- ContextItem.cs
- LinkGrep.cs
- IPipelineRuntime.cs
- CapabilitiesUse.cs
- StreamBodyWriter.cs
- CodeDirectionExpression.cs
- ImplicitInputBrush.cs
- RoleServiceManager.cs
- SplineKeyFrames.cs
- Executor.cs
- SqlInternalConnection.cs
- ClientTarget.cs
- ListBindableAttribute.cs
- SqlProfileProvider.cs
- SqlConnectionPoolProviderInfo.cs
- ServiceOperation.cs
- ClientConfigPaths.cs
- PropertyDescriptorComparer.cs
- EntityType.cs