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();
}
break;
case Keys.F:
ToFront = !ToFront;
TopMost = !TopMost;
break;
}
}
#endregion

View file

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

View file

@ -37,13 +37,21 @@ namespace Greenshot.Interop.Office {
string Version {
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
public interface IWorkbooks : ICommon, ICollection {
IWorkbook Add(object template);
// Use index + 1!!
IWorkbook this[object Index] {
IWorkbook this[object index] {
get;
}
}
@ -76,14 +84,14 @@ namespace Greenshot.Interop.Office {
}
// 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!!
IWorksheet this[object Index] {
IWorksheet this[object index] {
get;
}
}
public interface IPictures : ICommon, ICollection {
public interface IPictures : ICollection {
// Use index + 1!!
//IPicture this[object Index] { get; }
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 {
IItem CurrentItem {
get;

View file

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

View file

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

View file

@ -1256,7 +1256,6 @@ namespace GreenshotPlugin.Core {
/// </summary>
public static void ToForeground(IntPtr handle)
{
// Do nothing if the window is already in the foreground
if (User32.GetForegroundWindow() == handle)
{