- Apr 15, 2005
- 367
- 0
- 0
Hi all,
I am getting stuck with a piece of code to execute a process and wait for it to close, so found this example:
//-------------Code Start-------------
STARTUPINFO StartInfo; // name structure
PROCESS_INFORMATION ProcInfo; // name structure
memset(&ProcInfo, 0, sizeof(ProcInfo)); // Set up memory block
memset(&StartInfo, 0 , sizeof(StartInfo)); // Set up memory block
StartInfo.cb = sizeof(StartInfo); // Set structure size
int res = CreateProcess(NULL, "c:\\notepad.exe", NULL, NULL, NULL, NULL, NULL, NULL, &StartInfo, &ProcInfo); // starts MyApp
if (res)
{
WaitForSingleObject(ProcInfo.hThread, INFINITE); // wait forever for process to finish
SetFocus(); // Bring back focus
}
MessageDlg("Completed)+")",mtInformation,TMsgDlgButtons() << mbOK, 0);
exit (0);
//-------------Code End-------------
It does open notepad and waits but when I close notepad I recieve this error message:
"Canont focus an invisable or disabled window"
I am a lost and would appricate some help...
FYI I am using Borland C++ Builder 2010 (not my choice!)
Thanks,
James
I am getting stuck with a piece of code to execute a process and wait for it to close, so found this example:
//-------------Code Start-------------
STARTUPINFO StartInfo; // name structure
PROCESS_INFORMATION ProcInfo; // name structure
memset(&ProcInfo, 0, sizeof(ProcInfo)); // Set up memory block
memset(&StartInfo, 0 , sizeof(StartInfo)); // Set up memory block
StartInfo.cb = sizeof(StartInfo); // Set structure size
int res = CreateProcess(NULL, "c:\\notepad.exe", NULL, NULL, NULL, NULL, NULL, NULL, &StartInfo, &ProcInfo); // starts MyApp
if (res)
{
WaitForSingleObject(ProcInfo.hThread, INFINITE); // wait forever for process to finish
SetFocus(); // Bring back focus
}
MessageDlg("Completed)+")",mtInformation,TMsgDlgButtons() << mbOK, 0);
exit (0);
//-------------Code End-------------
It does open notepad and waits but when I close notepad I recieve this error message:
"Canont focus an invisable or disabled window"
I am a lost and would appricate some help...
FYI I am using Borland C++ Builder 2010 (not my choice!)
Thanks,
James