如何获取outlook中所有打开的inspector的title?
How to get the titles of all opened inspectors in outlook?
C#、VSTO、Outlook 2016。
我想获取 Outlook 中所有打开的检查器的标题列表。
第一次调用Outlook.Application.Inspectors[1].Caption returns“消息”作为检查员标题。
但是检查员的window-title显示邮件的主题。
但是当我打开更多检查器时,标题似乎发生了变化。
所以 collection 中总是有一个检查员没有
电子邮件主题和 Inspector.Caption 与对应的不匹配
window-title.
那么我怎样才能获得正确的 window-title 的列表?
对应代码:
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
m_Application = this.Application as Outlook.Application;
m_Inspectors = m_Application.Inspectors;
m_Inspectors.NewInspector += new Outlook.InspectorsEvents_NewInspectorEventHandler(m_Inspectors_NewInspector);
void m_Inspectors_NewInspector(Outlook.Inspector Inspector) {
if (Application.Inspectors.Count > 0) {
Debug.WriteLine("\n=== [Test] ================================");
Debug.WriteLine($" Inspectors.Count: {Application.Inspectors.Count}");
Debug.WriteLine(" Application.Inspectors: ");
foreach (Outlook.Inspector CurrentInspector in Application.Inspectors) {
Debug.WriteLine($" {CurrentInspector.Caption}");
Debug.WriteLine($" --> {CurrentInspector.CurrentItem.Subject}");
}
Debug.WriteLine("===========================================\n");
}
}
}
NewInspector
事件处理程序可能为时过早 - 尝试连接 Inspector.Activate
事件:它在 Inspector 可见时触发。
谢谢 Dmitry Streblechenko,这可以完成工作:
供参考:
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
Debug.WriteLine("[Test]: startet");
// Variables
m_Application = this.Application as Outlook.Application;
m_Inspectors = m_Application.Inspectors;
// Events
m_Inspectors.NewInspector += new Outlook.InspectorsEvents_NewInspectorEventHandler(m_Inspectors_NewInspector);
}
void m_Inspectors_NewInspector(Outlook.Inspector Inspector) {
Outlook.Inspector m_Inspector = Inspector;
((Outlook.InspectorEvents_Event) m_Inspector).Activate += new Outlook.InspectorEvents_ActivateEventHandler(m_Inspector_Activate);
}
void m_Inspector_Activate()
{
if (Application.Inspectors.Count > 0) {
Debug.WriteLine("\n=== [Test] ================================");
Debug.WriteLine($" Inspectors.Count: { Application.Inspectors.Count}");
Debug.WriteLine($" Application.Inspectors: ");
foreach (Outlook.Inspector CurrentInspector in Application.Inspectors) {
Debug.WriteLine($" {CurrentInspector.Caption}");
Debug.WriteLine($" --> {CurrentInspector.CurrentItem.Subject}");
}
Debug.WriteLine("===========================================\n");
}
}
但请注意,Activate-Event 的调用频率更高。所以每次你
更改或关闭 Inspector-window 事件被触发。
C#、VSTO、Outlook 2016。
我想获取 Outlook 中所有打开的检查器的标题列表。
第一次调用Outlook.Application.Inspectors[1].Caption returns“消息”作为检查员标题。 但是检查员的window-title显示邮件的主题。
但是当我打开更多检查器时,标题似乎发生了变化。
所以 collection 中总是有一个检查员没有 电子邮件主题和 Inspector.Caption 与对应的不匹配 window-title.
那么我怎样才能获得正确的 window-title 的列表?
对应代码:
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
m_Application = this.Application as Outlook.Application;
m_Inspectors = m_Application.Inspectors;
m_Inspectors.NewInspector += new Outlook.InspectorsEvents_NewInspectorEventHandler(m_Inspectors_NewInspector);
void m_Inspectors_NewInspector(Outlook.Inspector Inspector) {
if (Application.Inspectors.Count > 0) {
Debug.WriteLine("\n=== [Test] ================================");
Debug.WriteLine($" Inspectors.Count: {Application.Inspectors.Count}");
Debug.WriteLine(" Application.Inspectors: ");
foreach (Outlook.Inspector CurrentInspector in Application.Inspectors) {
Debug.WriteLine($" {CurrentInspector.Caption}");
Debug.WriteLine($" --> {CurrentInspector.CurrentItem.Subject}");
}
Debug.WriteLine("===========================================\n");
}
}
}
NewInspector
事件处理程序可能为时过早 - 尝试连接 Inspector.Activate
事件:它在 Inspector 可见时触发。
谢谢 Dmitry Streblechenko,这可以完成工作:
供参考:
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
Debug.WriteLine("[Test]: startet");
// Variables
m_Application = this.Application as Outlook.Application;
m_Inspectors = m_Application.Inspectors;
// Events
m_Inspectors.NewInspector += new Outlook.InspectorsEvents_NewInspectorEventHandler(m_Inspectors_NewInspector);
}
void m_Inspectors_NewInspector(Outlook.Inspector Inspector) {
Outlook.Inspector m_Inspector = Inspector;
((Outlook.InspectorEvents_Event) m_Inspector).Activate += new Outlook.InspectorEvents_ActivateEventHandler(m_Inspector_Activate);
}
void m_Inspector_Activate()
{
if (Application.Inspectors.Count > 0) {
Debug.WriteLine("\n=== [Test] ================================");
Debug.WriteLine($" Inspectors.Count: { Application.Inspectors.Count}");
Debug.WriteLine($" Application.Inspectors: ");
foreach (Outlook.Inspector CurrentInspector in Application.Inspectors) {
Debug.WriteLine($" {CurrentInspector.Caption}");
Debug.WriteLine($" --> {CurrentInspector.CurrentItem.Subject}");
}
Debug.WriteLine("===========================================\n");
}
}
但请注意,Activate-Event 的调用频率更高。所以每次你 更改或关闭 Inspector-window 事件被触发。