求助,如何把调用的外部程序限定在窗体内.

flien1 2010-09-02 05:58:49
我写了一个Form程序,可以记录外部程序的地址然后运行,现在有个想法.能不能在调用外部程序时候把程序限定在我的form内
比如,我的form1调用了QQ应用程序,然后我要的效果是,qq在我的form1里面打开,如图mdi子窗体一样.
...全文
78 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
wuyq11 2010-09-03
  • 打赏
  • 举报
回复

[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 = "";//设程序的父窗口
p.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Minimized; p.Start();
System.Threading.Thread.Sleep(100);// SetParent(p.MainWindowHandle, this.Handle);
ShowWindow(p.MainWindowHandle, 3);

}
flien1 2010-09-03
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 computerfox 的回复:]
参考:

C# code
[DllImport("User32.dll ", EntryPoint = "SetParent")]
private static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
[DllImport("user32.dll ", EntryPoint = "ShowWindo……
[/Quote]
只支持dos窗体么?
gomoku 2010-09-02
  • 打赏
  • 举报
回复
玩玩的话可以用SetParent API
http://msdn.microsoft.com/zh-cn/library/ms633541(VS.85).aspx
缭绕飘渺 2010-09-02
  • 打赏
  • 举报
回复
这个问题我以前也问过了
基本是不可能实现的
因为其他的程序已经是一个多窗体的东西
想限制不容易
dos命令行的窗体好像可以
捷哥1999 2010-09-02
  • 打赏
  • 举报
回复
参考:
[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);

}


上面的代码实现了用Process类启动外部exe程序,然后嵌在Form中。

110,534

社区成员

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

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

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