问题描述
我的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);
}
}
当我执行 NOTEPAD.EXE
而不是记事本++。exe文件
,它工作正常。普通记事本自带的面板中的 Windows窗体
里面。但是,当我使用记事本++。exe文件
,它是没有看到,而不是被外界打开了一个不同的窗口中的面板内。我不想这样。我的preference是的Notepad ++
可嵌入在面板我的 Windows窗体
,通过它,我想控制的Notepad ++
。
When I execute notepad.exe
instead of notepad++.exe
, it works fine. Normal notepad comes inside the panel in the Windows Form
. But when I use notepad++.exe
, it is not seen inside the panel instead, is opened outside as a different window. 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++
.
推荐答案
它的setParent工作会后补充睡眠。
Add Sleep after setParent it will work.
的setparent(proc.MainWindowHandle,panel1.Handle);Thread.sleep代码(500)
SetParent(proc.MainWindowHandle,panel1.Handle);Thread.Sleep(500)
这篇关于如何嵌入记事本+ +在Windows窗体应用程序,以及如何控制呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!