A piece of instance code, the purpose of the program is to useC # Start another program. The Technical Director has provided us with an effective way to start the program. Now I want to share with you:
Private void btnCreate_Click (object sender, EventArgs e) ...{ Int hWnd = FindWindow (null, "test"); // The Name Of The Window body. // 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 shocould be retrieved from Windows Registry, // The loaction is written by Installter during process of installation. Main_P.StartInfo.FileName = @ "C: est.exe"; // The exe path of the runtime. // This URL is passed to PowerReuse to open Main_P.StartInfo.Arguments = @ "C: Tempabc. prj"; // runtime data 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.main1_whandle.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.main1_whandle.tostring () + "" + Main_P.MainWindowTitle ); } } Catch (Exception ex) ...{ MessageBox. Show (ex. Message ); } } |