#include"tlhelp32.h"DWORDGetProcessIdFromName(LPCWSTRname){PROCESSENTRY32pe;DWORDid=0;HANDLEhSnapshot=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);pe.dwSize=sizeof(PROCESSENTRY32);if(!Process32First(hSnapshot,&pe))return0;while(1){pe.dwSize=sizeof(PROCESSENTRY32);if(Process32Next(hSnapshot,&pe)==FALSE)break;if(wcscmp(pe.szExeFile,name)==0){id=pe.th42ProcessID;break;}}CloseHandle(hSnapshot);returnid;}voidCMFCApplication1Dlg::OnBnClickedButton27(){INTret=GetProcessIdFromName(_T("notepad.exe"));//获取记事本的进程ID}