You should declare the arrays (si
and pi
) as global variables. Also you can't call the DisplayMenu
from within the process
function (recursion). Here's an example how to fix these problems:
STARTUPINFO si[3];
PROCESS_INFORMATION pi[3];
int DisplayMenu();
void process(int option);
void main()
{
ZeroMemory( &si[0], sizeof(si[0]) );
si[0].cb = sizeof(si[0]);
ZeroMemory( &pi[0], sizeof(pi[0]) );
ZeroMemory( &si[1], sizeof(si[1]) );
si[1].cb = sizeof(si[1]);
ZeroMemory( &pi[1], sizeof(pi[1]) );
ZeroMemory( &si[2], sizeof(si[2]) );
si[2].cb = sizeof(si[2]);
ZeroMemory( &pi[2], sizeof(pi[2]) );
while(DisplayMenu()!=4)
return;
}
int DisplayMenu()
{
int option;
system("cls");
cout << "\n\n\n";
cout << "\n\t*********************************";
cout << "\n\t* *";
cout << "\n\t* MENU *";
cout << "\n\t* *";
cout << "\n\t* 1. FreeCell *";
cout << "\n\t* 2. MineSweeper *";
cout << "\n\t* 3. Paint *";
cout << "\n\t* 4. Quit *";
cout << "\n\t* *";
cout << "\n\t*********************************";
cout << "\n\nPlease type your choice "
<< "and press the return key : ";
cin >> option;
process(option);
return option;
}
void process(int option)
{
switch (option)
{
case 1 : if(pi[0].hProcess==NULL)CreateProcess( NULL,
"FreeCell.exe",
NULL,
NULL,
FALSE,
NULL,
NULL,
NULL,
&si[0],
&pi[0]);
break;
case 2 : if(pi[1].hProcess==NULL)CreateProcess( NULL,
"winmine.exe",
NULL,
NULL,
FALSE,
NULL,
NULL,
NULL,
&si[1],
&pi[1]);
break;
case 3 : if(pi[2].hProcess==NULL)CreateProcess( NULL,
"MsPaint.exe", // Command line.
NULL,
NULL,
FALSE,
NULL,
NULL,
NULL,
&si[2],
&pi[2]);
break;
case 4 : if(pi[0].hProcess)::PostThreadMessage(pi[0].dwThreadId,WM_QUIT,0,0);
if(pi[1].hProcess)::PostThreadMessage(pi[1].dwThreadId,WM_QUIT,0,0);
if(pi[2].hProcess)::PostThreadMessage(pi[2].dwThreadId,WM_QUIT,0,0);
CloseHandle( pi[0].hProcess );
CloseHandle( pi[0].hThread );
CloseHandle( pi[1].hProcess );
CloseHandle( pi[1].hThread );
CloseHandle( pi[2].hProcess );
CloseHandle( pi[2].hThread );
// CloseHandle( pi[3].hProcess );
// CloseHandle( pi[3].hThread );
break;
default : printf("\a\aOption Not Available\n");
break;
}
return;
}
Regards, Andrzej Markowski
My Latest Articles