Example #1
0
 public static extern int DwmUpdateThumbnailProperties(IntPtr hThumb, ref DWM_THUMBNAIL_PROPERTIES props);
        private void ShowThumbnailOnEnter(object sender, EventArgs e)
        {
            ToolStripMenuItem captureWindowItem = sender as ToolStripMenuItem;
            WindowDetails window = captureWindowItem.Tag as WindowDetails;
            parentMenuBounds = captureWindowItem.GetCurrentParent().TopLevelControl.Bounds;
            if (thumbnailForm == null)
            {
                thumbnailForm = new FormWithoutActivation();
                thumbnailForm.ShowInTaskbar = false;
                thumbnailForm.FormBorderStyle = FormBorderStyle.None;
                thumbnailForm.TopMost = false;
                thumbnailForm.Enabled = false;
                if (conf.WindowCaptureMode == WindowCaptureMode.Auto || conf.WindowCaptureMode == WindowCaptureMode.Aero)
                {
                    thumbnailForm.BackColor = Color.FromArgb(255, conf.DWMBackgroundColor.R, conf.DWMBackgroundColor.G, conf.DWMBackgroundColor.B);
                }
                else
                {
                    thumbnailForm.BackColor = Color.White;
                }
            }
            if (thumbnailHandle != IntPtr.Zero)
            {
                DWM.DwmUnregisterThumbnail(thumbnailHandle);
                thumbnailHandle = IntPtr.Zero;
            }
            DWM.DwmRegisterThumbnail(thumbnailForm.Handle, window.Handle, out thumbnailHandle);
            if (thumbnailHandle != IntPtr.Zero)
            {
                Rectangle windowRectangle = window.WindowRectangle;
                int thumbnailHeight = 200;
                int thumbnailWidth = (int)(thumbnailHeight * ((float)windowRectangle.Width / (float)windowRectangle.Height));
                if (thumbnailWidth > parentMenuBounds.Width)
                {
                    thumbnailWidth = parentMenuBounds.Width;
                    thumbnailHeight = (int)(thumbnailWidth * ((float)windowRectangle.Height / (float)windowRectangle.Width));
                }
                thumbnailForm.Width = thumbnailWidth;
                thumbnailForm.Height = thumbnailHeight;
                // Prepare the displaying of the Thumbnail
                DWM_THUMBNAIL_PROPERTIES props = new DWM_THUMBNAIL_PROPERTIES();
                props.Opacity = (byte)255;
                props.Visible = true;
                props.SourceClientAreaOnly = false;
                props.Destination = new RECT(0, 0, thumbnailWidth, thumbnailHeight);
                DWM.DwmUpdateThumbnailProperties(thumbnailHandle, ref props);
                if (!thumbnailForm.Visible)
                {
                    thumbnailForm.Show();
                }
                // Make sure it's on "top"!
                User32.SetWindowPos(thumbnailForm.Handle, captureWindowItem.GetCurrentParent().TopLevelControl.Handle, 0, 0, 0, 0, WindowPos.SWP_NOMOVE | WindowPos.SWP_NOSIZE | WindowPos.SWP_NOACTIVATE);

                // Align to menu
                Rectangle screenBounds = WindowCapture.GetScreenBounds();
                if (screenBounds.Contains(parentMenuBounds.Left, parentMenuBounds.Top - thumbnailHeight))
                {
                    thumbnailForm.Location = new Point(parentMenuBounds.Left + (parentMenuBounds.Width / 2) - (thumbnailWidth / 2), parentMenuBounds.Top - thumbnailHeight);
                }
                else
                {
                    thumbnailForm.Location = new Point(parentMenuBounds.Left + (parentMenuBounds.Width / 2) - (thumbnailWidth / 2), parentMenuBounds.Bottom);
                }
            }
        }
Example #3
0
File: DWM.cs Project: zhk/greenshot
 public static extern int DwmUpdateThumbnailProperties(IntPtr hThumb, ref DWM_THUMBNAIL_PROPERTIES props);
Example #4
0
		/// <summary>
		/// Show the thumbnail of the supplied window above (or under) the parent Control
		/// </summary>
		/// <param name="window">WindowDetails</param>
		/// <param name="parentControl">Control</param>
		public void ShowThumbnail(WindowDetails window, Control parentControl) {
			UnregisterThumbnail();

			DWM.DwmRegisterThumbnail(Handle, window.Handle, out thumbnailHandle);
			if (thumbnailHandle != IntPtr.Zero) {
				SIZE sourceSize;
				DWM.DwmQueryThumbnailSourceSize(thumbnailHandle, out sourceSize);
				int thumbnailHeight = 200;
				int thumbnailWidth = (int)(thumbnailHeight * ((float)sourceSize.width / (float)sourceSize.height));
				if (parentControl != null && thumbnailWidth > parentControl.Width) {
					thumbnailWidth = parentControl.Width;
					thumbnailHeight = (int)(thumbnailWidth * ((float)sourceSize.height / (float)sourceSize.width));
				}
				Width = thumbnailWidth;
				Height = thumbnailHeight;
				// Prepare the displaying of the Thumbnail
				DWM_THUMBNAIL_PROPERTIES props = new DWM_THUMBNAIL_PROPERTIES();
				props.Opacity = (byte)255;
				props.Visible = true;
				props.SourceClientAreaOnly = false;
				props.Destination = new RECT(0, 0, thumbnailWidth, thumbnailHeight);
				DWM.DwmUpdateThumbnailProperties(thumbnailHandle, ref props);
				if (parentControl != null) {
					AlignToControl(parentControl);
				}

				if (!Visible) {
					Show();
				}
				// Make sure it's on "top"!
				if (parentControl != null) {
					User32.SetWindowPos(Handle, parentControl.Handle, 0, 0, 0, 0, WindowPos.SWP_NOMOVE | WindowPos.SWP_NOSIZE | WindowPos.SWP_NOACTIVATE);
				}
			}
		}