关于父窗口和子窗口

junhao_1022 2007-07-02 11:04:35
运行时在窗体Form1里打开一个应用程序,比如notepad.exe,这样notepad的窗体就在窗体Form1前面。如果我单击窗体Form1时,则notepad窗体就退到窗体Form1的后面了。


我想实现的是,单击Form1的时候,notepad窗体要么最小化在Form1上,要么只能先把notepad窗体关掉,再显示Form1。

...全文
218 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
hamehameha 2007-07-02
  • 打赏
  • 举报
回复
要外部程序是模式化的阿,好像比较麻烦。
wuhq030710914 2007-07-02
  • 打赏
  • 举报
回复
Form2 f2=new Form2 ();
f2.ShowDialog();
wuhq030710914 2007-07-02
  • 打赏
  • 举报
回复
在Form1中用showdailog打开另一个窗体(Form2)
神奇的章鱼哥 2007-07-02
  • 打赏
  • 举报
回复
蛮麻烦的,等高手来吧
jjhlover 2007-07-02
  • 打赏
  • 举报
回复
帮顶,学习
jjhlover 2007-07-02
  • 打赏
  • 举报
回复
帮顶,学习
jjhlover 2007-07-02
  • 打赏
  • 举报
回复
帮顶,学习
junhao_1022 2007-07-02
  • 打赏
  • 举报
回复
to hbxtlhx(平民百姓-自已动手,丰衣足食):

System.Diagnostics.ProcessStartInfo ps = new System.Diagnostics.ProcessStartInfo(fullFileName);
System.Diagnostics.Process p = new System.Diagnostics.Process();
p.StartInfo = ps;
ps.WorkingDirectory = @fileDirectory;
p.Start();

p.WaitForInputIdle();
SetParent(p.MainWindowHandle.ToInt32(), this.Handle.ToInt32());

现在能把Microsoft os自己的应用程序,比如notepad.exe,添加到当前窗体的子窗体中,不过自己安装的程序就不行了。提示说“没有与此对象关联的进程”。

我先前定义了的:
[DllImport("user32")]
public static extern int SetParent(int hWndChild, int hWndNewParent);
北京的雾霾天 2007-07-02
  • 打赏
  • 举报
回复
应该明确这属于两个进程间操作,并不会向同一个进程间那么方便,除非你使用系统的关于窗口的API函数来把打开的其它程序的窗口使用SetParent设置到当前程序的窗口的子窗口.比如:

[DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
public static extern IntPtr SetParent(HandleRef hWnd, HandleRef hWndParent);
junhao_1022 2007-07-02
  • 打赏
  • 举报
回复
System.Diagnostics.ProcessStartInfo ps = new System.Diagnostics.ProcessStartInfo(fullFileName);
System.Diagnostics.Process p = new System.Diagnostics.Process();
p.StartInfo = ps;
ps.WorkingDirectory = @fileDirectory;
p.Start();

p.WaitForInputIdle();
SetParent(p.MainWindowHandle.ToInt32(), this.Handle.ToInt32());

现在能把Microsoft os自己的应用程序,比如notepad.exe,添加到当前窗体的子窗体中,不过自己安装的程序就不行了。提示说“没有与此对象关联的进程”。

110,499

社区成员

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

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

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