mirror of
https://github.com/greenshot/greenshot
synced 2025-07-14 17:13:44 -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
|
@ -1125,7 +1125,6 @@ namespace Greenshot {
|
||||||
capture.CaptureDetails.DpiX = graphics.DpiY;
|
capture.CaptureDetails.DpiX = graphics.DpiY;
|
||||||
capture.CaptureDetails.DpiY = graphics.DpiY;
|
capture.CaptureDetails.DpiY = graphics.DpiY;
|
||||||
}
|
}
|
||||||
windowToCapture.Restore();
|
|
||||||
windowToCapture = CaptureHelper.SelectCaptureWindow(windowToCapture);
|
windowToCapture = CaptureHelper.SelectCaptureWindow(windowToCapture);
|
||||||
if (windowToCapture != null) {
|
if (windowToCapture != null) {
|
||||||
capture = CaptureHelper.CaptureWindow(windowToCapture, capture, coreConf.WindowCaptureMode);
|
capture = CaptureHelper.CaptureWindow(windowToCapture, capture, coreConf.WindowCaptureMode);
|
||||||
|
|
|
@ -631,12 +631,11 @@ namespace Greenshot.Helpers {
|
||||||
// Nothing to capture, code up in the stack will capture the full screen
|
// Nothing to capture, code up in the stack will capture the full screen
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (selectedCaptureWindow != null && selectedCaptureWindow.Iconic) {
|
if (!presupplied && selectedCaptureWindow != null && selectedCaptureWindow.Iconic) {
|
||||||
// Restore the window making sure it's visible!
|
// Restore the window making sure it's visible!
|
||||||
// This is done mainly for a screen capture, but some applications like Excel and TOAD have weird behaviour!
|
// This is done mainly for a screen capture, but some applications like Excel and TOAD have weird behaviour!
|
||||||
selectedCaptureWindow.Restore();
|
selectedCaptureWindow.Restore();
|
||||||
}
|
}
|
||||||
selectedCaptureWindow.ToForeground();
|
|
||||||
selectedCaptureWindow = SelectCaptureWindow(selectedCaptureWindow);
|
selectedCaptureWindow = SelectCaptureWindow(selectedCaptureWindow);
|
||||||
if (selectedCaptureWindow == null) {
|
if (selectedCaptureWindow == null) {
|
||||||
LOG.Warn("No window to capture, after SelectCaptureWindow!");
|
LOG.Warn("No window to capture, after SelectCaptureWindow!");
|
||||||
|
@ -657,7 +656,7 @@ namespace Greenshot.Helpers {
|
||||||
/// <returns>WindowDetails with the target Window OR a replacement</returns>
|
/// <returns>WindowDetails with the target Window OR a replacement</returns>
|
||||||
public static WindowDetails SelectCaptureWindow(WindowDetails windowToCapture) {
|
public static WindowDetails SelectCaptureWindow(WindowDetails windowToCapture) {
|
||||||
Rectangle windowRectangle = windowToCapture.WindowRectangle;
|
Rectangle windowRectangle = windowToCapture.WindowRectangle;
|
||||||
if (windowToCapture.Iconic || windowRectangle.Width == 0 || windowRectangle.Height == 0) {
|
if (windowRectangle.Width == 0 || windowRectangle.Height == 0) {
|
||||||
LOG.WarnFormat("Window {0} has nothing to capture, using workaround to find other window of same process.", windowToCapture.Text);
|
LOG.WarnFormat("Window {0} has nothing to capture, using workaround to find other window of same process.", windowToCapture.Text);
|
||||||
// Trying workaround, the size 0 arrises with e.g. Toad.exe, has a different Window when minimized
|
// Trying workaround, the size 0 arrises with e.g. Toad.exe, has a different Window when minimized
|
||||||
WindowDetails linkedWindow = WindowDetails.GetLinkedWindow(windowToCapture);
|
WindowDetails linkedWindow = WindowDetails.GetLinkedWindow(windowToCapture);
|
||||||
|
@ -706,10 +705,6 @@ namespace Greenshot.Helpers {
|
||||||
captureForWindow = new Capture();
|
captureForWindow = new Capture();
|
||||||
}
|
}
|
||||||
Rectangle windowRectangle = windowToCapture.WindowRectangle;
|
Rectangle windowRectangle = windowToCapture.WindowRectangle;
|
||||||
if (windowToCapture.Iconic) {
|
|
||||||
// Restore the window making sure it's visible!
|
|
||||||
windowToCapture.Restore();
|
|
||||||
}
|
|
||||||
|
|
||||||
// When Vista & DWM (Aero) enabled
|
// When Vista & DWM (Aero) enabled
|
||||||
bool dwmEnabled = DWM.isDWMEnabled();
|
bool dwmEnabled = DWM.isDWMEnabled();
|
||||||
|
@ -769,10 +764,15 @@ namespace Greenshot.Helpers {
|
||||||
bool captureTaken = false;
|
bool captureTaken = false;
|
||||||
// Try to capture
|
// Try to capture
|
||||||
while (!captureTaken) {
|
while (!captureTaken) {
|
||||||
if (windowCaptureMode == WindowCaptureMode.GDI) {
|
|
||||||
ICapture tmpCapture = null;
|
ICapture tmpCapture = null;
|
||||||
|
switch (windowCaptureMode) {
|
||||||
|
case WindowCaptureMode.GDI:
|
||||||
if (WindowCapture.isGDIAllowed(process)) {
|
if (WindowCapture.isGDIAllowed(process)) {
|
||||||
tmpCapture = windowToCapture.CaptureWindow(captureForWindow);
|
if (windowToCapture.Iconic) {
|
||||||
|
// Restore the window making sure it's visible!
|
||||||
|
windowToCapture.Restore();
|
||||||
|
}
|
||||||
|
tmpCapture = windowToCapture.CaptureGDIWindow(captureForWindow);
|
||||||
}
|
}
|
||||||
if (tmpCapture != null) {
|
if (tmpCapture != null) {
|
||||||
captureForWindow = tmpCapture;
|
captureForWindow = tmpCapture;
|
||||||
|
@ -781,8 +781,9 @@ namespace Greenshot.Helpers {
|
||||||
// A problem, try Screen
|
// A problem, try Screen
|
||||||
windowCaptureMode = WindowCaptureMode.Screen;
|
windowCaptureMode = WindowCaptureMode.Screen;
|
||||||
}
|
}
|
||||||
} else if (windowCaptureMode == WindowCaptureMode.Aero || windowCaptureMode == WindowCaptureMode.AeroTransparent) {
|
break;
|
||||||
ICapture tmpCapture = null;
|
case WindowCaptureMode.Aero:
|
||||||
|
case WindowCaptureMode.AeroTransparent:
|
||||||
if (WindowCapture.isDWMAllowed(process)) {
|
if (WindowCapture.isDWMAllowed(process)) {
|
||||||
tmpCapture = windowToCapture.CaptureDWMWindow(captureForWindow, windowCaptureMode, isAutoMode);
|
tmpCapture = windowToCapture.CaptureDWMWindow(captureForWindow, windowCaptureMode, isAutoMode);
|
||||||
}
|
}
|
||||||
|
@ -793,8 +794,13 @@ namespace Greenshot.Helpers {
|
||||||
// A problem, try GDI
|
// A problem, try GDI
|
||||||
windowCaptureMode = WindowCaptureMode.GDI;
|
windowCaptureMode = WindowCaptureMode.GDI;
|
||||||
}
|
}
|
||||||
} else {
|
break;
|
||||||
|
default:
|
||||||
// Screen capture
|
// Screen capture
|
||||||
|
if (windowToCapture.Iconic) {
|
||||||
|
// Restore the window making sure it's visible!
|
||||||
|
windowToCapture.Restore();
|
||||||
|
}
|
||||||
windowRectangle.Intersect(captureForWindow.ScreenBounds);
|
windowRectangle.Intersect(captureForWindow.ScreenBounds);
|
||||||
try {
|
try {
|
||||||
captureForWindow = WindowCapture.CaptureRectangle(captureForWindow, windowRectangle);
|
captureForWindow = WindowCapture.CaptureRectangle(captureForWindow, windowRectangle);
|
||||||
|
@ -803,6 +809,7 @@ namespace Greenshot.Helpers {
|
||||||
LOG.Error("Problem capturing", e);
|
LOG.Error("Problem capturing", e);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -75,12 +75,13 @@ namespace GreenshotPlugin.Controls {
|
||||||
|
|
||||||
DWM.DwmRegisterThumbnail(Handle, window.Handle, out thumbnailHandle);
|
DWM.DwmRegisterThumbnail(Handle, window.Handle, out thumbnailHandle);
|
||||||
if (thumbnailHandle != IntPtr.Zero) {
|
if (thumbnailHandle != IntPtr.Zero) {
|
||||||
Rectangle windowRectangle = window.WindowRectangle;
|
SIZE sourceSize;
|
||||||
|
DWM.DwmQueryThumbnailSourceSize(thumbnailHandle, out sourceSize);
|
||||||
int thumbnailHeight = 200;
|
int thumbnailHeight = 200;
|
||||||
int thumbnailWidth = (int)(thumbnailHeight * ((float)windowRectangle.Width / (float)windowRectangle.Height));
|
int thumbnailWidth = (int)(thumbnailHeight * ((float)sourceSize.width / (float)sourceSize.height));
|
||||||
if (parentControl != null && thumbnailWidth > parentControl.Width) {
|
if (parentControl != null && thumbnailWidth > parentControl.Width) {
|
||||||
thumbnailWidth = parentControl.Width;
|
thumbnailWidth = parentControl.Width;
|
||||||
thumbnailHeight = (int)(thumbnailWidth * ((float)windowRectangle.Height / (float)windowRectangle.Width));
|
thumbnailHeight = (int)(thumbnailWidth * ((float)sourceSize.height / (float)sourceSize.width));
|
||||||
}
|
}
|
||||||
Width = thumbnailWidth;
|
Width = thumbnailWidth;
|
||||||
Height = thumbnailHeight;
|
Height = thumbnailHeight;
|
||||||
|
|
|
@ -705,8 +705,10 @@ namespace GreenshotPlugin.Core {
|
||||||
User32.BringWindowToTop(this.hWnd);
|
User32.BringWindowToTop(this.hWnd);
|
||||||
User32.SetForegroundWindow(this.hWnd);
|
User32.SetForegroundWindow(this.hWnd);
|
||||||
// Make sure windows has time to perform the action
|
// Make sure windows has time to perform the action
|
||||||
|
while(Iconic) {
|
||||||
Application.DoEvents();
|
Application.DoEvents();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public WindowStyleFlags WindowStyle {
|
public WindowStyleFlags WindowStyle {
|
||||||
get {
|
get {
|
||||||
|
@ -738,7 +740,7 @@ namespace GreenshotPlugin.Core {
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="capture">The capture to fill</param>
|
/// <param name="capture">The capture to fill</param>
|
||||||
/// <returns>ICapture</returns>
|
/// <returns>ICapture</returns>
|
||||||
public ICapture CaptureWindow(ICapture capture) {
|
public ICapture CaptureGDIWindow(ICapture capture) {
|
||||||
Image capturedImage = PrintWindow();
|
Image capturedImage = PrintWindow();
|
||||||
if (capturedImage != null) {
|
if (capturedImage != null) {
|
||||||
capture.Image = capturedImage;
|
capture.Image = capturedImage;
|
||||||
|
@ -772,7 +774,7 @@ namespace GreenshotPlugin.Core {
|
||||||
SIZE sourceSize;
|
SIZE sourceSize;
|
||||||
DWM.DwmQueryThumbnailSourceSize(thumbnailHandle, out sourceSize);
|
DWM.DwmQueryThumbnailSourceSize(thumbnailHandle, out sourceSize);
|
||||||
|
|
||||||
if (sourceSize.cx <= 0 || sourceSize.cy <= 0) {
|
if (sourceSize.width <= 0 || sourceSize.height <= 0) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -819,7 +821,7 @@ namespace GreenshotPlugin.Core {
|
||||||
tempForm.Size = sourceSize.ToSize();
|
tempForm.Size = sourceSize.ToSize();
|
||||||
|
|
||||||
// Prepare rectangle to capture from the screen.
|
// Prepare rectangle to capture from the screen.
|
||||||
Rectangle captureRectangle = new Rectangle(formLocation.X, formLocation.Y, sourceSize.cx, sourceSize.cy);
|
Rectangle captureRectangle = new Rectangle(formLocation.X, formLocation.Y, sourceSize.width, sourceSize.height);
|
||||||
if (Maximised) {
|
if (Maximised) {
|
||||||
// Correct capture size for maximized window by offsetting the X,Y with the border size
|
// Correct capture size for maximized window by offsetting the X,Y with the border size
|
||||||
captureRectangle.X += borderSize.Width;
|
captureRectangle.X += borderSize.Width;
|
||||||
|
@ -838,14 +840,12 @@ namespace GreenshotPlugin.Core {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make sure the to be captured window is active, important for the close/resize buttons
|
|
||||||
this.Restore();
|
|
||||||
|
|
||||||
// Prepare the displaying of the Thumbnail
|
// Prepare the displaying of the Thumbnail
|
||||||
DWM_THUMBNAIL_PROPERTIES props = new DWM_THUMBNAIL_PROPERTIES();
|
DWM_THUMBNAIL_PROPERTIES props = new DWM_THUMBNAIL_PROPERTIES();
|
||||||
props.Opacity = (byte)255;
|
props.Opacity = (byte)255;
|
||||||
props.Visible = true;
|
props.Visible = true;
|
||||||
props.Destination = new RECT(0, 0, sourceSize.cx, sourceSize.cy);
|
props.Destination = new RECT(0, 0, sourceSize.width, sourceSize.height);
|
||||||
DWM.DwmUpdateThumbnailProperties(thumbnailHandle, ref props);
|
DWM.DwmUpdateThumbnailProperties(thumbnailHandle, ref props);
|
||||||
tempForm.Show();
|
tempForm.Show();
|
||||||
tempFormShown = true;
|
tempFormShown = true;
|
||||||
|
@ -1322,9 +1322,7 @@ namespace GreenshotPlugin.Core {
|
||||||
/// As GDI+ draws it, it will be without Aero borders!
|
/// As GDI+ draws it, it will be without Aero borders!
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Image PrintWindow() {
|
public Image PrintWindow() {
|
||||||
Rectangle windowRect = Rectangle.Empty;
|
Rectangle windowRect = WindowRectangle;
|
||||||
GetWindowRect(out windowRect);
|
|
||||||
|
|
||||||
// Start the capture
|
// Start the capture
|
||||||
Exception exceptionOccured = null;
|
Exception exceptionOccured = null;
|
||||||
Image returnImage = null;
|
Image returnImage = null;
|
||||||
|
|
|
@ -25,17 +25,17 @@ using System.Runtime.InteropServices;
|
||||||
namespace GreenshotPlugin.UnmanagedHelpers {
|
namespace GreenshotPlugin.UnmanagedHelpers {
|
||||||
[StructLayout(LayoutKind.Sequential), Serializable()]
|
[StructLayout(LayoutKind.Sequential), Serializable()]
|
||||||
public struct SIZE {
|
public struct SIZE {
|
||||||
public int cx;
|
public int width;
|
||||||
public int cy;
|
public int height;
|
||||||
public SIZE(Size size) : this(size.Width, size.Height) {
|
public SIZE(Size size) : this(size.Width, size.Height) {
|
||||||
|
|
||||||
}
|
}
|
||||||
public SIZE(int cx, int cy) {
|
public SIZE(int width, int height) {
|
||||||
this.cx = cx;
|
this.width = width;
|
||||||
this.cy = cy;
|
this.height = height;
|
||||||
}
|
}
|
||||||
public Size ToSize() {
|
public Size ToSize() {
|
||||||
return new Size(cx, cy);
|
return new Size(width, height);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue