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

@ -1254,7 +1254,25 @@ namespace GreenshotPlugin.Core {
/// <summary>
/// Set the window as foreground window
/// </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);
}