Click here to Skip to main content
15,925,255 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionHow do I record sound using DirectSound? Pin
mpallavi10-Apr-05 22:34
mpallavi10-Apr-05 22:34 
AnswerRe: How do I record sound using DirectSound? Pin
Tareq Ahmed Siraj10-Apr-05 23:22
Tareq Ahmed Siraj10-Apr-05 23:22 
GeneralInstaller Pin
topeakinniyi10-Apr-05 22:20
topeakinniyi10-Apr-05 22:20 
QuestionXML file traversal ???? Pin
Ritu Kwatra10-Apr-05 21:27
Ritu Kwatra10-Apr-05 21:27 
AnswerRe: XML file traversal ???? Pin
ThatsAlok10-Apr-05 22:37
ThatsAlok10-Apr-05 22:37 
GeneralRe: XML file traversal ???? Pin
Ritu Kwatra10-Apr-05 23:01
Ritu Kwatra10-Apr-05 23:01 
GeneralRe: XML file traversal ???? Pin
ThatsAlok10-Apr-05 23:17
ThatsAlok10-Apr-05 23:17 
GeneralRe: XML file traversal ???? Pin
Ritu Kwatra10-Apr-05 23:27
Ritu Kwatra10-Apr-05 23:27 
GeneralRe: XML file traversal ???? Pin
Ritu Kwatra10-Apr-05 23:33
Ritu Kwatra10-Apr-05 23:33 
GeneralRe: XML file traversal ???? Pin
ThatsAlok10-Apr-05 23:37
ThatsAlok10-Apr-05 23:37 
GeneralRe: XML file traversal ???? Pin
Ritu Kwatra10-Apr-05 23:53
Ritu Kwatra10-Apr-05 23:53 
GeneralRe: XML file traversal ???? Pin
ThatsAlok11-Apr-05 0:06
ThatsAlok11-Apr-05 0:06 
Generalvisual studio add-in & edit box Pin
sumo6910-Apr-05 21:26
sumo6910-Apr-05 21:26 
GeneralHelp me to kill running bugs .... Pin
Sreekanth Muralidharan10-Apr-05 19:07
Sreekanth Muralidharan10-Apr-05 19:07 
GeneralRe: Help me to kill running bugs .... Pin
oustar10-Apr-05 19:22
oustar10-Apr-05 19:22 
GeneralRe: Help me to kill running bugs .... Pin
Sreekanth Muralidharan10-Apr-05 21:31
Sreekanth Muralidharan10-Apr-05 21:31 
GeneralRe: Help me to kill running bugs .... Pin
ThatsAlok10-Apr-05 20:29
ThatsAlok10-Apr-05 20:29 
GeneralRe: Help me to kill running bugs .... Pin
Sreekanth Muralidharan10-Apr-05 21:33
Sreekanth Muralidharan10-Apr-05 21:33 
GeneralShellApi Pin
emilie560210-Apr-05 18:35
emilie560210-Apr-05 18:35 
QuestionHow to Convert BYTE * to byte[] Pin
DeepToot10-Apr-05 18:08
DeepToot10-Apr-05 18:08 
AnswerRe: How to Convert BYTE * to byte[] Pin
DeepToot12-Apr-05 8:53
DeepToot12-Apr-05 8:53 
GeneralCSliderCtrl + dblclick Pin
Chris Losinger10-Apr-05 15:39
professionalChris Losinger10-Apr-05 15:39 
Generalmenu and sub menu Pin
mpapeo10-Apr-05 12:31
mpapeo10-Apr-05 12:31 
I want to create a submenu which uses the case statements. So my problem is the program crushes and i can't get the logic how i can arrange the case statements. Please help me, i am already under pressure because of time.
I want the program run such that if i enter option 1 it create a process and then produce which i can now suspend the process from there or shut it down in the submenu
Here is my code
<br />
#include <windows.h><br />
#include <stdio.h><br />
#include <windef.h><br />
#include <winbase.h><br />
#include <imagehlp.h><br />
#include <stdlib.h><br />
#include <ctype.h><br />
typedef struct _iobuf FILE;<br />
#include <assert.h><br />
#include <sys/types.h><br />
#include <sys/stat.h><br />
<br />
int menu(void)<br />
{<br />
char iobuf[80];<br />
int choice;<br />
int i,len,valid;<br />
//HANDLE hProcess;<br />
printf ("\n");<br />
printf ("*****************************************\n");<br />
printf ("*\t\t\t\t\t*\n*\tPROCESS CREATION \t\t*\n");<br />
printf ("=========================================");<br />
printf ("\n=\t 1: Create a process \t\t=");<br />
printf ("\n=\t 2: Quit the system\t\t=");<br />
printf ("\n=========================================\n");<br />
valid=0;<br />
printf("\nEnter choice (1-3): ");<br />
   <br />
   while( valid == 0)<br />
   {<br />
     fgets(iobuf,sizeof(iobuf),stdin);<br />
     // remove '\n' <br />
     len = strlen(iobuf)-1;<br />
     iobuf[len] = 0;<br />
     // validate data<br />
     valid = 1; // assume valid input<br />
     for(i = 0; i < len; i++)<br />
     {<br />
         if( !isdigit(iobuf[i]))<br />
         {<br />
           printf("\nPlese enter numeric digits only (1-5)\n");<br />
           valid = 0;<br />
         }<br />
      }<br />
   }<br />
  choice = atoi(iobuf);<br />
<br />
	return choice; <br />
 }<br />
<br />
int submenu(void)<br />
{<br />
char iobuf[80];<br />
int choice2;<br />
int i,len,valid;<br />
//HANDLE hProcess;<br />
<br />
PROCESS_INFORMATION pi;       /* filled in by CreateProcess */<br />
	STARTUPINFO si;               /* startup info for the new process*/<br />
	HANDLE hProcess;<br />
	DWORD lpAddr = 0;<br />
	TCHAR lpApplicationName[_MAX_PATH]="";	<br />
	int result;<br />
char ans [4]="";<br />
//int choice;<br />
<br />
printf ("\n*****************************************\n");<br />
printf ("*\t\t\t\t\t*\n*\tPROCESS CREATION \t\t*\n");<br />
printf ("=========================================");<br />
printf ("\n=\t 1: Suspend the process\t\t=");<br />
printf ("\n=\t 2: Resume process \t=");<br />
printf ("\n=\t 3: Shutdown the process \t=");<br />
printf ("\n=\t 4: Exit the system \t=");<br />
printf ("\n=========================================\n");<br />
printf ("\n");<br />
valid=0;<br />
printf("\nEnter choice (1-4): ");   <br />
   while( valid == 0)<br />
   {<br />
     fgets(iobuf,sizeof(iobuf),stdin);<br />
     // remove '\n' <br />
     len = strlen(iobuf)-1;<br />
     iobuf[len] = 0;<br />
     // validate data<br />
     valid = 1; // assume valid input<br />
     for(i = 0; i < len; i++)<br />
     {<br />
         if( !isdigit(iobuf[i]))<br />
         {<br />
           printf("\nPlese enter numeric digits only (1-4)\n");<br />
           valid = 0;<br />
         }<br />
      }<br />
   }<br />
while((choice2 = submenu())!=3)//int choice;<br />
{<br />
switch (choice2)<br />
{<br />
case 1:<br />
		SuspendThread(pi.hThread);// identifies thread to suspend	<br />
break;<br />
case 2:<br />
	ResumeThread(pi.hThread);		<br />
break;<br />
case 3:<br />
	printf("\nYou are about to terminate a running process, do you want to continue ( y or n) ");<br />
		scanf ("%s",ans);	<br />
		result = strcmp(ans,"y");<br />
		if (result==0)<br />
		{<br />
		TerminateProcess(pi.hThread, 0);//identifies the process to terminate<br />
		GetLastError();<br />
		}<br />
	break;<br />
default: printf("Invalid choice: ");<br />
<br />
 }}<br />
  choice2 = atoi(iobuf);<br />
	return choice2; <br />
valid = 0;<br />
}//submenu<br />
<br />
int main(int argc, char **argv) <br />
{<br />
	PROCESS_INFORMATION pi;    /* filled in by CreateProcess */<br />
	STARTUPINFO si;             /* startup info for the new process*/<br />
	HANDLE hProcess;<br />
	DWORD lpAddr = 0;<br />
	TCHAR lpApplicationName[_MAX_PATH]="";	<br />
	int result;<br />
char ans [4]="";<br />
int choice;<br />
while((choice = menu())!=6)//int choice;<br />
{<br />
switch (choice)<br />
{<br />
case 1: <br />
	GetStartupInfo(&si);<br />
lpAddr = 0;<br />
	ZeroMemory( &si, sizeof(si) );<br />
	si.cb = sizeof(si);<br />
	ZeroMemory( &pi, sizeof(pi) );<br />
printf("Enter process you want to execute: ",lpApplicationName);<br />
scanf ("%s",lpApplicationName);<br />
printf("Process %d reporting for creation\n",GetCurrentProcessId());//print out our process ID<br />
<br />
CreateProcess(NULL, /* lpApplicationName */<br />
lpApplicationName, /* lpCommandLine assumes to use curent process directory*/<br />
NULL, /* lpsaProcess */<br />
NULL, /* lpsaThread */<br />
FALSE, /* bInheritHandles */<br />
CREATE_NEW_CONSOLE, /* dwCreationFlags */<br />
NULL, /* lpEnvironment */<br />
NULL, /* lpCurDir */<br />
&si, /* lpStartupInfo */<br />
&pi /* lpProcInfo */<br />
); <br />
hProcess = pi.hProcess;<br />
printf("New Process ID: %d ",pi.dwProcessId);<br />
submenu();<br />
<br />
break;<br />
case 2:<br />
printf("\n\tAre you sure you want to quit the system!(y or n) ");<br />
scanf ("%s",ans);<br />
					<br />
result = strcmp(ans,"y");//comparing the input and y to quit<br />
				<br />
if (result==0)<br />
					<br />
{<br />
TerminateProcess(pi.hProcess, 0);//identifies the process to terminate<br />
GetLastError();<br />
exit(EXIT_SUCCESS);		//exiting the console<br />
}GetLastError();	<br />
break;	<br />
default:<br />
printf("\nInvalid choice: ");<br />
}<br />
}<br />
return (0);<br />
}<br />

GeneralRe: menu and sub menu Pin
Christian Graus10-Apr-05 13:57
protectorChristian Graus10-Apr-05 13:57 
GeneralRe: menu and sub menu Pin
mpapeo10-Apr-05 15:17
mpapeo10-Apr-05 15:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.