在C#中启动另一个程序的实现方法

2016-02-19 13:48 61 1 收藏

只要你有一台电脑或者手机,都能关注图老师为大家精心推荐的在C#中启动另一个程序的实现方法,手机电脑控们准备好了吗?一起看过来吧!

【 tulaoshi.com - 编程语言 】

  一段实例代码,程序的目的是使用C#实现启动另一程序的方法。技术总监給出了我们这样一个有效的启动程序的有效方法,現在和大家分享下:

(本文来源于图老师网站,更多请访问https://www.tulaoshi.com/bianchengyuyan/)

以下是引用片段:
  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);
  }
  }

(本文来源于图老师网站,更多请访问https://www.tulaoshi.com/bianchengyuyan/)

来源:https://www.tulaoshi.com/n/20160219/1605259.html

延伸阅读
标签: windows 操作系统
  在Windo ws中Sfc.exe(系统文件检查器)是用来验证系统文件完整性并修复系统文件的实用工具。在Windows XP中,它的功能更为强大:我们也可以用这个工具来实现还原的功能,Windows XP中“系统文件检查器”可以扫描所有受保护的系统文件以验证其版本,也可以设置文件缓存大小、清除文件缓存及重新填充“%SystemRoot%\System32\Dllcac...
标签: Web开发
[Ctrl+A 全选 注:如需引入外部Js需刷新才能执行]
标签: ASP
       作者:rainbow ASP动网先锋      3.0 选择一个编辑器      尽管我是一个顽固的Notepad狂,但这次我不建议用它编辑源码。原因是你正在与真正的编程语言打交道,使用Notepad编辑源码编译时可能产生大量的错误信息行(C++程序员知道我在说什么。)  &n...
标签: Web开发
看了cragle的《有没有必要将网站Div Css重构?》的文章,有一些想法不说不快,我也在文章的评论里提到曾经开除过两个执着使用div技术的美工,遭到一些朋友的反对,但也有一位技术总监的朋友发帖表示支持,很经典的话就是:做站是给人看的。不是给机器。符合w3c标准又怎么样?。 说到web设计,我是2000年入行的,应该还是有说几句话的份,...
标签: Web开发
1、Iframe: iframe src="top1.html" frameBorder="0" width="900" scrolling="no" height="90"/iframe 2、Behavior的download方式 span id=show/span IE:Download ID="oDownload" STYLE="behavior:url(#default#download)" / script function onDownloadDone(downDate){ showImport.innerHTML=downDate } oDownload.startDownload('b...

经验教程

646

收藏

36
微博分享 QQ分享 QQ空间 手机页面 收藏网站 回到头部