Avoid annoying 'macro redefinition' warnings by defining
[wine.git] / programs / taskmgr / endproc.c
blob13853f6164b8dcbc36888f526ad2d1e6c139bcb2
1 /*
2 * ReactOS Task Manager
4 * endproc.c
6 * Copyright (C) 1999 - 2001 Brian Palmer <brianp@reactos.org>
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #define WIN32_LEAN_AND_MEAN /* Exclude rarely-used stuff from Windows headers */
24 #include <windows.h>
25 #include <commctrl.h>
26 #include <stdlib.h>
27 #include <malloc.h>
28 #include <memory.h>
29 #include <tchar.h>
30 #include <stdio.h>
31 #include <winnt.h>
33 #include "taskmgr.h"
34 #include "perfdata.h"
36 void ProcessPage_OnEndProcess(void)
38 LVITEM lvitem;
39 ULONG Index;
40 DWORD dwProcessId;
41 HANDLE hProcess;
42 TCHAR strErrorText[260];
44 for (Index=0; Index<(ULONG)ListView_GetItemCount(hProcessPageListCtrl); Index++)
46 memset(&lvitem, 0, sizeof(LVITEM));
48 lvitem.mask = LVIF_STATE;
49 lvitem.stateMask = LVIS_SELECTED;
50 lvitem.iItem = Index;
52 ListView_GetItem(hProcessPageListCtrl, &lvitem);
54 if (lvitem.state & LVIS_SELECTED)
55 break;
58 dwProcessId = PerfDataGetProcessId(Index);
60 if ((ListView_GetSelectedCount(hProcessPageListCtrl) != 1) || (dwProcessId == 0))
61 return;
63 if (MessageBox(hMainWnd, _T("WARNING: Terminating a process can cause undesired\nresults including loss of data and system instability. The\nprocess will not be given the chance to save its state or\ndata before it is terminated. Are you sure you want to\nterminate the process?"), _T("Task Manager Warning"), MB_YESNO|MB_ICONWARNING) != IDYES)
64 return;
66 hProcess = OpenProcess(PROCESS_TERMINATE, FALSE, dwProcessId);
68 if (!hProcess)
70 GetLastErrorText(strErrorText, 260);
71 MessageBox(hMainWnd, strErrorText, _T("Unable to Terminate Process"), MB_OK|MB_ICONSTOP);
72 return;
75 if (!TerminateProcess(hProcess, 0))
77 GetLastErrorText(strErrorText, 260);
78 MessageBox(hMainWnd, strErrorText, _T("Unable to Terminate Process"), MB_OK|MB_ICONSTOP);
81 CloseHandle(hProcess);
84 void ProcessPage_OnEndProcessTree(void)
86 LVITEM lvitem;
87 ULONG Index;
88 DWORD dwProcessId;
89 HANDLE hProcess;
90 TCHAR strErrorText[260];
92 for (Index=0; Index<(ULONG)ListView_GetItemCount(hProcessPageListCtrl); Index++)
94 memset(&lvitem, 0, sizeof(LVITEM));
96 lvitem.mask = LVIF_STATE;
97 lvitem.stateMask = LVIS_SELECTED;
98 lvitem.iItem = Index;
100 ListView_GetItem(hProcessPageListCtrl, &lvitem);
102 if (lvitem.state & LVIS_SELECTED)
103 break;
106 dwProcessId = PerfDataGetProcessId(Index);
108 if ((ListView_GetSelectedCount(hProcessPageListCtrl) != 1) || (dwProcessId == 0))
109 return;
111 if (MessageBox(hMainWnd, _T("WARNING: Terminating a process can cause undesired\nresults including loss of data and system instability. The\nprocess will not be given the chance to save its state or\ndata before it is terminated. Are you sure you want to\nterminate the process?"), _T("Task Manager Warning"), MB_YESNO|MB_ICONWARNING) != IDYES)
112 return;
114 hProcess = OpenProcess(PROCESS_TERMINATE, FALSE, dwProcessId);
116 if (!hProcess)
118 GetLastErrorText(strErrorText, 260);
119 MessageBox(hMainWnd, strErrorText, _T("Unable to Terminate Process"), MB_OK|MB_ICONSTOP);
120 return;
123 if (!TerminateProcess(hProcess, 0))
125 GetLastErrorText(strErrorText, 260);
126 MessageBox(hMainWnd, strErrorText, _T("Unable to Terminate Process"), MB_OK|MB_ICONSTOP);
129 CloseHandle(hProcess);