程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 更多關於編程 >> 用C#實現啟動另一程序的方法實例

用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";//咝械膃xe路徑
    //This URL is passed to PowerReuse to open
    Main_P.StartInfo.Arguments = @"C:Tempabc.prj";//咝袝r的參數
    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);
    }
    }

    1. 上一頁:
    2. 下一頁:
    Copyright © 程式師世界 All Rights Reserved