我很幸运地找到了一个名为globalmousekeyhook的项目,通过它我可以设置我的 PPT VSTO 插件的快捷方式。
核心部分代码如下。
当我按下定义的快捷方式时,我的插件功能和 PPT 的内部命令都会被执行。
这有一个副作用,即我的插件触发的窗口不会被聚焦。
我尝试添加frm.activate()
or frm.focus
,但它们都不起作用。
我该怎么做才能只执行我的插件功能?任何意见将不胜感激。
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using PowerPoint = Microsoft.Office.Interop.PowerPoint;
using Gma.System.MouseKeyHook;
namespace PowerPointAddIn1
{
public partial class ThisAddIn
{
public static PowerPoint.Application PPTApp;
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
var QRun = Combination.FromString("Alt+E");
Action actionQRun = ShowQRunWin;
var assignment = new Dictionary<Combination, Action>
{
{QRun, actionQRun}
};
Hook.AppEvents().OnCombination(assignment);
}
public void ShowQRunWin()
{
CMDForm frm = new CMDForm();
frm.FormBorderStyle = FormBorderStyle.FixedSingle; //set it un-resizeable
frm.MaximizeBox = false; //remove maximize button
frm.MinimizeBox = false; //remove minimize button
frm.Show();
frm.Activate();
frm.Focus();
}
private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
{
}
#region VSTO generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InternalStartup()
{
this.Startup += new System.EventHandler(ThisAddIn_Startup);
this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
}
#endregion
protected override Microsoft.Office.Core.IRibbonExtensibility CreateRibbonExtensibilityObject()
{
return new RibbonUI();
}
}
}