diff --git a/Greenshot/Forms/ImageEditorForm.cs b/Greenshot/Forms/ImageEditorForm.cs index d64f9a863..24ef53bc7 100644 --- a/Greenshot/Forms/ImageEditorForm.cs +++ b/Greenshot/Forms/ImageEditorForm.cs @@ -176,6 +176,7 @@ namespace Greenshot { Text = _surface.CaptureDetails.Title + " - " + Language.GetString(LangKey.editor_title); } } + Activate(); WindowDetails.ToForeground(Handle); } diff --git a/GreenshotPlugin/Core/WindowsHelper.cs b/GreenshotPlugin/Core/WindowsHelper.cs index 114d1296e..bc4aad664 100644 --- a/GreenshotPlugin/Core/WindowsHelper.cs +++ b/GreenshotPlugin/Core/WindowsHelper.cs @@ -1254,7 +1254,25 @@ namespace GreenshotPlugin.Core { /// /// Set the window as foreground window /// - public static void ToForeground(IntPtr handle) { + public static void ToForeground(IntPtr handle) + { + + // Do nothing if the window is already in the foreground + if (User32.GetForegroundWindow() == handle) + { + return; + } + + const byte ALT = 0xA4; + const int EXTENDEDKEY = 0x1; + const int KEYUP = 0x2; + + // 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. User32.SetForegroundWindow(handle); } diff --git a/GreenshotPlugin/UnmanagedHelpers/User32.cs b/GreenshotPlugin/UnmanagedHelpers/User32.cs index 97e8fe497..c0546ee48 100644 --- a/GreenshotPlugin/UnmanagedHelpers/User32.cs +++ b/GreenshotPlugin/UnmanagedHelpers/User32.cs @@ -62,6 +62,8 @@ namespace GreenshotPlugin.UnmanagedHelpers { #region DllImports [DllImport("user32", SetLastError = true)] + public static extern bool keybd_event(byte bVk, byte bScan, uint dwFlags, int dwExtraInfo); + [DllImport("user32", SetLastError = true)] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool IsWindowVisible(IntPtr hWnd); [DllImport("user32", SetLastError = true)]