Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / Orcas / NetFXw7 / 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
- TempFiles.cs
- SafeThemeHandle.cs
- SyndicationDeserializer.cs
- ContainerParaClient.cs
- FlowDocumentReader.cs
- FileDataSourceCache.cs
- TypeFieldSchema.cs
- SectionVisual.cs
- SQLRoleProvider.cs
- CRYPTPROTECT_PROMPTSTRUCT.cs
- StatusBarDrawItemEvent.cs
- SecurityHelper.cs
- ArithmeticLiteral.cs
- BitmapSourceSafeMILHandle.cs
- MDIControlStrip.cs
- Timeline.cs
- PipelineDeploymentState.cs
- SerializationObjectManager.cs
- BigInt.cs
- SystemException.cs
- SignatureResourcePool.cs
- RegexCompiler.cs
- SystemColors.cs
- MasterPageCodeDomTreeGenerator.cs
- EncryptedKeyIdentifierClause.cs
- GridViewRowPresenterBase.cs
- EventMap.cs
- AlphabetConverter.cs
- ClassHandlersStore.cs
- TimelineGroup.cs
- GridViewUpdateEventArgs.cs
- TcpChannelFactory.cs
- CfgParser.cs
- OrderByBuilder.cs
- EditBehavior.cs
- SortExpressionBuilder.cs
- EventLogTraceListener.cs
- Expression.cs
- BooleanFunctions.cs
- xmlfixedPageInfo.cs
- DataViewManagerListItemTypeDescriptor.cs
- WebPartCancelEventArgs.cs
- BuildDependencySet.cs
- BulletedList.cs
- AutoResetEvent.cs
- UndoEngine.cs
- ClientTargetCollection.cs
- SystemThemeKey.cs
- PeerTransportSecuritySettings.cs
- RegistryExceptionHelper.cs
- EventDescriptorCollection.cs
- XPathMultyIterator.cs
- CanExecuteRoutedEventArgs.cs
- WebUtil.cs
- WindowsAltTab.cs
- DashStyle.cs
- ListViewGroupItemCollection.cs
- SchemaReference.cs
- CommonDialog.cs
- PerformanceCounterPermission.cs
- TextStore.cs
- ObjectContextServiceProvider.cs
- _ListenerAsyncResult.cs
- OrderByBuilder.cs
- ObjectQuery_EntitySqlExtensions.cs
- SystemGatewayIPAddressInformation.cs
- WriteableOnDemandStream.cs
- HtmlHistory.cs
- ParallelQuery.cs
- TypeConverterHelper.cs
- ActivityDesigner.cs
- ProfileInfo.cs
- MemberExpressionHelper.cs
- DesignerWidgets.cs
- OptimalBreakSession.cs
- ScrollChrome.cs
- LookupNode.cs
- KeyValueConfigurationElement.cs
- IISMapPath.cs
- ViewDesigner.cs
- NominalTypeEliminator.cs
- CatalogZoneAutoFormat.cs
- ContainerVisual.cs
- HttpCachePolicyElement.cs
- KnownAssemblyEntry.cs
- dataSvcMapFileLoader.cs
- GridViewColumnHeader.cs
- ExtenderProvidedPropertyAttribute.cs
- ExpanderAutomationPeer.cs
- WindowsSysHeader.cs
- HttpWriter.cs
- TabControlCancelEvent.cs
- CodeDomComponentSerializationService.cs
- SessionStateItemCollection.cs
- WindowsStreamSecurityBindingElement.cs
- ListViewItem.cs
- DataGridColumn.cs
- X509ThumbprintKeyIdentifierClause.cs
- InkCanvasSelection.cs
- SoapIgnoreAttribute.cs