2

我们正在使用加载项快速区域,该区域加载在 Outlook 的右侧。在该表单区域中,我们有一个用户控件,MyContainer. 这又包含两个控件。

MyContainer中,我们需要决定每个子控件的可见性。

涉及ActiveInspector和的方法ActiveExplorer不可靠。

例子

在主资源管理器窗口中打开多个撰写窗口,我碰巧在资源管理器视图之间切换,它们是;已发送、发件箱等。我仍然找到资源管理器和检查器对象。

我需要一种好方法来确保加载我的区域或 MyContainer 控件的窗口是撰写/读取或主资源管理器(收件箱/发送/草稿/发件箱)。

我尝试了很多事情,但没有成功。

任何指示或建议都会非常有帮助。

4

3 回答 3

3

一个简单的 if/else 条件就可以完成这项工作。

主要问题是使用 Outlook 的内联响应时。

从版本 13 开始提供。所以我们使用空的 try/catch 来处理它。

            Outlook.MailItem Email = null;
            Outlook.Inspector actInspector = Outlook.Application.ActiveInspector();
            if (actInspector == null)
            {
                Outlook.Explorer explorer = Outlook.Application.ActiveExplorer();

                try
                {
                    Email = explorer.GetType().InvokeMember("ActiveInlineResponse", System.Reflection.BindingFlags.GetProperty | System.Reflection.BindingFlags.Instance |
                            System.Reflection.BindingFlags.Public, null, explorer, null) as Outlook.MailItem;
                }
                finally
                {
                    Marshal.ReleaseComObject(explorer);
                }
            }
            else
            {
                try
                {
                    Email = actInspector.CurrentItem as Outlook.MailItem;
                }
                finally
                {
                    if (actInspector != null) Marshal.ReleaseComObject(actInspector);
                }
            }
于 2016-12-05T17:12:19.493 回答
3

尝试Application.ActiveWindow(可以是ExplorerInspector)。

于 2016-12-05T15:11:17.127 回答
0

下面的代码可能很有用:

Outlook.MailItem mailItem = null; 
var windowType = Globals.ThisAddIn.Application.ActiveWindow(); 
if (windowType is Outlook.Explorer) 
{    
    // Main Explorer
    Outlook.Explorer explorer = windowType as Outlook.Explorer;    
    mailItem = explorer.Selection[0] as Outlook.MailItem; 
}
else if (windowType is Outlook.Inspector) 
{   
    // Read or Compose
    Outlook.Inspector inspector = windowType as Outlook.Inspector;  
    mailItem = inspector.CurrentItem as Outlook.MailItem; 
}
于 2019-11-17T15:22:51.923 回答