C#窗体如何嵌套外部程序(cmd.exe)在窗体里显示

cgpu456 2010-05-13 03:31:01

如题:!!!
...全文
1106 33 打赏 收藏 转发到动态 举报
写回复
用AI写文章
33 条回复
切换为时间正序
请发表友善的回复…
发表回复
zly100 2012-09-25
  • 打赏
  • 举报
回复
一定要MARK一下,找了好久
eastalee 2010-07-20
  • 打赏
  • 举报
回复
厉害,我回去试试
deknight 2010-05-14
  • 打赏
  • 举报
回复
mark
cgpu456 2010-05-14
  • 打赏
  • 举报
回复
谢谢大家的帮助了,CSDN里果然是高手好多呀,以后要多在这上面看看,散分了,分不多,12楼有重大功劳,多给呀!!
HELLOWORDC 2010-05-14
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 computerfox 的回复:]
这个问题很多人提过了,目前为止没有一个好的解决方案!
[/Quote]

是不是这样的?
@井九 2010-05-14
  • 打赏
  • 举报
回复
mark
yuanhuiqiao 2010-05-14
  • 打赏
  • 举报
回复
[Quote=引用 12 楼 mngzilin 的回复:]

C# code
[DllImport("User32.dll ", EntryPoint = "SetParent")]
private static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
[DllImport("user32.dll ", EntryPoint = "ShowWindow")]
pub……
[/Quote]
这个可行
Flavoring 2010-05-14
  • 打赏
  • 举报
回复
嗯,和17楼的有点像吧,不过11楼给的可以直接实现输入
wenfeng1 2010-05-14
  • 打赏
  • 举报
回复
学习了 收藏了
捷哥1999 2010-05-14
  • 打赏
  • 举报
回复
[Quote=引用 11 楼 mngzilin 的回复:]

C# code
[DllImport("User32.dll ", EntryPoint = "SetParent")]
private static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
[DllImport("user32.dll ", EntryPo……
[/Quote]
超级棒!海风的方法是对的!终于找到一个可以实现这个效果的方法了!
zhxingway 2010-05-14
  • 打赏
  • 举报
回复
[Quote=引用 12 楼 mngzilin 的回复:]
C# code
[DllImport("User32.dll ", EntryPoint = "SetParent")]
private static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
[DllImport("user32.dll ", EntryPoint = "ShowWindow")]
p……
[/Quote]

哈哈,这个收藏了.
myhope88 2010-05-14
  • 打赏
  • 举报
回复
来学习的
zhangyafei13 2010-05-14
  • 打赏
  • 举报
回复
看下,学习下
只在此山中 2010-05-14
  • 打赏
  • 举报
回复
使用管道获取dos命令的执行结果,然后用多行textbox显示。
qiqishardgel 2010-05-14
  • 打赏
  • 举报
回复
帮顶!
jianuMan 2010-05-13
  • 打赏
  • 举报
回复
[Quote=引用 11 楼 mngzilin 的回复:]
C# code
[DllImport("User32.dll ", EntryPoint = "SetParent")]
private static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
[DllImport("user32.dll ", EntryP……
[/Quote]


验证了一下
这位仁兄的代码可以实现内嵌cmd功能
xk1126 2010-05-13
  • 打赏
  • 举报
回复
学习了!~~~~~~
mngzilin 2010-05-13
  • 打赏
  • 举报
回复
直接看12楼,11楼的别看了。
mngzilin 2010-05-13
  • 打赏
  • 举报
回复
[DllImport("User32.dll ", EntryPoint = "SetParent")]
private static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
[DllImport("user32.dll ", EntryPoint = "ShowWindow")]
public static extern int ShowWindow(IntPtr hwnd, int nCmdShow);
private void button1_Click(object sender, EventArgs e)
{
Process p = new Process();
p.StartInfo.FileName = "cmd.exe ";
p.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Minimized;//加上这句效果更好
p.Start();
System.Threading.Thread.Sleep(100);//加上,100如果效果没有就继续加大

SetParent(p.MainWindowHandle, this.Handle);
ShowWindow(p.MainWindowHandle, 3);

}
加载更多回复(11)

111,125

社区成员

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

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

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