时间:2021-05-19
复制代码 代码如下:
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);
}
}
声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。
本文实例讲述了C#实现软件监控外部程序运行状态的方法。分享给大家供大家参考。具体方法如下:需要外挂一个程序,用于监控另一个程序运行状态,一旦检测到另一程序关闭,
本文实例讲述了C#实现程序开机启动的方法。分享给大家供大家参考,具体如下://此方法把启动项加载到注册表中//获得应用程序路径stringstrAssName=
本文实例讲述了C#实现将应用程序设置为开机启动的方法。分享给大家供大家参考。具体如下:privatevoidWriteRegistry(){stringstrN
本文和大家讲一下如何使用C#来创建系统中只能有该程序的一个实例运行。要实现程序的互斥,通常有下面几种方式,下面用C#语言来实现:方法一:使用线程互斥变量.通过定
有时我们需要在C#程序中启动外部的程序,这如何实现呢?我们可以借助System.Diagnostics.Process提供的Start方法来实现,下面用3个例子