【问题标题】:Is it possible to run a foreign .exe inside your window form?是否可以在窗口窗体中运行外部 .exe?
【发布时间】:2015-08-10 06:36:16
【问题描述】:

在这里,我试图在窗口窗体的面板中运行一些基于窗口的应用程序,并允许我在其中最小化它。 我能够在这个“notepad.exe”中运行和最小化,但不能使用 win 应用程序。

这是我的参考代码(仅适用于记事本):

[DllImport("USER32.DLL")]
static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);[DllImport("USER32.dll")]
private static extern bool MoveWindow(IntPtr hwnd, int x, int y, int cx, int cy, bool repaint);

Process process = Process.Start("someapp.exe");
process.WaitForInputIdle();
SetParent(process.MainWindowHandle, this.panel1.Handle);
MoveWindow(process.MainWindowHandle, 0, 0, this.Width - 90, this.Height, true);

请告诉我是否有可能实现以及如何实现?

【问题讨论】:

  • 我会建议避免这样的事情(阅读this 和谷歌一般的“oldnewthing”和“SetParent”)看看为什么。我最喜欢的名言“这在技术上是合法的。......玩电锯在技术上也是合法的。”
  • 所以基本上这是可能的,但不是一个好主意,对吧?

标签: c#


【解决方案1】:

好的,你需要做的就是替换

process.WaitForInputIdle();

Thread.Sleep(500); // Allow the process to open it's window

这是结果 app1 executes "For test app" several times and minimize them all

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-12-07
    • 2023-02-08
    • 2011-03-16
    • 1970-01-01
    • 2016-07-12
    • 2019-01-25
    • 1970-01-01
    • 2020-09-14
    相关资源
    最近更新 更多