Я создал надстройку Outlook 2016 с VSTO. Исходное меню вставляется в меню при щелчке правой кнопкой мыши на полученной почте. Смотрите ниже для деталей. Состоит из ThisAddin.cs и OutlookAddInExtensibility.cs.
Это работает, но я не могу отрегулировать положение меню. Например, возможно ли вывести его наверх?
введите описание изображения здесь
ThisAddin.cs
using System;
using Office = Microsoft.Office.Core;
namespace OutlookAddInRclick
{
public partial class ThisAddIn
{
protected override Office.IRibbonExtensibility CreateRibbonExtensibilityObject()
{
return new OutlookAddInExtensibility();
}
private void ThisAddIn_Startup(object sender, EventArgs e)
{
}
private void ThisAddIn_Shutdown(object sender, EventArgs e)
{
// Note: Outlook no longer raises this event. If you have code that
// must run when Outlook shuts down, see https://go.microsoft.com/fwlink/?LinkId=506785
}
#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
}
}
OutlookAddInExtensibility.cs
using Microsoft.Office.Core;
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Text;
using System.Text.RegularExpressions;
using System.Web;
using Outlook = Microsoft.Office.Interop.Outlook;
namespace OutlookAddInRclick
{
[ComVisible(true)]
public class OutlookAddInExtensibility : IRibbonExtensibility
{
public string GetCustomUI(string RibbonID)
{
return
@"<?xml version=""1.0"" encoding=""UTF-8""?>
<customUI xmlns=""http://schemas.microsoft.com/office/2009/07/customui"">
<contextMenus>
<contextMenu idMso=""ContextMenuReadOnlyMailText"">
<button id=""MyContextMenuReadOnlyMailText"" label=""Test"" onAction=""RibbonMenuClick"" />
</contextMenu>
</contextMenus>
</customUI>
";
}
public void RibbonMenuClick(IRibbonControl control)
{
object oItem;
Outlook.Application oApp = new Outlook.Application();
Outlook.Explorer oExp = oApp.ActiveExplorer();
Outlook.Selection oSel = oExp.Selection;
for (int i = 1; i <= oSel.Count; i++)
{
oItem = oSel[i];
Outlook.MailItem oMail = (Outlook.MailItem)oItem;
Outlook.Inspector inspector = oMail.GetInspector;
Microsoft.Office.Interop.Word.Document document =
(Microsoft.Office.Interop.Word.Document)inspector.WordEditor;
string request = "http://hogehoge.asp?tsn=";
string searchString = document.Application.Selection.Text;
RibbonMenuClickCore(request, searchString);
}
}
private static void RibbonMenuClickCore(string request, string searchString)
{
string query = request + HttpUtility.UrlEncode(searchString, Encoding.UTF8);
Regex re = new Regex("iexplore\\.exe", RegexOptions.IgnoreCase);
Guid CLSID_ShellWindows = new Guid("{9BA05972-F6A8-11CF-A442-00A0C90A8F39}");
dynamic shellWindows = Activator.CreateInstance(Type.GetTypeFromCLSID(CLSID_ShellWindows));
dynamic oMyIE = null;
foreach (var oIE in shellWindows)
{
string fullName = null;
try { fullName = oIE.FullName; }
catch (COMException ex)
{
Console.WriteLine(ex.Message);
}
if (re.IsMatch(fullName)) { oMyIE = oIE; break; }
else { Marshal.ReleaseComObject(oIE); }
}
if (oMyIE != null)
{
oMyIE.Navigate2(query);
Marshal.ReleaseComObject(oMyIE);
}
else
{
Process.Start(query);
}
}
}
}