如何在mdi窗体中运行其他程序

dapeng925 2011-08-22 11:48:42
怎样在一个父窗体中把其他程序(如计算器)作为子窗体运行呢?
...全文
155 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
跟帖的人真多 谁能告诉我 你们有在审题么 人家都说了别的程序

这个好像不能解决啊我也在琢磨这个问题 楼主解决了 支一声啊
sdl2005lyx 2011-08-23
  • 打赏
  • 举报
回复
“别的程序不行”,楼主是指另外的exe,当然不行;如果是dll,是可以的。。。
dapeng925 2011-08-23
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 isjoe 的回复:]
引用楼主 dapeng925 的回复:
怎样在一个父窗体中把其他程序(如计算器)作为子窗体运行呢?


如果只是计算器,还是自己写一个吧。。。。。。。。。
[/Quote]当然不是计算器了。。。。用vb我能实现,c#不行么?
form1.MdiParent=this;这个对自己写的mdi可以,别的程序不行吧。
程序猿CKeen 2011-08-23
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 wnyxy 的回复:]
C# code


Form1 form1 = new Form1();
form1.MdiParent = this;
form1.Show();
[/Quote]+1
wnyxy001 2011-08-23
  • 打赏
  • 举报
回复

Form1 form1 = new Form1();
form1.MdiParent = this;
form1.Show();

isjoe 2011-08-23
  • 打赏
  • 举报
回复
[Quote=引用楼主 dapeng925 的回复:]
怎样在一个父窗体中把其他程序(如计算器)作为子窗体运行呢?
[/Quote]

如果只是计算器,还是自己写一个吧。。。。。。。。。
wnyxy001 2011-08-23
  • 打赏
  • 举报
回复
学习~~~
inttoint 2011-08-23
  • 打赏
  • 举报
回复
回帖加分——用来提问
isjoe 2011-08-23
  • 打赏
  • 举报
回复
发现一个问题,加入的计算器无法正常退出,记事本没事,估计和计算器的窗口样式有关系
isjoe 2011-08-23
  • 打赏
  • 举报
回复
上面的代码我刚写的。。。测试了,没有问题

延迟你自己看着设置,我设置了三秒,也许不需要那么长。。。。。太短的话程序还没有启动,加入MDI会失败
isjoe 2011-08-23
  • 打赏
  • 举报
回复

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);
}
sdl2005lyx 2011-08-22
  • 打赏
  • 举报
回复
设置这个属性

form1.MdiParent=this;//this 为主窗体

111,125

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧