mirror of
https://github.com/greenshot/greenshot
synced 2025-08-14 02:37:03 -07:00
Fixed some capture issues, when trying to capture or show thumbnails of Windows that are iconized the size calculations are wrong.
git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@2206 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
parent
4d41fc0a43
commit
4a3161a281
5 changed files with 147 additions and 142 deletions
|
@ -26,92 +26,93 @@ using System.Drawing;
|
|||
using GreenshotPlugin.UnmanagedHelpers;
|
||||
|
||||
namespace GreenshotPlugin.Controls {
|
||||
/// <summary>
|
||||
/// This form allows us to show a Thumbnail preview of a window near the context menu when selecting a window to capture.
|
||||
/// Didn't make it completely "generic" yet, but at least most logic is in here so we don't have it in the mainform.
|
||||
/// </summary>
|
||||
public class ThumbnailForm : FormWithoutActivation {
|
||||
private static CoreConfiguration conf = IniConfig.GetIniSection<CoreConfiguration>();
|
||||
/// <summary>
|
||||
/// This form allows us to show a Thumbnail preview of a window near the context menu when selecting a window to capture.
|
||||
/// Didn't make it completely "generic" yet, but at least most logic is in here so we don't have it in the mainform.
|
||||
/// </summary>
|
||||
public class ThumbnailForm : FormWithoutActivation {
|
||||
private static CoreConfiguration conf = IniConfig.GetIniSection<CoreConfiguration>();
|
||||
|
||||
private IntPtr thumbnailHandle = IntPtr.Zero;
|
||||
private Rectangle parentMenuBounds = Rectangle.Empty;
|
||||
private IntPtr thumbnailHandle = IntPtr.Zero;
|
||||
private Rectangle parentMenuBounds = Rectangle.Empty;
|
||||
|
||||
public ThumbnailForm() {
|
||||
ShowInTaskbar = false;
|
||||
FormBorderStyle = FormBorderStyle.None;
|
||||
TopMost = false;
|
||||
Enabled = false;
|
||||
if (conf.WindowCaptureMode == WindowCaptureMode.Auto || conf.WindowCaptureMode == WindowCaptureMode.Aero) {
|
||||
BackColor = Color.FromArgb(255, conf.DWMBackgroundColor.R, conf.DWMBackgroundColor.G, conf.DWMBackgroundColor.B);
|
||||
} else {
|
||||
BackColor = Color.White;
|
||||
}
|
||||
public ThumbnailForm() {
|
||||
ShowInTaskbar = false;
|
||||
FormBorderStyle = FormBorderStyle.None;
|
||||
TopMost = false;
|
||||
Enabled = false;
|
||||
if (conf.WindowCaptureMode == WindowCaptureMode.Auto || conf.WindowCaptureMode == WindowCaptureMode.Aero) {
|
||||
BackColor = Color.FromArgb(255, conf.DWMBackgroundColor.R, conf.DWMBackgroundColor.G, conf.DWMBackgroundColor.B);
|
||||
} else {
|
||||
BackColor = Color.White;
|
||||
}
|
||||
|
||||
// cleanup at close
|
||||
this.FormClosing += delegate {
|
||||
UnregisterThumbnail();
|
||||
};
|
||||
}
|
||||
// cleanup at close
|
||||
this.FormClosing += delegate {
|
||||
UnregisterThumbnail();
|
||||
};
|
||||
}
|
||||
|
||||
public new void Hide() {
|
||||
UnregisterThumbnail();
|
||||
base.Hide();
|
||||
}
|
||||
public new void Hide() {
|
||||
UnregisterThumbnail();
|
||||
base.Hide();
|
||||
}
|
||||
|
||||
private void UnregisterThumbnail() {
|
||||
if (thumbnailHandle != IntPtr.Zero) {
|
||||
DWM.DwmUnregisterThumbnail(thumbnailHandle);
|
||||
thumbnailHandle = IntPtr.Zero;
|
||||
}
|
||||
}
|
||||
private void UnregisterThumbnail() {
|
||||
if (thumbnailHandle != IntPtr.Zero) {
|
||||
DWM.DwmUnregisterThumbnail(thumbnailHandle);
|
||||
thumbnailHandle = IntPtr.Zero;
|
||||
}
|
||||
}
|
||||
|
||||
/// <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();
|
||||
/// <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) {
|
||||
Rectangle windowRectangle = window.WindowRectangle;
|
||||
int thumbnailHeight = 200;
|
||||
int thumbnailWidth = (int)(thumbnailHeight * ((float)windowRectangle.Width / (float)windowRectangle.Height));
|
||||
if (parentControl != null && thumbnailWidth > parentControl.Width) {
|
||||
thumbnailWidth = parentControl.Width;
|
||||
thumbnailHeight = (int)(thumbnailWidth * ((float)windowRectangle.Height / (float)windowRectangle.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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void AlignToControl(Control alignTo) {
|
||||
Rectangle screenBounds = WindowCapture.GetScreenBounds();
|
||||
if (screenBounds.Contains(alignTo.Left, alignTo.Top - Height)) {
|
||||
Location = new Point(alignTo.Left + (alignTo.Width / 2) - (Width / 2), alignTo.Top - Height);
|
||||
} else {
|
||||
Location = new Point(alignTo.Left + (alignTo.Width / 2) - (Width / 2), alignTo.Bottom);
|
||||
}
|
||||
}
|
||||
}
|
||||
public void AlignToControl(Control alignTo) {
|
||||
Rectangle screenBounds = WindowCapture.GetScreenBounds();
|
||||
if (screenBounds.Contains(alignTo.Left, alignTo.Top - Height)) {
|
||||
Location = new Point(alignTo.Left + (alignTo.Width / 2) - (Width / 2), alignTo.Top - Height);
|
||||
} else {
|
||||
Location = new Point(alignTo.Left + (alignTo.Width / 2) - (Width / 2), alignTo.Bottom);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue