These changes should fix some issues with losing focus before capturing. [skip ci]

This commit is contained in:
RKrom 2014-12-14 22:19:46 +01:00
parent ccd809d4ed
commit dda5b53976
2 changed files with 37 additions and 16 deletions

View file

@ -250,18 +250,6 @@ namespace Greenshot.Helpers {
AddConfiguredDestination();
}
// Workaround for proble with DPI retrieval, the FromHwnd activates the window...
WindowDetails previouslyActiveWindow = WindowDetails.GetActiveWindow();
// Workaround for changed DPI settings in Windows 7
using (Graphics graphics = Graphics.FromHwnd(MainForm.Instance.Handle)) {
_capture.CaptureDetails.DpiX = graphics.DpiX;
_capture.CaptureDetails.DpiY = graphics.DpiY;
}
if (previouslyActiveWindow != null) {
// Set previouslyActiveWindow as foreground window
previouslyActiveWindow.ToForeground();
}
// Delay for the Context menu
if (conf.CaptureDelay > 0) {
Thread.Sleep(conf.CaptureDelay);
@ -283,6 +271,7 @@ namespace Greenshot.Helpers {
case CaptureMode.Window:
_capture = WindowCapture.CaptureScreen(_capture);
_capture.CaptureDetails.AddMetaData("source", "Screen");
SetDPI();
CaptureWithFeedback();
break;
case CaptureMode.ActiveWindow:
@ -296,11 +285,13 @@ namespace Greenshot.Helpers {
_capture.CaptureDetails.AddMetaData("source", "Screen");
_capture.CaptureDetails.Title = "Screen";
}
SetDPI();
HandleCapture();
break;
case CaptureMode.IE:
if (IECaptureHelper.CaptureIE(_capture, SelectedCaptureWindow) != null) {
_capture.CaptureDetails.AddMetaData("source", "Internet Explorer");
SetDPI();
HandleCapture();
}
break;
@ -331,6 +322,7 @@ namespace Greenshot.Helpers {
if (!captureTaken) {
_capture = WindowCapture.CaptureScreen(_capture);
}
SetDPI();
HandleCapture();
break;
case CaptureMode.Clipboard:
@ -424,6 +416,7 @@ namespace Greenshot.Helpers {
//capture.MoveElements(capture.ScreenBounds.Location.X - capture.Location.X, capture.ScreenBounds.Location.Y - capture.Location.Y);
_capture.CaptureDetails.AddMetaData("source", "screen");
SetDPI();
HandleCapture();
}
break;
@ -432,10 +425,12 @@ namespace Greenshot.Helpers {
if (Rectangle.Empty.Equals(_captureRect)) {
_capture = WindowCapture.CaptureScreen(_capture);
_capture.CaptureDetails.AddMetaData("source", "screen");
SetDPI();
CaptureWithFeedback();
} else {
_capture = WindowCapture.CaptureRectangle(_capture, _captureRect);
_capture.CaptureDetails.AddMetaData("source", "screen");
SetDPI();
HandleCapture();
}
break;
@ -943,6 +938,24 @@ namespace Greenshot.Helpers {
return captureForWindow;
}
private void SetDPI() {
// Workaround for proble with DPI retrieval, the FromHwnd activates the window...
WindowDetails previouslyActiveWindow = WindowDetails.GetActiveWindow();
// Workaround for changed DPI settings in Windows 7
using (Graphics graphics = Graphics.FromHwnd(MainForm.Instance.Handle)) {
_capture.CaptureDetails.DpiX = graphics.DpiX;
_capture.CaptureDetails.DpiY = graphics.DpiY;
}
if (previouslyActiveWindow != null) {
// Set previouslyActiveWindow as foreground window
previouslyActiveWindow.ToForeground();
}
if (_capture.CaptureDetails != null && _capture.Image != null) {
((Bitmap)_capture.Image).SetResolution(_capture.CaptureDetails.DpiX, _capture.CaptureDetails.DpiY);
}
}
#region capture with feedback
private void CaptureWithFeedback() {
// The following, to be precise the HideApp, causes the app to close as described in BUG-1620

View file

@ -589,12 +589,20 @@ namespace GreenshotPlugin.Core {
if (capture == null) {
capture = new Capture();
}
Image capturedImage = null;
// If the CaptureHandler has a handle use this, otherwise use the CaptureRectangle here
capture.Image = CaptureHandler.CaptureScreenRectangle != null ? CaptureHandler.CaptureScreenRectangle(captureBounds) : CaptureRectangle(captureBounds);
capture.Location = captureBounds.Location;
if (capture.CaptureDetails != null) {
((Bitmap)capture.Image).SetResolution(capture.CaptureDetails.DpiX, capture.CaptureDetails.DpiY);
if (CaptureHandler.CaptureScreenRectangle != null) {
try {
capturedImage = CaptureHandler.CaptureScreenRectangle(captureBounds);
} catch {
}
}
// If no capture, use the normal screen capture
if (capturedImage == null) {
capturedImage = CaptureRectangle(captureBounds);
}
capture.Image = capturedImage;
capture.Location = captureBounds.Location;
return capture.Image == null ? null : capture;
}