手机
当前位置:查字典教程网 >编程开发 >C#教程 >用C#实现启动另一程序的方法实例
用C#实现启动另一程序的方法实例
摘要:复制代码代码如下:privatevoidbtnCreate_Click(objectsender,EventArgse)...{inthWn...

复制代码 代码如下:

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);

}

}

【用C#实现启动另一程序的方法实例】相关文章:

用C#写的ADSL拨号程序的代码示例

C#缩略图多路径多格式保存的实例

C# 静态变量与静态方法实例研究

使用C# Winform应用程序获取网页源文件的解决方法

C# 获取属性名的方法

c#在控制台输出彩色文字的方法

使用C#实现在屏幕上画图效果的代码实例

自定义实现Json字符串向C#对象转变的方法

C#处理JPEG头信息的方法

c#之利用API函数实现动画窗体的方法详解

精品推荐
分类导航