//+--------------------------------------------------------------------- // // Internal Methods // //---------------------------------------------------------------------- #region Internal Methods /// <summary> /// Sets the owner MediaContext and creates the notification window. /// </summary> internal MediaContextNotificationWindow(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 <HwndWrapper>(hwndNotification); _hwndNotification.Value.AddHook(_hwndNotificationHook); _isDisposed = false; // // On Vista, we need to know when the Magnifier goes on and off // in order to switch to and from software rendering because the // Vista Magnifier cannot magnify D3D content. To receive the // window message informing us of this, we must tell the DWM // we are MIL content. // // The Win7 Magnifier can magnify D3D content so it's not an // issue there. In fact, Win7 doesn't even send the WM. // // If the DWM is not running, this call will result in NoOp. // ChangeWindowMessageFilter(s_dwmRedirectionEnvironmentChanged, 1 /* MSGFLT_ADD */); MS.Internal.HRESULT.Check(MilContent_AttachToHwnd(_hwndNotification.Value.Handle)); }
///<summary> /// Construtor that takes a ActionQueue that it will be used to pull all the action /// that are going to be executed ///</summary> internal Win32AsyncActionsManager(ActionsQueue queue) { if (queue == null) { throw new ArgumentNullException("the ActionQueue cannot be null"); } if (queue.AmountTestCases <= 0) { throw new InvalidOperationException("The queue doesn't have any items"); } _queue = queue; _hwnd = new HwndWrapper(0, 0, 0, 0, 0, 0, 0, "", NativeConstants.HWND_MESSAGE, null); _hwndWrapperHook = new HwndWrapperHook(_hwndHook); _hwnd.AddHook(_hwndWrapperHook); }
public virtual bool?ShowDialog() { this.CheckPermissionsToShowDialog(); if (!Environment.UserInteractive) { throw new InvalidOperationException(SR.Get("CantShowModalOnNonInteractive")); } IntPtr intPtr = UnsafeNativeMethods.GetActiveWindow(); if (intPtr == IntPtr.Zero && Application.Current != null) { intPtr = Application.Current.ParkingHwnd; } HwndWrapper hwndWrapper = null; bool? result; try { if (intPtr == IntPtr.Zero) { hwndWrapper = new HwndWrapper(0, 0, 0, 0, 0, 0, 0, "", IntPtr.Zero, null); intPtr = hwndWrapper.Handle; } this._hwndOwnerWindow = intPtr; try { ComponentDispatcher.CriticalPushModal(); result = new bool?(this.RunDialog(intPtr)); } finally { ComponentDispatcher.CriticalPopModal(); } } finally { if (hwndWrapper != null) { hwndWrapper.Dispose(); } } return(result); }
public virtual Nullable <bool> ShowDialog() { CheckPermissionsToShowDialog(); // Don't allow file dialogs to be shown if not in interactive mode // (for example, if we're running as a service) if (!Environment.UserInteractive) { throw new InvalidOperationException(SR.Get(SRID.CantShowModalOnNonInteractive)); } // Call GetActiveWindow to retrieve the window handle to the active window // attached to the calling thread's message queue. We'll set the owner of // the common dialog to this handle. IntPtr hwndOwner = UnsafeNativeMethods.GetActiveWindow(); if (hwndOwner == IntPtr.Zero) { // No active window, so we'll use the parking window as the owner, // if its available. if (Application.Current != null) { hwndOwner = Application.Current.ParkingHwnd; } } HwndWrapper tempParentHwnd = null; try { // No active window and application wasn't available or didn't have // a ParkingHwnd, we create a hidden parent window for the dialog to // prevent breaking UIAutomation. if (hwndOwner == IntPtr.Zero) { tempParentHwnd = new HwndWrapper(0, 0, 0, 0, 0, 0, 0, "", IntPtr.Zero, null); hwndOwner = tempParentHwnd.Handle; } // Store the handle of the owner window inside our class so we can use it // to center the dialog later. _hwndOwnerWindow = hwndOwner; // Signal that this thread is going to go modal. try { ComponentDispatcher.CriticalPushModal(); return(RunDialog(hwndOwner)); } finally { ComponentDispatcher.CriticalPopModal(); } } finally { if (tempParentHwnd != null) { tempParentHwnd.Dispose(); } } }
private void BuildOrReparentWindow() { this.DemandIfUntrusted(); if (this._isBuildingWindow || this._isDisposed) { return; } this._isBuildingWindow = true; IntPtr intPtr = IntPtr.Zero; PresentationSource presentationSource = PresentationSource.CriticalFromVisual(this, false); if (presentationSource != null) { HwndSource hwndSource = presentationSource as HwndSource; if (hwndSource != null) { intPtr = hwndSource.CriticalHandle; } } else { PresentationSource presentationSource2 = PresentationSource.CriticalFromVisual(this, true); if (presentationSource2 != null && TraceHwndHost.IsEnabled) { TraceHwndHost.Trace(TraceEventType.Warning, TraceHwndHost.HwndHostIn3D); } } try { if (intPtr != IntPtr.Zero) { if (this._hwnd.Handle == IntPtr.Zero) { this.BuildWindow(new HandleRef(null, intPtr)); base.LayoutUpdated += this._handlerLayoutUpdated; base.IsEnabledChanged += this._handlerEnabledChanged; base.IsVisibleChanged += this._handlerVisibleChanged; } else if (intPtr != UnsafeNativeMethods.GetParent(this._hwnd)) { UnsafeNativeMethods.SetParent(this._hwnd, new HandleRef(null, intPtr)); } } else { IntPtr value = (!FrameworkAppContextSwitches.DisableDevDiv1035544) ? this.Handle : this._hwnd.Handle; if (value != IntPtr.Zero) { HwndWrapper dpiAwarenessCompatibleNotificationWindow = SystemResources.GetDpiAwarenessCompatibleNotificationWindow(this._hwnd); if (dpiAwarenessCompatibleNotificationWindow != null) { UnsafeNativeMethods.SetParent(this._hwnd, new HandleRef(null, dpiAwarenessCompatibleNotificationWindow.Handle)); SystemResources.DelayHwndShutdown(); } else { Trace.WriteLineIf(dpiAwarenessCompatibleNotificationWindow == null, string.Format("- Warning - Notification Window is null\n{0}", new StackTrace(true).ToString())); } } } } finally { this._isBuildingWindow = false; } }