#include"tlhelp32.h" DWORD GetProcessIdFromName(LPCWSTR name) { PROCESSENTRY32 pe; DWORD id = 0; HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); pe.dwSize = sizeof(PROCESSENTRY32); if (!Process32First(hSnapshot, &pe)) return 0; while (1) { pe.dwSize = sizeof(PROCESSENTRY32); if (Process32Next(hSnapshot, &pe) == FALSE) break; if (wcscmp(pe.szExeFile, name) == 0) { id = pe.th42ProcessID; break; } } CloseHandle(hSnapshot); return id; } void CMFCApplication1Dlg::OnBnClickedButton27() { INT ret = GetProcessIdFromName(_T("notepad.exe") );//获取记事本的进程ID }
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。