在Winform面板中打开c# exe
本文关键字:exe Winform | 更新日期: 2023-09-27 18:07:31
我只是用c#代码写了一个exe,我想在c# winform中使用SetParent来运行exe
Process proc = Process.Start(
new ProcessStartInfo()
{
FileName = "Menu",
Arguments = "/c echo hello user ^<!^> && pause",
WindowStyle = ProcessWindowStyle.Minimized
});
SetParent(proc.MainWindowHandle, this.panel2.Handle);
你可以试试这个(菜单文件名没有。exe扩展名)
[DllImport("user32.dll", SetLastError = true)]
static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
then in your function
var proc = new Process();
proc.StartInfo.FileName = "Menu.exe";
proc.StartInfo.Arguments = "/c echo hello user ^<!^> && pause",
proc.Start();
SetParent(proc.MainWindowHandle, this.panel2.Handle);
using System.Runtime.InteropServices;
using System.Threading;
[DllImport("user32.dll", SetLastError = true)]
private static extern bool MoveWindow(IntPtr hwnd, int x, int y, int cx, int cy, bool repaint);
[DllImport("user32.dll", SetLastError = true)]
static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
然后 var proc = new Process();
proc.StartInfo.FileName = "Menu.exe";
proc.Start();
IntPtr ptr = IntPtr.Zero;
while ((ptr = proc.MainWindowHandle) == IntPtr.Zero) ;
SetParent(proc.MainWindowHandle, trackerPanel.Handle);
MoveWindow(proc.MainWindowHandle, 0, 0, this.Width - 90, this.Height, true);
引用这个