当前位置: 移动技术网 > IT编程>开发语言>c# > 用C#实现启动另一程序的方法实例

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

2019年07月18日  | 移动技术网IT编程  | 我要评论
复制代码 代码如下:  private void btncreate_click(object sender, eventargs e)   ...{   int hwnd
复制代码 代码如下:

  private void btncreate_click(object sender, eventargs e)
  ...{
  int hwnd = findwindow(null, "test");//窗體的名稱
  //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";//運行時的參數
  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);
  }
  }

如您对本文有疑问或者有任何想说的,请点击进行留言回复,万千网友为您解惑!

相关文章:

验证码:
移动技术网