[英]How to embed notepad++ in a Windows Form application and how to control it?
My code: 我的代码:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private const int WM_SYSCOMMAND = 274; private const int SC_MAXIMIZE = 61488;
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true, ExactSpelling = true)]
public static extern int SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true, ExactSpelling = true)]
public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
private void button1_Click(object sender, EventArgs e)
{
Process proc;
proc = Process.Start("Notepad++.exe");
proc.WaitForInputIdle();
SetParent(proc.MainWindowHandle,panel1.Handle);
//SendMessage(proc.MainWindowHandle, WM_SYSCOMMAND, SC_MAXIMIZE, 0);
}
}
When I execute notepad.exe
instead of notepad++.exe
, it works fine. 当我执行
notepad.exe
而不是notepad++.exe
,它可以正常工作。 Normal notepad comes inside the panel in the Windows Form
. 普通记事本位于
Windows Form
的面板内部。 But when I use notepad++.exe
, it is not seen inside the panel instead, is opened outside as a different window. 但是,当我使用
notepad++.exe
,它在面板内部不可见,而是作为另一个窗口在外部打开。 I don't want this. 我不要这个 My preference is
notepad++
to be embedded inside panel my Windows Form
, through which, I want to control the notepad++
. 我的首选是将
notepad++
嵌入到Windows Form
面板中,通过该控件我想控制notepad++
。
Add Sleep after setParent it will work. 在setParent之后添加Sleep它将起作用。
SetParent(proc.MainWindowHandle,panel1.Handle); 的setparent(proc.MainWindowHandle,panel1.Handle); Thread.Sleep(500)
Thread.sleep代码(500)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.