我正在处理基于.NET Windows窗体的应用程序产品。在这个应用程序中,我可以添加process.start来启动Internet Explorer会话。但是不知何故,IE会话总是在后台打开。有没有办法可以强迫它留在最终用户面前?谢谢
答案 0 :(得分:0)
没有直接的方法。 你必须使用pinvoke:
[DllImport("user32.dll", SetLastError = true)]
static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int x, int y, int cx, int cy, uint uFlags);
[Fact]
public void OpenIeAsTopWindow()
{
Process process = Process.Start("IExplore.exe", "http://google.com");
var HWND_TOPMOST = new IntPtr(-1);
const uint SWP_NOSIZE = 0x0001;
const uint SWP_NOMOVE = 0x0002;
const uint SWP_SHOWWINDOW = 0x0040;
SetWindowPos(process.MainWindowHandle, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);
}
所有定义均来自here