FEATURE-992: Fixing a problem with the editor not becoming the foreground window. [skip ci]

This commit is contained in:
Robin 2016-12-26 21:00:15 +01:00
parent 4f289d838a
commit eabe6a18be
3 changed files with 22 additions and 1 deletions

View file

@ -176,6 +176,7 @@ namespace Greenshot {
Text = _surface.CaptureDetails.Title + " - " + Language.GetString(LangKey.editor_title); Text = _surface.CaptureDetails.Title + " - " + Language.GetString(LangKey.editor_title);
} }
} }
Activate();
WindowDetails.ToForeground(Handle); WindowDetails.ToForeground(Handle);
} }

View file

@ -1254,7 +1254,25 @@ 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) { 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); User32.SetForegroundWindow(handle);
} }

View file

@ -62,6 +62,8 @@ namespace GreenshotPlugin.UnmanagedHelpers {
#region DllImports #region DllImports
[DllImport("user32", SetLastError = true)] [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)] [return: MarshalAs(UnmanagedType.Bool)]
public static extern bool IsWindowVisible(IntPtr hWnd); public static extern bool IsWindowVisible(IntPtr hWnd);
[DllImport("user32", SetLastError = true)] [DllImport("user32", SetLastError = true)]