Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / Orcas / QFE / wpf / src / Core / CSharp / System / Windows / Media / MediaContextNotificationWindow.cs / 1 / MediaContextNotificationWindow.cs
//------------------------------------------------------------------------------
//
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// Description:
// A wrapper for a top-level hidden window that is used to process
// messages broadcasted to top-level windows only (such as DWM's
// WM_DWMCOMPOSITIONCHANGED). If the WPF application doesn't have
// a top-level window (as it is the case for XBAP applications),
// such messages would have been ignored.
//
//-----------------------------------------------------------------------------
using System;
using System.Windows.Threading;
using System.Collections;
using System.Diagnostics;
using System.Windows.Media.Animation;
using System.Windows.Media.Composition;
using Microsoft.Win32;
using Microsoft.Internal;
using MS.Internal;
using MS.Win32;
using System.Security;
using System.Security.Permissions;
using SR=MS.Internal.PresentationCore.SR;
using SRID=MS.Internal.PresentationCore.SRID;
using UnsafeNativeMethods=MS.Win32.PresentationCore.UnsafeNativeMethods.MilCoreApi;
using SafeNativeMethods=MS.Win32.PresentationCore.SafeNativeMethods;
namespace System.Windows.Media
{
///
/// The MediaContextNotificationWindow structure provides its owner
/// MediaContext with the ability to receive and forward window
/// messages broadcasted to top-level windows.
///
internal struct MediaContextNotificationWindow
{
//+---------------------------------------------------------------------
//
// Internal Methods
//
//---------------------------------------------------------------------
#region Internal Methods
///
/// Sets the owner MediaContext and creates the notification window.
///
///
/// Critical - Creates an HwndWrapper and adds a hook.
/// TreatAsSafe: The _hwndNotification window is critical and this function is safe to call
///
[SecurityCritical, SecurityTreatAsSafe]
internal void CreateNotificationWindow(MediaContext ownerMediaContext)
{
// Remember the pointer to the owner MediaContext that we'll forward the broadcasts to.
_ownerMediaContext = ownerMediaContext;
// Create a top-level, invisible window so we can get the WM_DWMCOMPOSITIONCHANGED
// and other DWM notifications that are broadcasted to top-level windows only.
HwndWrapper hwndNotification;
hwndNotification = new HwndWrapper(0, NativeMethods.WS_POPUP, 0, 0, 0, 0, 0, "MediaContextNotificationWindow", IntPtr.Zero, null);
_hwndNotificationHook = new HwndWrapperHook(MessageFilter);
_hwndNotification = new SecurityCriticalDataClass(hwndNotification);
_hwndNotification.Value.AddHook(_hwndNotificationHook);
}
///
/// Critical - Calls dispose on the critical hwnd wrapper.
/// TreatAsSafe: It is safe to dispose the wrapper
///
[SecurityCritical, SecurityTreatAsSafe]
internal void DisposeNotificationWindow()
{
if (_hwndNotification != null)
_hwndNotification.Value.Dispose();
_hwndNotificationHook = null;
_hwndNotification = null;
_ownerMediaContext = null;
}
#endregion Internal Methods
//+----------------------------------------------------------------------
//
// Private Methods
//
//---------------------------------------------------------------------
#region Private Methods
///
/// If any of the interesting broadcast messages is seen, forward them to the owner MediaContext.
///
private IntPtr MessageFilter(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
{
Debug.Assert(_ownerMediaContext != null);
if (msg == NativeMethods.WM_DWMCOMPOSITIONCHANGED)
{
_ownerMediaContext.OnDWMCompositionChanged();
}
return IntPtr.Zero;
}
#endregion Private Methods
//+----------------------------------------------------------------------
//
// Private Fields
//
//----------------------------------------------------------------------
#region Private Fields
// The owner MediaContext
private MediaContext _ownerMediaContext;
// A top-level hidden window.
private SecurityCriticalDataClass _hwndNotification;
// The message filter hook for the top-level hidden window.
private HwndWrapperHook _hwndNotificationHook;
#endregion Private Fields
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//------------------------------------------------------------------------------
//
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// Description:
// A wrapper for a top-level hidden window that is used to process
// messages broadcasted to top-level windows only (such as DWM's
// WM_DWMCOMPOSITIONCHANGED). If the WPF application doesn't have
// a top-level window (as it is the case for XBAP applications),
// such messages would have been ignored.
//
//-----------------------------------------------------------------------------
using System;
using System.Windows.Threading;
using System.Collections;
using System.Diagnostics;
using System.Windows.Media.Animation;
using System.Windows.Media.Composition;
using Microsoft.Win32;
using Microsoft.Internal;
using MS.Internal;
using MS.Win32;
using System.Security;
using System.Security.Permissions;
using SR=MS.Internal.PresentationCore.SR;
using SRID=MS.Internal.PresentationCore.SRID;
using UnsafeNativeMethods=MS.Win32.PresentationCore.UnsafeNativeMethods.MilCoreApi;
using SafeNativeMethods=MS.Win32.PresentationCore.SafeNativeMethods;
namespace System.Windows.Media
{
///
/// The MediaContextNotificationWindow structure provides its owner
/// MediaContext with the ability to receive and forward window
/// messages broadcasted to top-level windows.
///
internal struct MediaContextNotificationWindow
{
//+---------------------------------------------------------------------
//
// Internal Methods
//
//---------------------------------------------------------------------
#region Internal Methods
///
/// Sets the owner MediaContext and creates the notification window.
///
///
/// Critical - Creates an HwndWrapper and adds a hook.
/// TreatAsSafe: The _hwndNotification window is critical and this function is safe to call
///
[SecurityCritical, SecurityTreatAsSafe]
internal void CreateNotificationWindow(MediaContext ownerMediaContext)
{
// Remember the pointer to the owner MediaContext that we'll forward the broadcasts to.
_ownerMediaContext = ownerMediaContext;
// Create a top-level, invisible window so we can get the WM_DWMCOMPOSITIONCHANGED
// and other DWM notifications that are broadcasted to top-level windows only.
HwndWrapper hwndNotification;
hwndNotification = new HwndWrapper(0, NativeMethods.WS_POPUP, 0, 0, 0, 0, 0, "MediaContextNotificationWindow", IntPtr.Zero, null);
_hwndNotificationHook = new HwndWrapperHook(MessageFilter);
_hwndNotification = new SecurityCriticalDataClass(hwndNotification);
_hwndNotification.Value.AddHook(_hwndNotificationHook);
}
///
/// Critical - Calls dispose on the critical hwnd wrapper.
/// TreatAsSafe: It is safe to dispose the wrapper
///
[SecurityCritical, SecurityTreatAsSafe]
internal void DisposeNotificationWindow()
{
if (_hwndNotification != null)
_hwndNotification.Value.Dispose();
_hwndNotificationHook = null;
_hwndNotification = null;
_ownerMediaContext = null;
}
#endregion Internal Methods
//+----------------------------------------------------------------------
//
// Private Methods
//
//---------------------------------------------------------------------
#region Private Methods
///
/// If any of the interesting broadcast messages is seen, forward them to the owner MediaContext.
///
private IntPtr MessageFilter(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
{
Debug.Assert(_ownerMediaContext != null);
if (msg == NativeMethods.WM_DWMCOMPOSITIONCHANGED)
{
_ownerMediaContext.OnDWMCompositionChanged();
}
return IntPtr.Zero;
}
#endregion Private Methods
//+----------------------------------------------------------------------
//
// Private Fields
//
//----------------------------------------------------------------------
#region Private Fields
// The owner MediaContext
private MediaContext _ownerMediaContext;
// A top-level hidden window.
private SecurityCriticalDataClass _hwndNotification;
// The message filter hook for the top-level hidden window.
private HwndWrapperHook _hwndNotificationHook;
#endregion Private Fields
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- JpegBitmapEncoder.cs
- XmlSchema.cs
- cache.cs
- DataContractAttribute.cs
- ParameterCollection.cs
- DataGridSortCommandEventArgs.cs
- ConfigXmlWhitespace.cs
- PropertyTabChangedEvent.cs
- Boolean.cs
- CacheOutputQuery.cs
- InvalidDataException.cs
- WebBaseEventKeyComparer.cs
- JoinTreeSlot.cs
- DocumentPaginator.cs
- Item.cs
- FixedNode.cs
- ConsoleEntryPoint.cs
- DataGridCaption.cs
- CursorConverter.cs
- LogLogRecordEnumerator.cs
- ManualWorkflowSchedulerService.cs
- AutomationEvent.cs
- KeyGestureConverter.cs
- AsyncCodeActivity.cs
- CultureMapper.cs
- BackEase.cs
- EntityRecordInfo.cs
- WrappingXamlSchemaContext.cs
- FormViewUpdatedEventArgs.cs
- InputProviderSite.cs
- BooleanStorage.cs
- Comparer.cs
- BooleanToVisibilityConverter.cs
- CompilerErrorCollection.cs
- XPathNode.cs
- returneventsaver.cs
- RawTextInputReport.cs
- Header.cs
- SqlBulkCopyColumnMapping.cs
- ProxySimple.cs
- TextTrailingCharacterEllipsis.cs
- ToolStripMenuItemCodeDomSerializer.cs
- PagesSection.cs
- ValidatingReaderNodeData.cs
- HtmlContainerControl.cs
- ServiceElement.cs
- SatelliteContractVersionAttribute.cs
- ContentFileHelper.cs
- KeyValueConfigurationElement.cs
- SQLByteStorage.cs
- Deserializer.cs
- ServiceObjectContainer.cs
- TextOptions.cs
- HttpServerVarsCollection.cs
- ProxyHelper.cs
- XmlAtomicValue.cs
- GeneralTransformGroup.cs
- TraceFilter.cs
- ValueTable.cs
- ISFTagAndGuidCache.cs
- __Filters.cs
- AudioFormatConverter.cs
- DataReceivedEventArgs.cs
- UnmanagedMarshal.cs
- TrackingStringDictionary.cs
- ProfileWorkflowElement.cs
- TypeInitializationException.cs
- DateTimeConverter.cs
- DataGridViewColumn.cs
- XmlQueryRuntime.cs
- WSFederationHttpBindingCollectionElement.cs
- HitTestParameters3D.cs
- EncryptedReference.cs
- TreeNodeBinding.cs
- LocalValueEnumerator.cs
- ListQueryResults.cs
- FlowDocumentPageViewerAutomationPeer.cs
- AttachInfo.cs
- SettingsSection.cs
- ViewCellSlot.cs
- ComponentCache.cs
- QueryOptionExpression.cs
- DataRowCollection.cs
- GrammarBuilderBase.cs
- StylusCollection.cs
- KnownTypes.cs
- WpfXamlLoader.cs
- SafeProcessHandle.cs
- SafeThemeHandle.cs
- WebPartActionVerb.cs
- ReflectPropertyDescriptor.cs
- PropertyTab.cs
- SqlTriggerContext.cs
- NoneExcludedImageIndexConverter.cs
- IOThreadScheduler.cs
- Package.cs
- DeclarativeCatalogPart.cs
- DictionaryBase.cs
- DataGridViewLinkCell.cs
- DBConnection.cs