简体   繁体   English

如何可靠地知道当前(焦点)展望窗口中的对象。 即资源管理器类型或检查器类型

[英]How to reliably know what object is current (in focus) outlook window. i.e. an explorer type or Inspector type

We are using an add-in express region, which loads on the right-hand side of Outlook.我们正在使用加载项快速区域,它加载在 Outlook 的右侧。 In that form region, we have one user control, MyContainer .在那个表单区域中,我们有一个用户控件MyContainer This in turn contains two controls.这又包含两个控件。

In MyContainer , we need to decide on the visibility of each child control.MyContainer ,我们需要决定每个子控件的可见性。

A method involving ActiveInspector and ActiveExplorer , is not reliable.涉及ActiveInspectorActiveExplorer方法不可靠。

Example示例

Opening more than one compose window in the main explorer window, I happen to switch between explorer views, which are;在主资源管理器窗口中打开多个撰写窗口,我碰巧在资源管理器视图之间切换,它们是; Sent, Outbox, etc. I still find the explorer and inspector objects.已发送、发件箱等。我仍然可以找到资源管理器和检查器对象。

I need a good way to ensure that the window in which my region or MyContainer control is loading in is a compose/read or main Explorer (Inbox/Sent/Drafts/Outbox).我需要一个很好的方法来确保我的区域或 MyContainer 控件正在加载的窗口是一个撰写/阅读或主资源管理器(收件箱/已发送/草稿/发件箱)。

I have tried a number of things, but with no success.我尝试了很多东西,但没有成功。

Any pointers or suggestions will be really helpful.任何指示或建议都会非常有帮助。

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

A simple if/else condition can do the job.一个简单的 if/else 条件就可以完成这项工作。

The main problem is when the In-line response from Outlook is being used.主要问题是何时使用来自 Outlook 的内联响应。

That is available since version 13. So we use an empty try/catch to handle that.从版本 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);
                }
            }

Below code can be useful:下面的代码可能很有用:

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; 
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何获取当前的窗口ID或Outlook新的电子邮件窗口。 - how to get the current window id or something of a outlook new email window.? 如何在运行时定义委托类型(即动态委托类型) - How to I define a delegate type at runtime (i.e. dynamic delegate type) 如何判断一个类型是否是“简单”类型? 即持有一个单一的价值 - How do I tell if a type is a “simple” type? i.e. holds a single value 如何在Inspector和Explorer窗口中设置outlook右侧窗格的最小宽度 - How to set minimum width of outlook Right Side Pane in Inspector and Explorer window 我怎么知道对象的类型并引起它? - How do I know the type of object and cause it? c#:如何将字符串转换为自定义模板类型(即实现“T convertTo <T> (串)”) - c#: how to convert string to custom template type (i.e. implement “T convertTo<T>(string)”) 如何在不使用 Nullable 的情况下使用可选值类型(即结构体)参数<T>在 WebApi 2 中? - How to use optional value type (i.e. struct) parameters without using Nullable<T> in WebApi 2? 如何将多个相同类型的字符(即“ lala ,,, lala”)替换为单数(“ lala,lala”) - How to replace multiple same type of characters i.e.(“lala,,,,lala”) to a singular (“lala,lala”) 如何以编程方式在Outlook搜索文件夹上设置自定义图标? (即Outlook文件夹SetCustomIcon) - How to programmatically set a custom icon on an Outlook search folder? (i.e. Outlook Folder SetCustomIcon) 如何获取字符串名称来解析对象(即从它的意义上来说) - How to get a string name to resolve to an object (i.e. in the sense of what it is)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM