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

雪夜残血痛谁知

雪夜残血痛谁知

2016-02-19 13:48

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

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

(本文来源于图老师网站,更多请访问https://m.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://m.tulaoshi.com/bianchengyuyan/)
展开更多 50%)
分享

猜你喜欢

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

编程语言 网络编程
在C#中启动另一个程序的实现方法

在C#程序中实现插件架构

编程语言 网络编程
在C#程序中实现插件架构

s8lol主宰符文怎么配

英雄联盟 网络游戏
s8lol主宰符文怎么配

从一个程序中生成另一个程序(资源法)

编程语言 网络编程
从一个程序中生成另一个程序(资源法)

城市的另一个角度

平面设计 海报设计 广告设计 画报设计 签名设计 服装设计 名片设计 画册设计 版式设计 商标设计
城市的另一个角度

lol偷钱流符文搭配推荐

英雄联盟 网络游戏
lol偷钱流符文搭配推荐

将count(*)值写入另一个表中的方法

编程语言 网络编程
将count(*)值写入另一个表中的方法

WinXP中的另一个还原专家揭秘

windows 操作系统
WinXP中的另一个还原专家揭秘

lolAD刺客新符文搭配推荐

英雄联盟
lolAD刺客新符文搭配推荐

qq用过的头像怎么找回?

qq用过的头像怎么找回?

C#中的委托和事件

C#中的委托和事件
下拉加载更多内容 ↓