+ -
当前位置:首页 → 问答吧 → WPF下能不能在控件里打开一个新程序?

WPF下能不能在控件里打开一个新程序?

时间:2011-12-08

来源:互联网

目的是在自己的程序中的一个控件里打开另外一个程序,这样那一个程序的位置就会固定在我们自己的控件里,不用两个程序相互切换了。

用winform是可以实现的,代码如下:
C# code

System.Diagnostics.Process.Process p = System.Diagnostics.Process.Start("C:\\Windows\\system32\\notepad.exe"); //notepad");
p.WaitForInputIdle();
SetParent(p.MainWindowHandle, panel1.Handle);
ShowWindowAsync(p.MainWindowHandle, 3);



当然还有缺陷,比如可以把里面的程序移动到边界外等。

现在如果用WPF能否实现相同的功能?目前我无法获取控件的Handle

作者: nomad_aa   发布时间: 2011-12-08

wpf可以实现这样的功能
以下是我 wpf调用winform的应用程序 
 string file = string.Format("{0}G2", System.AppDomain.CurrentDomain.BaseDirectory);
  System.Diagnostics.ProcessStartInfo Info = new System.Diagnostics.ProcessStartInfo();
  Info.FileName = "IVM_DVS_G2.exe";//设置外部程序名
  string ip=dtDvs.Rows[0]["dvsIp"].ToString();
  string port=dtDvs.Rows[0]["port"].ToString();
  string useName=dtDvs.Rows[0]["userName"].ToString();
  string password=dtDvs.Rows[0]["pwd"].ToString();
  string args = ip + ":" + port + ":" + useName + ":" + password;
  Info.Arguments = args; //设置外部程序的启动参数
  Info.WorkingDirectory = file; //设置外部程序工作目录
  try
  {
  System.Diagnostics.Process.Start(Info); //启动外部程序
  }
  catch
  {
  MessagingBox mb = new MessagingBox("配置人脸失败区域失败,请检查G2设备配置程序是否在\\G2目录下", Helper.MessageImage.Information, false);
  mb.ShowDialog();
  }
  但愿对你有帮助

作者: zhang0322yan   发布时间: 2011-12-08