欢迎来到代码驿站!

.NET代码

当前位置:首页 > 软件编程 > .NET代码

用C#实现启动另一程序的方法实例

时间:2020-12-30 14:01:48|栏目:.NET代码|点击:
复制代码 代码如下:

  private void btnCreate_Click(object sender, EventArgs e)
  ...{
  int hWnd = FindWindow(null, "test");//窗?w的名?Q
  //check if PowerReuse is launched or not
  //if yes, pass path of project to PowerReuse
  //or, launch PowerReuse with specified parameter
  if (hWnd > 0)
  ...{
  MessageBox.Show("powerReuse has been launched already." + " " + hWnd.ToString());
  //SendMessage to PowerReuse
  return;
  }
  try
  ...{
  Process Main_P = new Process();
  //this path should be retrieved from Windows Registry,
  //the loaction is written by Installter during process of installation.
  Main_P.StartInfo.FileName = @"C: est.exe";//?\行的exe路??
  //This URL is passed to PowerReuse to open
  Main_P.StartInfo.Arguments = @"C:Tempabc.prj";//?\行?r的???
  Main_P.StartInfo.UseShellExecute = true;
  Main_P.Start();
  //
  //we have to wait for a while until UI has been initialized
  //
  Main_P.WaitForInputIdle(10000);
  //although UI has been initialzied,
  //it does not mean main form of application has been completed.
  //we may wait for another 10 seconds
  for (int i = 0; i < 100; i++)
  ...{
  hWnd = FindWindow(null, "PowerReuse (Beta)");
  //hWnd = Main_P.MainWindowHandle.ToInt32() ;
  if (hWnd > 0) break;
  Thread.Sleep(100);
  }
  //Here, we check if PowerReuse is fully launched
  if (hWnd == 0)
  ...{
  //Handle exception
  MessageBox.Show("We cannot find window handle of PowerReuse");
  }
  else
  ...{
  //other handling
  //
  MessageBox.Show(hWnd.ToString() + " " + Main_P.MainWindowHandle.ToString() + " " + Main_P.MainWindowTitle);
  }
  }
  catch (Exception ex)
  ...{
  MessageBox.Show(ex.Message);
  }
  }

上一篇:C#利用正则判断输入是否为纯数字、容器类

栏    目:.NET代码

下一篇:"PageMethods未定义"或"对象不支持此属性或方法"解决方法分享

本文标题:用C#实现启动另一程序的方法实例

本文地址:http://www.codeinn.net/misctech/38388.html

推荐教程

广告投放 | 联系我们 | 版权申明

重要申明:本站所有的文章、图片、评论等,均由网友发表或上传并维护或收集自网络,属个人行为,与本站立场无关。

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:914707363 | 邮箱:codeinn#126.com(#换成@)

Copyright © 2020 代码驿站 版权所有