protected sealed override HWND BuildWindowCore(HWND hwndParent) { HwndSourceParameters hwndSourceParameters = new HwndSourceParameters(); hwndSourceParameters.WindowStyle = (int)(WS.VISIBLE | WS.CHILD | WS.CLIPSIBLINGS | WS.CLIPCHILDREN); //hwndSourceParameters.ExtendedWindowStyle = (int)(WS_EX.NOACTIVATE); hwndSourceParameters.ParentWindow = hwndParent.DangerousGetHandle(); _hwndSource = new HwndSource(hwndSourceParameters); _hwndSource.SizeToContent = SizeToContent.Manual; // TODO: make this an option // On Vista, or when Win7 uses vista-blit, DX content is not // available via BitBlit or PrintWindow? If WPF is using hardware // acceleration, anything it renders won't be available either. // One workaround is to force WPF to use software rendering. Of // course, this is only a partial workaround since other content // like XNA or D2D won't work either. //_hwndSource.CompositionTarget.RenderMode = RenderMode.SoftwareOnly; // Set the root visual of the HwndSource to an instance of // HwndSourceHostRoot. Hook it up as a logical child if // we are on the same thread. HwndSourceHostRoot root = new HwndSourceHostRoot(); _hwndSource.RootVisual = root; root.OnMeasure += OnRootMeasured; AddLogicalChild(_hwndSource.RootVisual); SetRootVisual(Child); return(new HWND(_hwndSource.Handle)); }
/// <summary> /// Determine the desired size of this element within the /// specified constraints. /// </summary> protected override Size MeasureOverride(Size constraint) { if (_hwndSource != null && _hwndSource.RootVisual != null) { HwndSourceHostRoot root = (HwndSourceHostRoot)_hwndSource.RootVisual; // We are a simple pass-through element. root.Measure(constraint); return(root.DesiredSize); } else { // We don't have a child yet. return(new Size()); } }
// Delegate IKeyboardInputSink calls to the hosted HwndSource. protected sealed override bool TranslateAcceleratorCore(ref MSG msg, ModifierKeys modifiers) { if (_hwndSource != null) { HwndSourceHostRoot root = (HwndSourceHostRoot)_hwndSource.RootVisual; Debug.Assert(root.IsLogicalParentEnabled); root.IsLogicalParentEnabled = false; try { return(((IKeyboardInputSink)_hwndSource).TranslateAccelerator(ref msg, modifiers)); } finally { root.IsLogicalParentEnabled = true; } } else { return(base.TranslateAcceleratorCore(ref msg, modifiers)); } }
private object SetRootVisual(object arg) { Debug.Assert(_hwndSource != null); FrameworkElement child = arg as FrameworkElement; if (child == null && arg is Uri) { child = (FrameworkElement)Application.LoadComponent((Uri)arg); } HwndSourceHostRoot root = (HwndSourceHostRoot)_hwndSource.RootVisual; root.Child = child; // Invalidate measure on this HwndHost so that we can remeasure // ourselves to our content. InvalidateMeasure(); return(null); }
protected sealed override HWND BuildWindowOverride(HWND hwndParent) { HwndSourceParameters hwndSourceParameters = new HwndSourceParameters(); hwndSourceParameters.WindowStyle = (int)(WS.VISIBLE | WS.CHILD | WS.CLIPSIBLINGS | WS.CLIPCHILDREN); hwndSourceParameters.ParentWindow = hwndParent.DangerousGetHandle(); _hwndSource = new HwndSource(hwndSourceParameters); _hwndSource.SizeToContent = SizeToContent.Manual; // Set the root visual of the HwndSource to an instance of // HwndSourceHostRoot. Hook it up as a logical child if // we are on the same thread. HwndSourceHostRoot root = new HwndSourceHostRoot(); _hwndSource.RootVisual = root; root.OnMeasure += OnRootMeasured; AddLogicalChild(_hwndSource.RootVisual); SetRootVisual(Child); return(new HWND(_hwndSource.Handle)); }
protected override sealed HWND BuildWindowOverride(HWND hwndParent) { HwndSourceParameters hwndSourceParameters = new HwndSourceParameters(); hwndSourceParameters.WindowStyle = (int)(WS.VISIBLE | WS.CHILD | WS.CLIPSIBLINGS | WS.CLIPCHILDREN); hwndSourceParameters.ParentWindow = hwndParent.DangerousGetHandle(); _hwndSource = new HwndSource(hwndSourceParameters); _hwndSource.SizeToContent = SizeToContent.Manual; // Set the root visual of the HwndSource to an instance of // HwndSourceHostRoot. Hook it up as a logical child if // we are on the same thread. HwndSourceHostRoot root = new HwndSourceHostRoot(); _hwndSource.RootVisual = root; root.OnMeasure += OnRootMeasured; AddLogicalChild(_hwndSource.RootVisual); SetRootVisual(Child); return new HWND(_hwndSource.Handle); }
protected override sealed HWND BuildWindowCore(HWND hwndParent) { HwndSourceParameters hwndSourceParameters = new HwndSourceParameters(); hwndSourceParameters.WindowStyle = (int)(WS.VISIBLE | WS.CHILD | WS.CLIPSIBLINGS | WS.CLIPCHILDREN); //hwndSourceParameters.ExtendedWindowStyle = (int)(WS_EX.NOACTIVATE); hwndSourceParameters.ParentWindow = hwndParent.DangerousGetHandle(); _hwndSource = new HwndSource(hwndSourceParameters); _hwndSource.SizeToContent = SizeToContent.Manual; // TODO: make this an option // On Vista, or when Win7 uses vista-blit, DX content is not // available via BitBlit or PrintWindow? If WPF is using hardware // acceleration, anything it renders won't be available either. // One workaround is to force WPF to use software rendering. Of // course, this is only a partial workaround since other content // like XNA or D2D won't work either. //_hwndSource.CompositionTarget.RenderMode = RenderMode.SoftwareOnly; // Set the root visual of the HwndSource to an instance of // HwndSourceHostRoot. Hook it up as a logical child if // we are on the same thread. HwndSourceHostRoot root = new HwndSourceHostRoot(); _hwndSource.RootVisual = root; root.OnMeasure += OnRootMeasured; AddLogicalChild(_hwndSource.RootVisual); SetRootVisual(Child); return new HWND(_hwndSource.Handle); }