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
- RequestNavigateEventArgs.cs
- RefType.cs
- Hash.cs
- UpdateCommand.cs
- ICollection.cs
- MethodAccessException.cs
- EntityExpressionVisitor.cs
- TransformValueSerializer.cs
- NameObjectCollectionBase.cs
- ObjectPersistData.cs
- ToolStripOverflowButton.cs
- TemplateComponentConnector.cs
- SymbolDocumentGenerator.cs
- MarshalByValueComponent.cs
- SoapReflectionImporter.cs
- IUnknownConstantAttribute.cs
- XmlSchemaObject.cs
- TreeViewTemplateSelector.cs
- EventLogPermission.cs
- HtmlImage.cs
- EnumBuilder.cs
- HotSpot.cs
- Catch.cs
- ListControl.cs
- DataGridClipboardCellContent.cs
- LocalizationComments.cs
- NotifyParentPropertyAttribute.cs
- GetPageNumberCompletedEventArgs.cs
- Duration.cs
- Matrix.cs
- ScriptComponentDescriptor.cs
- EventSourceCreationData.cs
- ObjectDisposedException.cs
- SplitterPanel.cs
- EnumDataContract.cs
- DataGridRow.cs
- RequestNavigateEventArgs.cs
- GeneralTransform3DTo2D.cs
- PresentationSource.cs
- DBDataPermission.cs
- PackWebRequestFactory.cs
- LogicalChannel.cs
- ViewManager.cs
- EventMappingSettingsCollection.cs
- LoginStatusDesigner.cs
- Material.cs
- SqlColumnizer.cs
- SqlBulkCopyColumnMappingCollection.cs
- ClientReliableChannelBinder.cs
- TreeNodeCollection.cs
- SocketInformation.cs
- ArrayListCollectionBase.cs
- HtmlValidatorAdapter.cs
- BamlRecords.cs
- HtmlButton.cs
- ProxyWebPartManager.cs
- WebMethodAttribute.cs
- BasicExpressionVisitor.cs
- VectorAnimationBase.cs
- AQNBuilder.cs
- QuestionEventArgs.cs
- DiscreteKeyFrames.cs
- DayRenderEvent.cs
- UrlMappingsSection.cs
- SaveFileDialog.cs
- CellConstantDomain.cs
- DynamicDataManager.cs
- SqlTypeConverter.cs
- MaterialCollection.cs
- RegexRunnerFactory.cs
- ResizeGrip.cs
- HttpStaticObjectsCollectionBase.cs
- BuildProviderAppliesToAttribute.cs
- DoubleAnimationUsingPath.cs
- SharedPersonalizationStateInfo.cs
- ParagraphVisual.cs
- DependentTransaction.cs
- X509ThumbprintKeyIdentifierClause.cs
- ProcessHostConfigUtils.cs
- AutomationPropertyInfo.cs
- FormCollection.cs
- PropVariant.cs
- SqlBinder.cs
- Crc32.cs
- GridPatternIdentifiers.cs
- FormattedText.cs
- XmlBinaryWriter.cs
- SymbolType.cs
- EventInfo.cs
- DataServiceQueryOfT.cs
- SafeNativeMethods.cs
- RepeatInfo.cs
- ResourceManager.cs
- IPAddress.cs
- CurrentChangedEventManager.cs
- ToolStripInSituService.cs
- ObjectConverter.cs
- WorkflowServiceAttributes.cs
- ExclusiveTcpTransportManager.cs
- TextBounds.cs