1void CShowAllProcessDlg::OnGetProcess()
2{
3 // TODO: Add your control notification handler code here
4 HANDLE snapshot;
5 //get the snapshot of process , heap , module , thread
6 snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS , 0);
7 PROCESSENTRY32 processListStr;
8 processListStr.dwSize = sizeof (PROCESSENTRY32);
9 BOOL returnValue;
10 //get the first information of the process
11 returnValue = Process32First (snapshot , &processListStr);
12 m_showlist.DeleteAllItems();
13
14 int i = 0 ;
15 while (returnValue)
16 {
17 m_showlist.InsertItem(i , processListStr.szExeFile , 0);
18 CString s;
19 s.Format("%d" , processListStr.cntThreads);
20 m_showlist.SetItemText(i , 1 ,s);
21 s.Format("%d" , processListStr.th32ParentProcessID);
22 m_showlist.SetItemText(i , 2 , s);
23 s.Format("%d" , processListStr.pcPriClassBase);
24 m_showlist.SetItemText(i , 3 , s);
25
26
27 int memory = processListStr.cntThreads;
28 m_ProcessIndex[i] = processListStr.th32ProcessID;
29 returnValue = Process32Next (snapshot , &processListStr);
30 i++;
31 }
32}
33
34void CShowAllProcessDlg::OnStopProcess()
35{
36 // TODO: Add your control notification handler code here
37 POSITION pos = m_showlist.GetFirstSelectedItemPosition();
38 int currentSelect = m_showlist.GetNextSelectedItem(pos);
39 if (currentSelect > 0)
40 {
41 //选择某项
42 CString FileBuffer;
43 FileBuffer = CString (TEXT("确实要终止进程") + m_showlist.GetItemText(currentSelect,0) +
44 TEXT("?"));
45
46 if (AfxMessageBox(FileBuffer , MB_OKCANCEL , 0) == IDOK)
47 {
48 HANDLE ProcessHandle;
49 ProcessHandle = OpenProcess(PROCESS_ALL_ACCESS , FALSE , m_ProcessIndex[currentSelect]);
50 if (ProcessHandle)
51 {
52 //Terminate the process
53 TerminateProcess(ProcessHandle , 0);
54 AfxMessageBox("指定的进程已经终止!");
55 //flush
56 OnGetProcess();
57 }
58 else
59 {
60 AfxMessageBox("系统不允许终止指定的进程!");
61 }
62 }
63 }
64 else
65 {
66 AfxMessageBox("请选择一个要终止的进程!" , MB_OK);
67 }
68}
69
2{
3 // TODO: Add your control notification handler code here
4 HANDLE snapshot;
5 //get the snapshot of process , heap , module , thread
6 snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS , 0);
7 PROCESSENTRY32 processListStr;
8 processListStr.dwSize = sizeof (PROCESSENTRY32);
9 BOOL returnValue;
10 //get the first information of the process
11 returnValue = Process32First (snapshot , &processListStr);
12 m_showlist.DeleteAllItems();
13
14 int i = 0 ;
15 while (returnValue)
16 {
17 m_showlist.InsertItem(i , processListStr.szExeFile , 0);
18 CString s;
19 s.Format("%d" , processListStr.cntThreads);
20 m_showlist.SetItemText(i , 1 ,s);
21 s.Format("%d" , processListStr.th32ParentProcessID);
22 m_showlist.SetItemText(i , 2 , s);
23 s.Format("%d" , processListStr.pcPriClassBase);
24 m_showlist.SetItemText(i , 3 , s);
25
26
27 int memory = processListStr.cntThreads;
28 m_ProcessIndex[i] = processListStr.th32ProcessID;
29 returnValue = Process32Next (snapshot , &processListStr);
30 i++;
31 }
32}
33
34void CShowAllProcessDlg::OnStopProcess()
35{
36 // TODO: Add your control notification handler code here
37 POSITION pos = m_showlist.GetFirstSelectedItemPosition();
38 int currentSelect = m_showlist.GetNextSelectedItem(pos);
39 if (currentSelect > 0)
40 {
41 //选择某项
42 CString FileBuffer;
43 FileBuffer = CString (TEXT("确实要终止进程") + m_showlist.GetItemText(currentSelect,0) +
44 TEXT("?"));
45
46 if (AfxMessageBox(FileBuffer , MB_OKCANCEL , 0) == IDOK)
47 {
48 HANDLE ProcessHandle;
49 ProcessHandle = OpenProcess(PROCESS_ALL_ACCESS , FALSE , m_ProcessIndex[currentSelect]);
50 if (ProcessHandle)
51 {
52 //Terminate the process
53 TerminateProcess(ProcessHandle , 0);
54 AfxMessageBox("指定的进程已经终止!");
55 //flush
56 OnGetProcess();
57 }
58 else
59 {
60 AfxMessageBox("系统不允许终止指定的进程!");
61 }
62 }
63 }
64 else
65 {
66 AfxMessageBox("请选择一个要终止的进程!" , MB_OK);
67 }
68}
69