在winform窗口中,嵌入外部exe,可使用panel控件作为容器进行,下面是代码
[DllImport("user32.dll", SetLastError = true)]
private static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
[DllImport("user32.dll", SetLastError = true)]
private static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags);
private const uint SWP_ASYNCWINDOWPOS = 0x4000;
private const uint SWP_SHOWWINDOW = 0x0040;
[DllImport("user32.dll", SetLastError = true)]
private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
Process externalProcess;
IntPtr targetWindowHandle = IntPtr.Zero;
在窗体代码加载方法中添加如下代码:
string path = System.Environment.CurrentDirectory+"\\***.exe";
StartEmbeddedProcess(path);
/// <summary>
/// 启动exe程序
/// </summary>
///