33f297cf02bfcf4ebc3bc087611bb7db3e521f4b
[reactos.git] / reactos / base / applications / taskmgr / endproc.c
1 /*
2 * ReactOS Task Manager
3 *
4 * endproc.cpp
5 *
6 * Copyright (C) 1999 - 2001 Brian Palmer <brianp@reactos.org>
7 * 2005 Klemens Friedl <frik85@reactos.at>
8 *
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
13 *
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 */
23
24 #include <precomp.h>
25
26 void ProcessPage_OnEndProcess(void)
27 {
28 LVITEM lvitem;
29 ULONG Index;
30 DWORD dwProcessId;
31 HANDLE hProcess;
32 WCHAR szTitle[256];
33 WCHAR strErrorText[260];
34
35 for (Index=0; Index<(ULONG)ListView_GetItemCount(hProcessPageListCtrl); Index++)
36 {
37 memset(&lvitem, 0, sizeof(LVITEM));
38
39 lvitem.mask = LVIF_STATE;
40 lvitem.stateMask = LVIS_SELECTED;
41 lvitem.iItem = Index;
42
43 (void)ListView_GetItem(hProcessPageListCtrl, &lvitem);
44
45 if (lvitem.state & LVIS_SELECTED)
46 break;
47 }
48
49 dwProcessId = PerfDataGetProcessId(Index);
50
51 if ((ListView_GetSelectedCount(hProcessPageListCtrl) != 1) || (dwProcessId == 0))
52 return;
53
54 LoadStringW(hInst, IDS_MSG_WARNINGTERMINATING, strErrorText, 256);
55 LoadStringW(hInst, IDS_MSG_TASKMGRWARNING, szTitle, 256);
56 if (MessageBoxW(hMainWnd, strErrorText, szTitle, MB_YESNO|MB_ICONWARNING) != IDYES)
57 return;
58
59 hProcess = OpenProcess(PROCESS_TERMINATE, FALSE, dwProcessId);
60
61 if (!hProcess)
62 {
63 GetLastErrorText(strErrorText, 260);
64 LoadStringW(hInst, IDS_MSG_UNABLETERMINATEPRO, szTitle, 256);
65 MessageBoxW(hMainWnd, strErrorText, szTitle, MB_OK|MB_ICONSTOP);
66 return;
67 }
68
69 if (!TerminateProcess(hProcess, 0))
70 {
71 GetLastErrorText(strErrorText, 260);
72 LoadStringW(hInst, IDS_MSG_UNABLETERMINATEPRO, szTitle, 256);
73 MessageBoxW(hMainWnd, strErrorText, szTitle, MB_OK|MB_ICONSTOP);
74 }
75
76 CloseHandle(hProcess);
77 }
78
79 void ProcessPage_OnEndProcessTree(void)
80 {
81 LVITEM lvitem;
82 ULONG Index;
83 DWORD dwProcessId;
84 HANDLE hProcess;
85 WCHAR szTitle[256];
86 WCHAR strErrorText[260];
87
88 for (Index=0; Index<(ULONG)ListView_GetItemCount(hProcessPageListCtrl); Index++)
89 {
90 memset(&lvitem, 0, sizeof(LVITEM));
91
92 lvitem.mask = LVIF_STATE;
93 lvitem.stateMask = LVIS_SELECTED;
94 lvitem.iItem = Index;
95
96 (void)ListView_GetItem(hProcessPageListCtrl, &lvitem);
97
98 if (lvitem.state & LVIS_SELECTED)
99 break;
100 }
101
102 dwProcessId = PerfDataGetProcessId(Index);
103
104 if ((ListView_GetSelectedCount(hProcessPageListCtrl) != 1) || (dwProcessId == 0))
105 return;
106
107 LoadStringW(hInst, IDS_MSG_WARNINGTERMINATING, strErrorText, 256);
108 LoadStringW(hInst, IDS_MSG_TASKMGRWARNING, szTitle, 256);
109 if (MessageBoxW(hMainWnd, strErrorText, szTitle, MB_YESNO|MB_ICONWARNING) != IDYES)
110 return;
111
112 hProcess = OpenProcess(PROCESS_TERMINATE, FALSE, dwProcessId);
113
114 if (!hProcess)
115 {
116 GetLastErrorText(strErrorText, 260);
117 LoadStringW(hInst, IDS_MSG_UNABLETERMINATEPRO, szTitle, 256);
118 MessageBoxW(hMainWnd, strErrorText, szTitle, MB_OK|MB_ICONSTOP);
119 return;
120 }
121
122 if (!TerminateProcess(hProcess, 0))
123 {
124 GetLastErrorText(strErrorText, 260);
125 LoadStringW(hInst, IDS_MSG_UNABLETERMINATEPRO, szTitle, 256);
126 MessageBoxW(hMainWnd, strErrorText, szTitle, MB_OK|MB_ICONSTOP);
127 }
128
129 CloseHandle(hProcess);
130 }