/// <summary>Updates the thumbnail /// </summary> private void UpdateThumbnail() { if (IntPtr.Zero != _thumb) { Win32.NativeMethods.ThumbnailProperties props = new Win32.NativeMethods.ThumbnailProperties(); props.ClientAreaOnly = this.ClientAreaOnly; props.Opacity = (byte)(255 * this.Opacity); props.Flags = Win32.NativeMethods.ThumbnailFlags.SourceClientAreaOnly | Win32.NativeMethods.ThumbnailFlags.Opacity; Win32.NativeMethods.DwmUpdateThumbnailProperties(_thumb, ref props); } }
/// <summary>Handles the LayoutUpdated event of the Thumbnail image /// Actually, we really just ask Windows to paint us at our new size... /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> private void Thumbnail_LayoutUpdated(object sender, EventArgs e) { if (IntPtr.Zero.Equals(_thumb)) { InitialiseThumbnail(this.WindowSource); } else if (null != _target) { if (!_target.RootVisual.IsAncestorOf(this)) { //we are no longer in the visual tree ReleaseThumbnail(); return; } GeneralTransform transform = TransformToAncestor(_target.RootVisual); Point a = transform.Transform(new Point(0, 0)); Point b = transform.Transform(new Point(this.ActualWidth, this.ActualHeight)); Win32.NativeMethods.ThumbnailProperties props = new Win32.NativeMethods.ThumbnailProperties(); props.Visible = true; props.Destination = new Win32.NativeMethods.RECT( 2 + (int)Math.Ceiling(a.X), 2 + (int)Math.Ceiling(a.Y), -2 + (int)Math.Ceiling(b.X), -2 + (int)Math.Ceiling(b.Y)); props.Flags = Win32.NativeMethods.ThumbnailFlags.Visible | Win32.NativeMethods.ThumbnailFlags.RectDestination; Win32.NativeMethods.DwmUpdateThumbnailProperties(_thumb, ref props); } }
/// <summary>Initialises the thumbnail image /// </summary> /// <param name="source">The source.</param> private void InitialiseThumbnail(IntPtr source) { if (IntPtr.Zero != _thumb) { // release the old thumbnail ReleaseThumbnail(); } if (IntPtr.Zero != source) { // find our parent hwnd // [System.Windows.Interop.HwndSource]::FromHwnd( [Diagnostics.Process]::GetCurrentProcess().MainWindowHandle ) //target = HwndSource.FromHwnd(System.Diagnostics.Process.GetCurrentProcess().MainWindowHandle); _target = (HwndSource)HwndSource.FromVisual((UIElement)this); // if we have one, we can attempt to register the thumbnail if (_target != null ) { int result = Win32.NativeMethods.DwmRegisterThumbnail(_target.Handle, source, out this._thumb); if( 0 == result) { Win32.NativeMethods.ThumbnailProperties props = new Win32.NativeMethods.ThumbnailProperties(); props.Visible = false; props.ClientAreaOnly = this.ClientAreaOnly; props.Opacity = (byte)(255 * this.Opacity); props.Flags = Win32.NativeMethods.ThumbnailFlags.Visible | Win32.NativeMethods.ThumbnailFlags.SourceClientAreaOnly | Win32.NativeMethods.ThumbnailFlags.Opacity; Win32.NativeMethods.DwmUpdateThumbnailProperties(_thumb, ref props); } } } }