Embedding different applications in a Win Form in .NET

北城以北 提交于 2019-12-06 10:43:12

I think you may be looking for the SetParent Windows API call.

To do this, you'd need to import the relevant API call:

[DllImport("user32.dll")]
static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);

Add using directives at the top of the file:

using System.Diagnostics;
using System.Runtime.InteropServices;

Start the external and call SetParent on it (we are using notepad here):

Process notepad = new Process();
ProcessStartInfo psi = new ProcessStartInfo("notepad.exe");
psi.WindowStyle = ProcessWindowStyle.Normal;
notepad.StartInfo = psi;

notepad.Start();
notepad.WaitForInputIdle(3000);            

SetParent(notepad.MainWindowHandle, this.Handle);

This should work, but I've experienced some strange behaviour with it, in general, I would avoid it if possible.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!