c# - 在特定屏幕上启动进程

标签 c# windows process pinvoke multiple-monitors

我正在编写一个在特定屏幕上打开程序的小工具,这样我就可以将我们的监控屏幕(1 台机器有 2 个屏幕)设置为在一夜之间重新启动,并让它在启动时将监控网页恢复到正确的屏幕。我想通过使用 .NET 的 System.Diagnostics.Process 类来完成此操作。

我已经看到可以打开一个进程,然后使用 P/Invokes ( Open notepad to specific location on the screen, and to desired size? ) 将它移动到某个地方, 但是,我想在应用程序打开之前设置目标屏幕,以便例如在 Kiosk 模式下使用此设置正确启动 Chrome。

有人知道怎么做吗?

最佳答案

我们不久前使用 user32.dll 的 SetWindowPos 创建了一个类似的解决方案。虽然它不会在所需窗口中打开程序,但需要几毫秒才能打开,所以对于您的要求来说这不是真正的问题!

你可以看看下面的要点:
https://gist.github.com/reinhardholl/013a7c3fa319beeaf534#file-display-cs

特别注意 Display 类:

    private void ShowAppOnDisplay(App app)
    {
        SetWindowPos(app.Process.MainWindowHandle, 0, _screen.WorkingArea.Left, _screen.WorkingArea.Top, _screen.WorkingArea.Width, _screen.WorkingArea.Height, SWP_SHOWWINDOW);
    }

如果您需要更多帮助,请告诉我!

关于c# - 在特定屏幕上启动进程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24034115/

相关文章:

c++ - 实时、用户时间和系统时间的区别

Linux - 篡改现有进程

c# - 将定义常量传递给 dotnet build 会杀死目标框架符号

c# - 如何将带有反斜杠的字符串与另一个字符串连接起来

c# - asp net core 1 RC2 AccountController注入(inject)

windows - Windows下如何在Qt Creator中调试?

c - windows下EOF的值

windows - 我如何指定 C :\Program Files without a space in it for programs that can't handle spaces in file paths?

python - 我如何从 Linux 上的 python 中的进程 ID 获取用户名?

c# - 将平面数据库行数据转换为嵌套类型对象 linq