C# Interop.word在前台打开文档
我试图打开现有的word文档,并将MS word窗口置于最前面。我使用了以下代码C# Interop.word在前台打开文档,c#,.net,interop,ms-office,C#,.net,Interop,Ms Office,我试图打开现有的word文档,并将MS word窗口置于最前面。我使用了以下代码 var app = new Application{ Visible = true}; app.Documents.Open(path); app.Activate(); 这将在word中打开文档,在“我的windows 7”框中,word 2013将出现在前台。在运行windows 8.1和office 2010的最终用户计算机上,它会打开文档,但不会将Word放在前面。 windows 8或office 20
var app = new Application{ Visible = true};
app.Documents.Open(path);
app.Activate();
这将在word中打开文档,在“我的windows 7”框中,word 2013将出现在前台。在运行windows 8.1和office 2010的最终用户计算机上,它会打开文档,但不会将Word放在前面。
windows 8或office 2010是否需要不同的/缺少的步骤
谢谢试试看
如果这不起作用,请尝试以下API:
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool SetForegroundWindow(IntPtr hWnd);
[DllImport("user32.dll", SetLastError = true)]
static extern System.IntPtr FindWindow(string lpClassName, string lpWindowName);
private void ShowForeground(Word.Application app)
{
IntPtr handler = FindWindow(null, app.Caption);
SetForegroundWindow(handler);
}
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool SetForegroundWindow(IntPtr hWnd);
[DllImport("user32.dll", SetLastError = true)]
static extern System.IntPtr FindWindow(string lpClassName, string lpWindowName);
private void ShowForeground(Word.Application app)
{
IntPtr handler = FindWindow(null, app.Caption);
SetForegroundWindow(handler);
}