* Sync with recent trunk (r52637).
[reactos.git] / base / applications / taskmgr / endproc.c
1 /*
2 * ReactOS Task Manager
3 *
4 * endproc.c
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 */
23
24 #include <precomp.h>
25
26 void ProcessPage_OnEndProcess(void)
27 {
28 DWORD dwProcessId;
29 HANDLE hProcess;
30 WCHAR szTitle[256];
31 WCHAR strErrorText[260];
32
33 dwProcessId = GetSelectedProcessId();
34
35 if (dwProcessId == 0)
36 return;
37
38 LoadStringW(hInst, IDS_MSG_WARNINGTERMINATING, strErrorText, 256);
39 LoadStringW(hInst, IDS_MSG_TASKMGRWARNING, szTitle, 256);
40 if (MessageBoxW(hMainWnd, strErrorText, szTitle, MB_YESNO|MB_ICONWARNING) != IDYES)
41 return;
42
43 hProcess = OpenProcess(PROCESS_TERMINATE, FALSE, dwProcessId);
44
45 if (!hProcess)
46 {
47 GetLastErrorText(strErrorText, 260);
48 LoadStringW(hInst, IDS_MSG_UNABLETERMINATEPRO, szTitle, 256);
49 MessageBoxW(hMainWnd, strErrorText, szTitle, MB_OK|MB_ICONSTOP);
50 return;
51 }
52
53 if (!TerminateProcess(hProcess, 1))
54 {
55 GetLastErrorText(strErrorText, 260);
56 LoadStringW(hInst, IDS_MSG_UNABLETERMINATEPRO, szTitle, 256);
57 MessageBoxW(hMainWnd, strErrorText, szTitle, MB_OK|MB_ICONSTOP);
58 }
59
60 CloseHandle(hProcess);
61 }
62
63 void ProcessPage_OnEndProcessTree(void)
64 {
65 DWORD dwProcessId;
66 HANDLE hProcess;
67 WCHAR szTitle[256];
68 WCHAR strErrorText[260];
69
70 dwProcessId = GetSelectedProcessId();
71
72 if (dwProcessId == 0)
73 return;
74
75 LoadStringW(hInst, IDS_MSG_WARNINGTERMINATING, strErrorText, 256);
76 LoadStringW(hInst, IDS_MSG_TASKMGRWARNING, szTitle, 256);
77 if (MessageBoxW(hMainWnd, strErrorText, szTitle, MB_YESNO|MB_ICONWARNING) != IDYES)
78 return;
79
80 hProcess = OpenProcess(PROCESS_TERMINATE, FALSE, dwProcessId);
81
82 if (!hProcess)
83 {
84 GetLastErrorText(strErrorText, 260);
85 LoadStringW(hInst, IDS_MSG_UNABLETERMINATEPRO, szTitle, 256);
86 MessageBoxW(hMainWnd, strErrorText, szTitle, MB_OK|MB_ICONSTOP);
87 return;
88 }
89
90 if (!TerminateProcess(hProcess, 0))
91 {
92 GetLastErrorText(strErrorText, 260);
93 LoadStringW(hInst, IDS_MSG_UNABLETERMINATEPRO, szTitle, 256);
94 MessageBoxW(hMainWnd, strErrorText, szTitle, MB_OK|MB_ICONSTOP);
95 }
96
97 CloseHandle(hProcess);
98 }