mirror of
https://github.com/greenshot/greenshot
synced 2025-07-14 00:53:51 -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.DpiY = graphics.DpiY;
|
||||
}
|
||||
windowToCapture.Restore();
|
||||
windowToCapture = CaptureHelper.SelectCaptureWindow(windowToCapture);
|
||||
if (windowToCapture != null) {
|
||||
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
|
||||
return false;
|
||||
}
|
||||
if (selectedCaptureWindow != null && selectedCaptureWindow.Iconic) {
|
||||
if (!presupplied && selectedCaptureWindow != null && selectedCaptureWindow.Iconic) {
|
||||
// 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!
|
||||
selectedCaptureWindow.Restore();
|
||||
}
|
||||
selectedCaptureWindow.ToForeground();
|
||||
selectedCaptureWindow = SelectCaptureWindow(selectedCaptureWindow);
|
||||
if (selectedCaptureWindow == null) {
|
||||
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>
|
||||
public static WindowDetails SelectCaptureWindow(WindowDetails windowToCapture) {
|
||||
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);
|
||||
// Trying workaround, the size 0 arrises with e.g. Toad.exe, has a different Window when minimized
|
||||
WindowDetails linkedWindow = WindowDetails.GetLinkedWindow(windowToCapture);
|
||||
|
@ -706,10 +705,6 @@ namespace Greenshot.Helpers {
|
|||
captureForWindow = new Capture();
|
||||
}
|
||||
Rectangle windowRectangle = windowToCapture.WindowRectangle;
|
||||
if (windowToCapture.Iconic) {
|
||||
// Restore the window making sure it's visible!
|
||||
windowToCapture.Restore();
|
||||
}
|
||||
|
||||
// When Vista & DWM (Aero) enabled
|
||||
bool dwmEnabled = DWM.isDWMEnabled();
|
||||
|
@ -769,10 +764,15 @@ namespace Greenshot.Helpers {
|
|||
bool captureTaken = false;
|
||||
// Try to capture
|
||||
while (!captureTaken) {
|
||||
if (windowCaptureMode == WindowCaptureMode.GDI) {
|
||||
ICapture tmpCapture = null;
|
||||
switch (windowCaptureMode) {
|
||||
case WindowCaptureMode.GDI:
|
||||
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) {
|
||||
captureForWindow = tmpCapture;
|
||||
|
@ -781,8 +781,9 @@ namespace Greenshot.Helpers {
|
|||
// A problem, try Screen
|
||||
windowCaptureMode = WindowCaptureMode.Screen;
|
||||
}
|
||||
} else if (windowCaptureMode == WindowCaptureMode.Aero || windowCaptureMode == WindowCaptureMode.AeroTransparent) {
|
||||
ICapture tmpCapture = null;
|
||||
break;
|
||||
case WindowCaptureMode.Aero:
|
||||
case WindowCaptureMode.AeroTransparent:
|
||||
if (WindowCapture.isDWMAllowed(process)) {
|
||||
tmpCapture = windowToCapture.CaptureDWMWindow(captureForWindow, windowCaptureMode, isAutoMode);
|
||||
}
|
||||
|
@ -793,8 +794,13 @@ namespace Greenshot.Helpers {
|
|||
// A problem, try GDI
|
||||
windowCaptureMode = WindowCaptureMode.GDI;
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
default:
|
||||
// Screen capture
|
||||
if (windowToCapture.Iconic) {
|
||||
// Restore the window making sure it's visible!
|
||||
windowToCapture.Restore();
|
||||
}
|
||||
windowRectangle.Intersect(captureForWindow.ScreenBounds);
|
||||
try {
|
||||
captureForWindow = WindowCapture.CaptureRectangle(captureForWindow, windowRectangle);
|
||||
|
@ -803,6 +809,7 @@ namespace Greenshot.Helpers {
|
|||
LOG.Error("Problem capturing", e);
|
||||
return null;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -75,12 +75,13 @@ namespace GreenshotPlugin.Controls {
|
|||
|
||||
DWM.DwmRegisterThumbnail(Handle, window.Handle, out thumbnailHandle);
|
||||
if (thumbnailHandle != IntPtr.Zero) {
|
||||
Rectangle windowRectangle = window.WindowRectangle;
|
||||
SIZE sourceSize;
|
||||
DWM.DwmQueryThumbnailSourceSize(thumbnailHandle, out sourceSize);
|
||||
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) {
|
||||
thumbnailWidth = parentControl.Width;
|
||||
thumbnailHeight = (int)(thumbnailWidth * ((float)windowRectangle.Height / (float)windowRectangle.Width));
|
||||
thumbnailHeight = (int)(thumbnailWidth * ((float)sourceSize.height / (float)sourceSize.width));
|
||||
}
|
||||
Width = thumbnailWidth;
|
||||
Height = thumbnailHeight;
|
||||
|
|
|
@ -705,8 +705,10 @@ namespace GreenshotPlugin.Core {
|
|||
User32.BringWindowToTop(this.hWnd);
|
||||
User32.SetForegroundWindow(this.hWnd);
|
||||
// Make sure windows has time to perform the action
|
||||
while(Iconic) {
|
||||
Application.DoEvents();
|
||||
}
|
||||
}
|
||||
|
||||
public WindowStyleFlags WindowStyle {
|
||||
get {
|
||||
|
@ -738,7 +740,7 @@ namespace GreenshotPlugin.Core {
|
|||
/// </summary>
|
||||
/// <param name="capture">The capture to fill</param>
|
||||
/// <returns>ICapture</returns>
|
||||
public ICapture CaptureWindow(ICapture capture) {
|
||||
public ICapture CaptureGDIWindow(ICapture capture) {
|
||||
Image capturedImage = PrintWindow();
|
||||
if (capturedImage != null) {
|
||||
capture.Image = capturedImage;
|
||||
|
@ -772,7 +774,7 @@ namespace GreenshotPlugin.Core {
|
|||
SIZE sourceSize;
|
||||
DWM.DwmQueryThumbnailSourceSize(thumbnailHandle, out sourceSize);
|
||||
|
||||
if (sourceSize.cx <= 0 || sourceSize.cy <= 0) {
|
||||
if (sourceSize.width <= 0 || sourceSize.height <= 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -819,7 +821,7 @@ namespace GreenshotPlugin.Core {
|
|||
tempForm.Size = sourceSize.ToSize();
|
||||
|
||||
// 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) {
|
||||
// Correct capture size for maximized window by offsetting the X,Y with the border size
|
||||
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
|
||||
DWM_THUMBNAIL_PROPERTIES props = new DWM_THUMBNAIL_PROPERTIES();
|
||||
props.Opacity = (byte)255;
|
||||
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);
|
||||
tempForm.Show();
|
||||
tempFormShown = true;
|
||||
|
@ -1322,9 +1322,7 @@ namespace GreenshotPlugin.Core {
|
|||
/// As GDI+ draws it, it will be without Aero borders!
|
||||
/// </summary>
|
||||
public Image PrintWindow() {
|
||||
Rectangle windowRect = Rectangle.Empty;
|
||||
GetWindowRect(out windowRect);
|
||||
|
||||
Rectangle windowRect = WindowRectangle;
|
||||
// Start the capture
|
||||
Exception exceptionOccured = null;
|
||||
Image returnImage = null;
|
||||
|
|
|
@ -25,17 +25,17 @@ using System.Runtime.InteropServices;
|
|||
namespace GreenshotPlugin.UnmanagedHelpers {
|
||||
[StructLayout(LayoutKind.Sequential), Serializable()]
|
||||
public struct SIZE {
|
||||
public int cx;
|
||||
public int cy;
|
||||
public int width;
|
||||
public int height;
|
||||
public SIZE(Size size) : this(size.Width, size.Height) {
|
||||
|
||||
}
|
||||
public SIZE(int cx, int cy) {
|
||||
this.cx = cx;
|
||||
this.cy = cy;
|
||||
public SIZE(int width, int height) {
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
}
|
||||
public Size ToSize() {
|
||||
return new Size(cx, cy);
|
||||
return new Size(width, height);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue