BUG-2108: a change in ToForeground which should fix another issue, involved a key press, which "disables" the context menu in this use-case.

This commit is contained in:
Robin 2017-01-13 19:15:17 +01:00
commit 73bdd0f405
2 changed files with 17 additions and 10 deletions

View file

@ -844,7 +844,7 @@ namespace Greenshot.Helpers {
// Restore the window making sure it's visible! // Restore the window making sure it's visible!
windowToCapture.Restore(); windowToCapture.Restore();
} else { } else {
windowToCapture.ToForeground(); windowToCapture.ToForeground(false);
} }
tmpCapture = windowToCapture.CaptureGdiWindow(captureForWindow); tmpCapture = windowToCapture.CaptureGdiWindow(captureForWindow);
if (tmpCapture != null) { if (tmpCapture != null) {
@ -946,7 +946,7 @@ namespace Greenshot.Helpers {
_capture.CaptureDetails.DpiY = graphics.DpiY; _capture.CaptureDetails.DpiY = graphics.DpiY;
} }
// Set previouslyActiveWindow as foreground window // Set previouslyActiveWindow as foreground window
previouslyActiveWindow?.ToForeground(); previouslyActiveWindow?.ToForeground(false);
if (_capture.CaptureDetails != null) { if (_capture.CaptureDetails != null) {
((Bitmap) _capture.Image)?.SetResolution(_capture.CaptureDetails.DpiX, _capture.CaptureDetails.DpiY); ((Bitmap) _capture.Image)?.SetResolution(_capture.CaptureDetails.DpiX, _capture.CaptureDetails.DpiY);
} }

View file

@ -1254,7 +1254,9 @@ namespace GreenshotPlugin.Core {
/// <summary> /// <summary>
/// Set the window as foreground window /// Set the window as foreground window
/// </summary> /// </summary>
public static void ToForeground(IntPtr handle) /// <param name="handle">hWnd of the window to bring to the foreground</param>
/// <param name="workaround">bool with true to use a trick to really bring the window to the foreground</param>
public static void ToForeground(IntPtr handle, bool workaround = true)
{ {
// Do nothing if the window is already in the foreground // Do nothing if the window is already in the foreground
if (User32.GetForegroundWindow() == handle) if (User32.GetForegroundWindow() == handle)
@ -1266,10 +1268,14 @@ namespace GreenshotPlugin.Core {
const int EXTENDEDKEY = 0x1; const int EXTENDEDKEY = 0x1;
const int KEYUP = 0x2; const int KEYUP = 0x2;
// Simulate an "ALT" key press. // See https://msdn.microsoft.com/en-us/library/windows/desktop/ms633539(v=vs.85).aspx
User32.keybd_event(ALT, 0x45, EXTENDEDKEY | 0, 0); if (workaround)
// Simulate an "ALT" key release. {
User32.keybd_event(ALT, 0x45, EXTENDEDKEY | KEYUP, 0); // Simulate an "ALT" key press.
User32.keybd_event(ALT, 0x45, EXTENDEDKEY | 0, 0);
// Simulate an "ALT" key release.
User32.keybd_event(ALT, 0x45, EXTENDEDKEY | KEYUP, 0);
}
// Show window in forground. // Show window in forground.
User32.SetForegroundWindow(handle); User32.SetForegroundWindow(handle);
@ -1278,8 +1284,9 @@ namespace GreenshotPlugin.Core {
/// <summary> /// <summary>
/// Set the window as foreground window /// Set the window as foreground window
/// </summary> /// </summary>
public void ToForeground() { /// <param name="workaround">true to use a workaround, otherwise the window might only flash</param>
ToForeground(Handle); public void ToForeground(bool workaround = true) {
ToForeground(Handle, workaround);
} }
/// <summary> /// <summary>