Refresh the current process table with onfresh ()
void OnFresh () {m_number = 0; m_wndList.ResetContent (); HANDLE hSnapshot; hSnapshot = CreateToolhelp32Snapshot (TH32CS_SNAPPROCESS, 0); PROCESSENTRY32 pe; Process32First (hSnapshot, & pe); do {int index = m_wndList.AddString (pe.szExeFile) ; m_wndList.SetItemData (index, pe.th32ProcessID); m_number ;} while (Process32Next (hSnapshot, & pe)); CloseHandle (hSnapshot); GetDlgItem (IDC_STOP) -> EnableWindow (FALSE); UpdateData (FALSE);}
Use void onstop () to stop operation of the specified process
void CSHUTDOWNDlg :: OnStop () {int index = m_wndList.GetCurSel (); DWORD data = m_wndList.GetItemData (index); HANDLE hProcess; hProcess = OpenProcess (PROCESS_TERMINATE, FALSE, data); if (hProcess) TerminateProcess (hProcess, 0 ); Else MessageBox ("This program may have been closed"); SLEEP (500); onfresh ();}