c#outlook打开现有实例并获取打开的Outlook窗口列表以构成对所选窗口的回复。
我能够获得Outlook的现有实例,但不知道如何接近其子窗口并使用现有电子邮件设置回复而不是创建新的mailitem
public static Outlook.Application OutlookInstance { 得到 { Outlook.Application application = null;
// Check whether there is an Outlook process running.
if (Process.GetProcessesByName("OUTLOOK").Count() > 0)
{
// If so, use the GetActiveObject method to obtain the process and cast it to an Application object.
application = Marshal.GetActiveObject("Outlook.Application") as Outlook.Application;
}
else
{
// If not, create a new instance of Outlook and log on to the default profile.
application = new Outlook.Application();
Outlook.NameSpace nameSpace = application.GetNamespace("MAPI");
nameSpace.Logon("", "", Missing.Value, Missing.Value);
nameSpace = null;
}
// Return the Outlook Application object.
return application;
}
}
答案 0 :(得分:0)
看起来您对ActiveInspector方法感兴趣,该方法返回桌面上最顶层的Inspector对象。使用此方法可以访问用户最有可能查看的Inspector对象。如果没有检查器处于活动状态,则返回null(VB.NET中没有任何内容)。
此外,您可能会发现Application类的Inspectors属性很有帮助。它返回一个Inspectors集合对象,该对象包含代表所有打开的检查器的Inspector对象。
Dim myInspectors As Outlook.Inspectors
Dim x as Integer
Dim iCount As Integer
Set myInspectors = Application.Inspectors
iCount = Application.Inspectors.Count
If iCount > 0 Then
For x = 1 To iCount
MsgBox myInspectors.Item(x).Caption
Next x
Else
MsgBox "No inspector windows are open."
End If
如果需要在Outlook资源管理器窗口中获取当前选定的项目,请使用Selection对象。有关详细信息,请参阅How to: Programmatically Determine the Current Outlook Item。