[英]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.涉及ActiveInspector
和ActiveExplorer
方法不可靠。
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
(可以是Explorer
或Inspector
)。
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.