Some fixed for not getting windows to focus/to front which were inspired by FEATURE-992. [skip ci]

This commit is contained in:
Robin 2016-12-30 22:35:28 +01:00
commit 5a1a4737ec
8 changed files with 51 additions and 9 deletions

View file

@ -300,6 +300,10 @@ namespace Greenshot.Forms {
HandleMouseUp(); HandleMouseUp();
} }
break; break;
case Keys.F:
ToFront = !ToFront;
TopMost = !TopMost;
break;
} }
} }
#endregion #endregion

View file

@ -22,6 +22,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Reflection; using System.Reflection;
using System.Drawing; using System.Drawing;
using GreenshotPlugin.Core;
namespace Greenshot.Interop.Office { namespace Greenshot.Interop.Office {
public class ExcelExporter { public class ExcelExporter {
@ -72,6 +73,11 @@ namespace Greenshot.Interop.Office {
} }
} }
} }
int hWnd = excelApplication.Hwnd;
if (hWnd > 0)
{
WindowDetails.ToForeground(new IntPtr(hWnd));
}
} }
} }

View file

@ -22,6 +22,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using GreenshotOfficePlugin; using GreenshotOfficePlugin;
using Greenshot.IniFile; using Greenshot.IniFile;
using GreenshotPlugin.Core;
namespace Greenshot.Interop.Office { namespace Greenshot.Interop.Office {
public class WordExporter { public class WordExporter {
@ -123,7 +124,15 @@ namespace Greenshot.Interop.Office {
// ignored // ignored
} }
try { try {
wordDocument.Activate(); using (var activeWindow = wordDocument.ActiveWindow)
{
activeWindow.Activate();
int hWnd = activeWindow.Hwnd;
if (hWnd > 0)
{
WindowDetails.ToForeground(new IntPtr(hWnd));
}
}
} }
catch catch
{ {
@ -192,7 +201,15 @@ namespace Greenshot.Interop.Office {
// ignored // ignored
} }
try { try {
wordDocument.ActiveWindow.Activate(); using (var activeWindow = wordDocument.ActiveWindow)
{
activeWindow.Activate();
int hWnd = activeWindow.Hwnd;
if (hWnd > 0)
{
WindowDetails.ToForeground(new IntPtr(hWnd));
}
}
} }
catch catch
{ {

View file

@ -37,13 +37,21 @@ namespace Greenshot.Interop.Office {
string Version { string Version {
get; get;
} }
/// <summary>
/// Returns an Integer indicating the top-level window handle of the Microsoft Excel window.
/// </summary>
int Hwnd
{
get;
}
} }
// See: http://msdn.microsoft.com/en-us/library/microsoft.office.interop.excel.workbooks.aspx // See: http://msdn.microsoft.com/en-us/library/microsoft.office.interop.excel.workbooks.aspx
public interface IWorkbooks : ICommon, ICollection { public interface IWorkbooks : ICommon, ICollection {
IWorkbook Add(object template); IWorkbook Add(object template);
// Use index + 1!! // Use index + 1!!
IWorkbook this[object Index] { IWorkbook this[object index] {
get; get;
} }
} }
@ -76,14 +84,14 @@ namespace Greenshot.Interop.Office {
} }
// See: http://msdn.microsoft.com/en-us/library/microsoft.office.interop.excel.iworksheets_members.aspx // See: http://msdn.microsoft.com/en-us/library/microsoft.office.interop.excel.iworksheets_members.aspx
public interface IWorksheets : ICommon, ICollection { public interface IWorksheets : ICollection {
// Use index + 1!! // Use index + 1!!
IWorksheet this[object Index] { IWorksheet this[object index] {
get; get;
} }
} }
public interface IPictures : ICommon, ICollection { public interface IPictures : ICollection {
// Use index + 1!! // Use index + 1!!
//IPicture this[object Index] { get; } //IPicture this[object Index] { get; }
void Insert(string file); void Insert(string file);

View file

@ -289,7 +289,9 @@ namespace Greenshot.Interop.Office {
} }
} }
// See: http://msdn.microsoft.com/en-us/library/microsoft.office.interop.outlook.inspector_members.aspx /// <summary>
/// See: http://msdn.microsoft.com/en-us/library/microsoft.office.interop.outlook.inspector_members.aspx
/// </summary>
public interface IInspector : ICommonExplorer { public interface IInspector : ICommonExplorer {
IItem CurrentItem { IItem CurrentItem {
get; get;

View file

@ -60,6 +60,11 @@ namespace Greenshot.Interop.Office {
string Caption { string Caption {
get; get;
} }
/// <summary>
/// Returns an Integer (int in C#) that indicates the window handle of the specified window
/// </summary>
int Hwnd { get; }
} }
/// <summary> /// <summary>

View file

@ -152,7 +152,8 @@ namespace GreenshotPlugin.Core {
var menu = new ContextMenuStrip var menu = new ContextMenuStrip
{ {
ImageScalingSize = CoreConfig.IconSize, ImageScalingSize = CoreConfig.IconSize,
Tag = null Tag = null,
TopLevel = true
}; };
menu.Closing += delegate(object source, ToolStripDropDownClosingEventArgs eventArgs) { menu.Closing += delegate(object source, ToolStripDropDownClosingEventArgs eventArgs) {

View file

@ -1256,7 +1256,6 @@ namespace GreenshotPlugin.Core {
/// </summary> /// </summary>
public static void ToForeground(IntPtr handle) public static void ToForeground(IntPtr handle)
{ {
// 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)
{ {