winedbg: Fix "floating pointer" typo.
[wine] / programs / taskmgr / endproc.c
1 /*
2  *  ReactOS Task Manager
3  *
4  *  endproc.c
5  *
6  *  Copyright (C) 1999 - 2001  Brian Palmer  <brianp@reactos.org>
7  *
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.
12  *
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.
17  *
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21  */
22     
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>
32     
33 #include "taskmgr.h"
34 #include "perfdata.h"
35
36 void ProcessPage_OnEndProcess(void)
37 {
38     LVITEM            lvitem;
39     ULONG            Index;
40     DWORD            dwProcessId;
41     HANDLE            hProcess;
42     TCHAR            strErrorText[260];
43
44     for (Index=0; Index<(ULONG)ListView_GetItemCount(hProcessPageListCtrl); Index++)
45     {
46         lvitem.mask = LVIF_STATE;
47         lvitem.stateMask = LVIS_SELECTED;
48         lvitem.iItem = Index;
49         lvitem.iSubItem = 0;
50
51         SendMessage(hProcessPageListCtrl, LVM_GETITEM, 0, (LPARAM) &lvitem);
52
53         if (lvitem.state & LVIS_SELECTED)
54             break;
55     }
56
57     dwProcessId = PerfDataGetProcessId(Index);
58
59     if ((ListView_GetSelectedCount(hProcessPageListCtrl) != 1) || (dwProcessId == 0))
60         return;
61
62     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)
63         return;
64
65     hProcess = OpenProcess(PROCESS_TERMINATE, FALSE, dwProcessId);
66
67     if (!hProcess)
68     {
69         GetLastErrorText(strErrorText, 260);
70         MessageBox(hMainWnd, strErrorText, _T("Unable to Terminate Process"), MB_OK|MB_ICONSTOP);
71         return;
72     }
73
74     if (!TerminateProcess(hProcess, 0))
75     {
76         GetLastErrorText(strErrorText, 260);
77         MessageBox(hMainWnd, strErrorText, _T("Unable to Terminate Process"), MB_OK|MB_ICONSTOP);
78     }
79
80     CloseHandle(hProcess);
81 }
82
83 void ProcessPage_OnEndProcessTree(void)
84 {
85     LVITEM            lvitem;
86     ULONG            Index;
87     DWORD            dwProcessId;
88     HANDLE            hProcess;
89     TCHAR            strErrorText[260];
90
91     for (Index=0; Index<(ULONG)ListView_GetItemCount(hProcessPageListCtrl); Index++)
92     {
93         lvitem.mask = LVIF_STATE;
94         lvitem.stateMask = LVIS_SELECTED;
95         lvitem.iItem = Index;
96         lvitem.iSubItem = 0;
97
98         SendMessage(hProcessPageListCtrl, LVM_GETITEM, 0, (LPARAM) &lvitem);
99
100         if (lvitem.state & LVIS_SELECTED)
101             break;
102     }
103
104     dwProcessId = PerfDataGetProcessId(Index);
105
106     if ((ListView_GetSelectedCount(hProcessPageListCtrl) != 1) || (dwProcessId == 0))
107         return;
108
109     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)
110         return;
111
112     hProcess = OpenProcess(PROCESS_TERMINATE, FALSE, dwProcessId);
113
114     if (!hProcess)
115     {
116         GetLastErrorText(strErrorText, 260);
117         MessageBox(hMainWnd, strErrorText, _T("Unable to Terminate Process"), MB_OK|MB_ICONSTOP);
118         return;
119     }
120
121     if (!TerminateProcess(hProcess, 0))
122     {
123         GetLastErrorText(strErrorText, 260);
124         MessageBox(hMainWnd, strErrorText, _T("Unable to Terminate Process"), MB_OK|MB_ICONSTOP);
125     }
126
127     CloseHandle(hProcess);
128 }