示例#1
0
        /// <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(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(ActualWidth, ActualHeight));

                var props = new NativeMethods.ThumbnailProperties
                {
                    Visible     = true,
                    Destination = new 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)),
                    Flags = NativeMethods.ThumbnailFlags.Visible | NativeMethods.ThumbnailFlags.RectDestination
                };
                NativeMethods.DwmUpdateThumbnailProperties(_thumb, ref props);
            }
        }
示例#2
0
        /// <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)PresentationSource.FromVisual(this);

                // if we have one, we can attempt to register the thumbnail
                if (_target != null)
                {
                    int result = NativeMethods.DwmRegisterThumbnail(_target.Handle, source, out _thumb);
                    if (0 == result)
                    {
                        var props = new NativeMethods.ThumbnailProperties
                        {
                            Visible        = false,
                            ClientAreaOnly = ClientAreaOnly,
                            Opacity        = (byte)(255 * Opacity),
                            Flags          = NativeMethods.ThumbnailFlags.Visible | NativeMethods.ThumbnailFlags.SourceClientAreaOnly
                                             | NativeMethods.ThumbnailFlags.Opacity
                        };
                        NativeMethods.DwmUpdateThumbnailProperties(_thumb, ref props);
                    }
                }
            }
        }
示例#3
0
 /// <summary>Updates the thumbnail
 /// </summary>
 private void UpdateThumbnail()
 {
     if (IntPtr.Zero != _thumb)
     {
         var props = new NativeMethods.ThumbnailProperties
         {
             ClientAreaOnly = ClientAreaOnly,
             Opacity        = (byte)(255 * Opacity),
             Flags          = NativeMethods.ThumbnailFlags.SourceClientAreaOnly | NativeMethods.ThumbnailFlags.Opacity
         };
         NativeMethods.DwmUpdateThumbnailProperties(_thumb, ref props);
     }
 }
示例#4
0
 /// <summary>Updates the thumbnail
 /// </summary>
 private void UpdateThumbnail()
 {
    if (IntPtr.Zero != thumb)
    {
       NativeMethods.ThumbnailProperties props = new NativeMethods.ThumbnailProperties();
       props.ClientAreaOnly = this.ClientAreaOnly;
       props.Opacity = (byte)(255 * this.Opacity);
       props.Flags = NativeMethods.ThumbnailFlags.SourceClientAreaOnly | NativeMethods.ThumbnailFlags.Opacity;
       NativeMethods.DwmUpdateThumbnailProperties(thumb, ref props);
    }
 }
示例#5
0
      /// <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));

            NativeMethods.ThumbnailProperties props = new NativeMethods.ThumbnailProperties();
            props.Visible = true;
            props.Destination = new NativeMethods.ApiRect(
                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 = NativeMethods.ThumbnailFlags.Visible | NativeMethods.ThumbnailFlags.RectDestination;
            NativeMethods.DwmUpdateThumbnailProperties(thumb, ref props);
         }
      }
示例#6
0
      /// <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
            target = (HwndSource)HwndSource.FromVisual(this);

            // if we have one, we can attempt to register the thumbnail
            if (target != null && 0 == NativeMethods.DwmRegisterThumbnail(target.Handle, source, out this.thumb))
            {
               NativeMethods.ThumbnailProperties props = new NativeMethods.ThumbnailProperties();
               props.Visible = false;
               props.ClientAreaOnly = this.ClientAreaOnly;
               props.Opacity = (byte)(255 * this.Opacity);
               props.Flags = NativeMethods.ThumbnailFlags.Visible | NativeMethods.ThumbnailFlags.SourceClientAreaOnly
                   | NativeMethods.ThumbnailFlags.Opacity;
               NativeMethods.DwmUpdateThumbnailProperties(thumb, ref props);
            }
         }
      }