为什么不Word和QUOT;走到前面"当我们启动了吗? [英] Why doesn't Word "come to front" when we activate it?

查看:160
本文介绍了为什么不Word和QUOT;走到前面"当我们启动了吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们的WinForms应用程序使用MS Word中进行交互,我们运行这个code时生成一个文件,我们要显示在Word中我们的应用程序的前面:

Our winforms application interacts with MS Word and we run this code when a document is generated and we want to show it in Word in front of our application:

[setup w as a Word interop object]

w.Visible = True
w.Activate()

在推出了为 XP上运行Office 2007的计算机这个工程的目的。

When rolled out to XP machines running Office 2007 this works as intended.

Win7的运行Office 2010的计算机我们的任务栏上的应用程序,并闪烁背后的文档加载。

On Win7 machines running Office 2010 the document loads behind our application and flashes on the taskbar.

任何想法?

推荐答案

我最近偶然发现了一个类似的问题。我的.NET程序调用COM应用程序,但是在Win7的它有时会没有显示在任务栏上,也不是桌面上的。我是不是真的能够追查这个原因,但我写了下面的函数来解决这个问题:

I stumbled upon a similar problem recently. My .NET program called a COM application, but on Win7 it would sometimes neither show up in taskbar nor on the desktop at all. I wasn't really able to track down the cause of this, but I wrote the following function to work around the issue:

[System.Runtime.InteropServices.DllImport("User32.dll")]
private static extern bool SetForegroundWindow(IntPtr hwnd);

private static void BringAppToFront() {
    foreach (var p in System.Diagnostics.Process.GetProcesses().Where(p => p.ProcessName == "COMInstanceName")) {
        if (p.MainWindowHandle.ToInt32() != 0)
            SetForegroundWindow(p.MainWindowHandle);
    }
}

这篇关于为什么不Word和QUOT;走到前面"当我们启动了吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆