Code:
/ 4.0 / 4.0 / untmp / 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.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- AuthenticodeSignatureInformation.cs
- MergePropertyDescriptor.cs
- Int32Collection.cs
- FlowLayoutPanel.cs
- LicenseProviderAttribute.cs
- XXXInfos.cs
- SafeCertificateStore.cs
- TextBlockAutomationPeer.cs
- CapabilitiesSection.cs
- SignatureToken.cs
- ZipIOExtraField.cs
- SemanticResultKey.cs
- __Error.cs
- UserNamePasswordValidator.cs
- MembershipUser.cs
- TextView.cs
- SigningCredentials.cs
- UrlAuthorizationModule.cs
- pingexception.cs
- MetafileHeaderEmf.cs
- EntityReference.cs
- ThemeableAttribute.cs
- XmlCountingReader.cs
- XPathItem.cs
- PointValueSerializer.cs
- sapiproxy.cs
- SqlRewriteScalarSubqueries.cs
- ExpandSegmentCollection.cs
- DrawingImage.cs
- AccessDataSource.cs
- SecUtil.cs
- PerformanceCounterPermission.cs
- ProfileEventArgs.cs
- XmlObjectSerializerWriteContext.cs
- LockCookie.cs
- CodeSnippetTypeMember.cs
- RequestCachePolicy.cs
- MaterialCollection.cs
- QuotedPairReader.cs
- OutOfMemoryException.cs
- ImageCollectionEditor.cs
- ResourceIDHelper.cs
- BatchServiceHost.cs
- DBAsyncResult.cs
- TypeConverters.cs
- SqlDataSourceStatusEventArgs.cs
- COM2ColorConverter.cs
- SettingsAttributeDictionary.cs
- httpserverutility.cs
- DataViewSetting.cs
- BitmapEffectState.cs
- DBSchemaRow.cs
- IntermediatePolicyValidator.cs
- ErrorHandler.cs
- TextElementEditingBehaviorAttribute.cs
- Pair.cs
- AutoGeneratedField.cs
- WebServiceResponse.cs
- XmlWrappingReader.cs
- ArraySegment.cs
- DynamicVirtualDiscoSearcher.cs
- CoreSwitches.cs
- DebugHandleTracker.cs
- Triplet.cs
- DocumentViewerBaseAutomationPeer.cs
- ProviderConnectionPoint.cs
- HitTestParameters3D.cs
- SiteOfOriginPart.cs
- CellTreeNodeVisitors.cs
- ComboBox.cs
- PersistenceTypeAttribute.cs
- ScriptingSectionGroup.cs
- PersistenceMetadataNamespace.cs
- DelegatedStream.cs
- TraceHandler.cs
- QilBinary.cs
- EmbeddedMailObject.cs
- AsyncStreamReader.cs
- SoapCodeExporter.cs
- AddInContractAttribute.cs
- Color.cs
- EmptyCollection.cs
- RunWorkerCompletedEventArgs.cs
- PaintValueEventArgs.cs
- DataTableExtensions.cs
- EntityConnectionStringBuilderItem.cs
- OracleConnectionFactory.cs
- SelectQueryOperator.cs
- OutputWindow.cs
- HandleCollector.cs
- ExpressionStringBuilder.cs
- DES.cs
- MissingMethodException.cs
- AffineTransform3D.cs
- EncryptedData.cs
- TimeSpanValidatorAttribute.cs
- SqlDataSourceWizardForm.cs
- MSG.cs
- ClientUtils.cs
- storepermission.cs