【问题标题】:.net process start an Internet Explorer on top.net 进程在顶部启动 Internet Explorer
【发布时间】:2017-01-26 15:43:27
【问题描述】:

我正在处理基于 .NET Windows 窗体的应用程序产品。在这个应用程序中,我可以添加 process.start 来启动 Internet Explorer 会话。但是不知何故,IE 会话总是在后台打开。有没有办法可以强制它保持在最终用户面前?谢谢

【问题讨论】:

    标签: .net windows forms process.start


    【解决方案1】:

    没有直接的方法。 你必须使用 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

    【讨论】:

      猜你喜欢
      • 2011-09-21
      • 1970-01-01
      • 1970-01-01
      • 2023-03-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-29
      • 1970-01-01
      相关资源
      最近更新 更多