#include "stdafx.h"
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
// TODO: Place code here.
STARTUPINFO siStartupInfo;
PROCESS_INFORMATION piProcessInfo;
memset(&siStartupInfo, 0, sizeof(siStartupInfo));
memset(&piProcessInfo, 0, sizeof(piProcessInfo));
siStartupInfo.cb = sizeof(siStartupInfo);
if(CreateProcess("c:\\windows\\notepad.exe", // Application name
0, // Application arguments
0,
0,
FALSE,
CREATE_DEFAULT_ERROR_MODE,
0,
0, // Working directory
&siStartupInfo,
&piProcessInfo) == FALSE)
// Could not start application -> call 'GetLastError()'
// Wait until application has terminated
WaitForSingleObject(piProcessInfo.hProcess, INFINITE);
MessageBox(NULL, "Hello World", "Hello World", 0);
// Close process and thread handles
::CloseHandle(piProcessInfo.hThread);
::CloseHandle(piProcessInfo.hProcess);
return 0;
}
In the above code I try to make a program that will show a MessageBox when I close the "notepad" but this doesn't happen. The MsgBox and the "notepad" open together. What am I doing wrong?
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
// TODO: Place code here.
STARTUPINFO siStartupInfo;
PROCESS_INFORMATION piProcessInfo;
memset(&siStartupInfo, 0, sizeof(siStartupInfo));
memset(&piProcessInfo, 0, sizeof(piProcessInfo));
siStartupInfo.cb = sizeof(siStartupInfo);
if(CreateProcess("c:\\windows\\notepad.exe", // Application name
0, // Application arguments
0,
0,
FALSE,
CREATE_DEFAULT_ERROR_MODE,
0,
0, // Working directory
&siStartupInfo,
&piProcessInfo) == FALSE)
// Could not start application -> call 'GetLastError()'
// Wait until application has terminated
WaitForSingleObject(piProcessInfo.hProcess, INFINITE);
MessageBox(NULL, "Hello World", "Hello World", 0);
// Close process and thread handles
::CloseHandle(piProcessInfo.hThread);
::CloseHandle(piProcessInfo.hProcess);
return 0;
}
In the above code I try to make a program that will show a MessageBox when I close the "notepad" but this doesn't happen. The MsgBox and the "notepad" open together. What am I doing wrong?
