Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / Orcas / SP / 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
- NonClientArea.cs
- SchemaDeclBase.cs
- ByteStack.cs
- ManifestResourceInfo.cs
- WinEventTracker.cs
- HitTestParameters3D.cs
- FormConverter.cs
- BitmapEffectvisualstate.cs
- SerializationInfoEnumerator.cs
- ServicePointManager.cs
- SHA384Managed.cs
- ClaimSet.cs
- TrustManagerPromptUI.cs
- StyleXamlParser.cs
- HostVisual.cs
- RowToParametersTransformer.cs
- UnSafeCharBuffer.cs
- QueryPageSettingsEventArgs.cs
- RoleGroupCollection.cs
- Form.cs
- MailAddressCollection.cs
- Timeline.cs
- WebCategoryAttribute.cs
- SpeechSeg.cs
- RuleDefinitions.cs
- MemberMemberBinding.cs
- BooleanAnimationUsingKeyFrames.cs
- ExtendedProperty.cs
- WizardPanelChangingEventArgs.cs
- CodeGen.cs
- EnumType.cs
- ServiceOperationHelpers.cs
- __ComObject.cs
- ProgramNode.cs
- PageCache.cs
- LinqMaximalSubtreeNominator.cs
- DataGridViewCell.cs
- WindowsRichEditRange.cs
- StretchValidation.cs
- HttpCookie.cs
- UIElement3D.cs
- DataGridViewCellEventArgs.cs
- DragEvent.cs
- AssemblyName.cs
- RewritingSimplifier.cs
- CreatingCookieEventArgs.cs
- GroupBox.cs
- DataSysAttribute.cs
- DataTemplate.cs
- ScrollableControl.cs
- ContactManager.cs
- AuthorizationRule.cs
- DependencyObject.cs
- XmlUtf8RawTextWriter.cs
- StandardCommands.cs
- DataPagerField.cs
- ValidationPropertyAttribute.cs
- DocumentPaginator.cs
- ZipIOLocalFileDataDescriptor.cs
- OpenFileDialog.cs
- IntSecurity.cs
- IRCollection.cs
- SpecialNameAttribute.cs
- Material.cs
- WebPartHelpVerb.cs
- MultiSelector.cs
- StringArrayConverter.cs
- GenerateTemporaryTargetAssembly.cs
- DataGridRowEventArgs.cs
- WebPartTransformerCollection.cs
- _ConnectOverlappedAsyncResult.cs
- ChannelParameterCollection.cs
- BinaryFormatter.cs
- Span.cs
- SHA256Managed.cs
- CheckBoxList.cs
- WindowsSlider.cs
- Block.cs
- TableItemStyle.cs
- DataDocumentXPathNavigator.cs
- AbstractSvcMapFileLoader.cs
- CodeStatement.cs
- DataGridRelationshipRow.cs
- MobileTextWriter.cs
- ActivityStateRecord.cs
- SoundPlayerAction.cs
- ClientSideQueueItem.cs
- PanelStyle.cs
- RightsManagementPermission.cs
- ComboBox.cs
- webbrowsersite.cs
- MultipartIdentifier.cs
- DateTimeConverter2.cs
- TextMarkerSource.cs
- ConnectionInterfaceCollection.cs
- OdbcCommand.cs
- QuaternionValueSerializer.cs
- InputLangChangeEvent.cs
- EventLogQuery.cs
- Path.cs