国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > C# > 正文

在C#中啟動另一個程序的實現方法

2023-05-18 12:33:08
字體:
來源:轉載
供稿:網友

在本網站中曾經探討過在C#程序中啟動外部程序的方法,在這里有另一種方法同樣可以啟動外部的程序。

程序的目的是使用C#實現啟動另一程序的方法。技術總監給出了我們這樣一個有效的啟動程序的有效方法,大家分享下:

 

以下是引用片段:
  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);
  }
  }
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 漳平市| 科技| 聂荣县| 龙胜| 丹江口市| 双桥区| 桂林市| 丰城市| 海伦市| 桐梓县| 临高县| 攀枝花市| 石柱| 普安县| 滨州市| 辽阳市| 许昌市| 洞口县| 忻城县| 阜阳市| 玛多县| 从化市| 务川| 墨竹工卡县| 奈曼旗| 且末县| 东宁县| 肇源县| 方正县| 家居| 元江| 安多县| 遂川县| 顺平县| 渭南市| 忻州市| 吉水县| 霞浦县| 丽水市| 柘城县| 丽水市|