111,125
社区成员
发帖
与我相关
我的任务
分享
Form1 form1 = new Form1();
form1.MdiParent = this;
form1.Show();
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Diagnostics;
using System.Threading;
/// <summary>
///
/// </summary>
/// <param name="hChild"></param>
/// <param name="hParent"></param>
/// <returns></returns>
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public extern static IntPtr SetParent(IntPtr hChild, IntPtr hParent);
/// <summary>
///
/// </summary>
/// <param name="lpClassName"></param>
/// <param name="lpWindowName"></param>
/// <returns></returns>
[DllImport("user32.dll", EntryPoint = "FindWindow")]
public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
/// <summary>
/// 将计算器和记事本加入到当前的MDI中
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button2_Click(object sender, EventArgs e)
{
Process ps = new Process();
ps.StartInfo.FileName = "Notepad.exe";
ps.Start();
for (int i = 0; i < 3; i++)
{
Thread.Sleep(1000);
Application.DoEvents();
}
IntPtr Hwnd = FindWindow(null, "无标题 - 记事本");
SetParent(Hwnd, this.Handle);
Process ps1 = new Process();
ps1.StartInfo.FileName = "Calc.exe";
ps1.Start();
for (int i = 0; i < 3; i++)
{
Thread.Sleep(1000);
Application.DoEvents();
}
IntPtr Hwnd1 = FindWindow(null, "计算器");
SetParent(Hwnd1, this.Handle);
}