关闭记事本为例子

HANDLE hProcessHandle;
ULONG nProcessID;
CWnd *theWindow = NULL;
theWindow = FindWindow(NULL,L"无标题 - 记事本");
if (NULL == theWindow)
{
return;
}
GetWindowThreadProcessId(theWindow->GetSafeHwnd(),&nProcessID);
hProcessHandle = OpenProcess(PROCESS_TERMINATE,false,nProcessID);
TerminateProcess(hProcessHandle,4);