Outlook 超链接上下文菜单

Outlook hyperlink context menu

我正在尝试为超链接制作上下文菜单。似乎有几个上下文可以拦截超链接事件——目前我对 idMso="ContextMenuReadOnlyMailHyperlink".

的上下文菜单感兴趣

有两种不同的方式可以执行此菜单中我的新按钮的回调——如果在 Outlook 的预览窗格中右键单击超链接,或者打开电子邮件以在其自身中阅读 window。

从预览窗格调用时,我的回调接收到一个 Explorer COM 对象。我假设资源管理器的 ActiveInlineResponseWordEditor 属性 会以某种方式包含我选择的超链接,但它会抛出一个无用的 COM 异常 ("The operation failed")。

如何从上下文中找到选定的超链接?

此外,Inspector COM 对象如何(当从电子邮件中右键单击超链接时 window)?

我遇到了类似的问题,我的解决方案如下:

public void OnCustomHyperlinkMenuClick(IRibbonControl control)
{
    Explorer explorer = control.Context as Explorer;
    if (explorer != null)
    {
        Document document = explorer.ActiveInlineResponseWordEditor;
        //Note from asker: above line throws a COM Exception ("The operation failed")

        if (document != null && document.Windows != null && document.Windows.Count > 0)
        {
            Microsoft.Office.Interop.Word.Selection selection = document.Windows[1].Selection;
            if (selection != null && selection.Hyperlinks != null && selection.Hyperlinks.Count > 0)
            {
                Hyperlink hyperlink = selection.Hyperlinks[1];
                string hyperlinkUrl = hyperlink.Address;
                DoSomethingWithUrl(hyperlinkUrl);
            }
        }
    }
}

您需要在项目中添加对单词互操作程序集 "Microsoft.Office.Interop.Word.dll" 的引用。

I assumed the Explorer's ActiveInlineResponseWordEditor property would contain my selected hyperlink somehow, but it throws a non-helpful COM exception ("The operation failed").

当用户执行导致内联响应出现在阅读窗格中的操作时,将触发资源管理器 class 的 ActiveInlineResponseWordEditor property cannot be used when the InlineResponse is not activated. The InlineResponse 事件。在您的情况下,内联响应未激活。

How can I find the selected hyperlink from this context?

资源管理器 class 提供了 Selection property which returns a Selection object that contains the item or items that are selected in the explorer window. You can use the Item method (represented by the indexer in C#) to get a Microsoft Outlook item or conversation header from the selection. Then try to cast it to the MailItem class and get the Inspector object, see the GetInspector method of the MailItem class. The Inspector class provides the WordEditor 属性 returns 正在显示的消息的 Microsoft Word 文档对象模型。您可以使用 Word 对象模型来获取选择。