winedbg: Fix parsing table for ARM disassembler.
[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  *  Copyright (C) 2008  Vladimir Pankratov
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 St, Fifth Floor, Boston, MA 02110-1301, USA
22  */
23
24 #include <stdio.h>
25 #include <stdlib.h>
26
27 #include <windows.h>
28 #include <commctrl.h>
29 #include <winnt.h>
30
31 #include "wine/unicode.h"
32 #include "taskmgr.h"
33 #include "perfdata.h"
34
35 static WCHAR wszWarnMsg[511];
36 static WCHAR wszWarnTitle[255];
37 static WCHAR wszUnable2Terminate[255];
38
39 static void load_message_strings(void)
40 {
41     LoadStringW(hInst, IDS_TERMINATE_MESSAGE, wszWarnMsg, sizeof(wszWarnMsg)/sizeof(WCHAR));
42     LoadStringW(hInst, IDS_TERMINATE_UNABLE2TERMINATE, wszUnable2Terminate, sizeof(wszUnable2Terminate)/sizeof(WCHAR));
43     LoadStringW(hInst, IDS_WARNING_TITLE, wszWarnTitle, sizeof(wszWarnTitle)/sizeof(WCHAR));
44 }
45
46 void ProcessPage_OnEndProcess(void)
47 {
48     LVITEMW          lvitem;
49     ULONG            Index, Count;
50     DWORD            dwProcessId;
51     HANDLE           hProcess;
52     WCHAR            wstrErrorText[256];
53
54     load_message_strings();
55
56     Count = SendMessageW(hProcessPageListCtrl, LVM_GETITEMCOUNT, 0, 0);
57     for (Index=0; Index<Count; Index++)
58     {
59         lvitem.mask = LVIF_STATE;
60         lvitem.stateMask = LVIS_SELECTED;
61         lvitem.iItem = Index;
62         lvitem.iSubItem = 0;
63
64         SendMessageW(hProcessPageListCtrl, LVM_GETITEMW, 0, (LPARAM) &lvitem);
65
66         if (lvitem.state & LVIS_SELECTED)
67             break;
68     }
69
70     Count = SendMessageW(hProcessPageListCtrl, LVM_GETSELECTEDCOUNT, 0, 0);
71     dwProcessId = PerfDataGetProcessId(Index);
72     if ((Count != 1) || (dwProcessId == 0))
73         return;
74
75     if (MessageBoxW(hMainWnd, wszWarnMsg, wszWarnTitle, MB_YESNO|MB_ICONWARNING) != IDYES)
76         return;
77
78     hProcess = OpenProcess(PROCESS_TERMINATE, FALSE, dwProcessId);
79
80     if (!hProcess)
81     {
82         GetLastErrorText(wstrErrorText, sizeof(wstrErrorText)/sizeof(WCHAR));
83         MessageBoxW(hMainWnd, wstrErrorText,wszUnable2Terminate, MB_OK|MB_ICONSTOP);
84         return;
85     }
86
87     if (!TerminateProcess(hProcess, 0))
88     {
89         GetLastErrorText(wstrErrorText, sizeof(wstrErrorText)/sizeof(WCHAR));
90         MessageBoxW(hMainWnd, wstrErrorText,wszUnable2Terminate, MB_OK|MB_ICONSTOP);
91     }
92
93     CloseHandle(hProcess);
94 }
95
96 void ProcessPage_OnEndProcessTree(void)
97 {
98     LVITEMW          lvitem;
99     ULONG            Index, Count;
100     DWORD            dwProcessId;
101     HANDLE           hProcess;
102     WCHAR            wstrErrorText[256];
103
104     load_message_strings();
105
106     Count = SendMessageW(hProcessPageListCtrl, LVM_GETITEMCOUNT, 0, 0);
107     for (Index=0; Index<Count; Index++)
108     {
109         lvitem.mask = LVIF_STATE;
110         lvitem.stateMask = LVIS_SELECTED;
111         lvitem.iItem = Index;
112         lvitem.iSubItem = 0;
113
114         SendMessageW(hProcessPageListCtrl, LVM_GETITEMW, 0, (LPARAM) &lvitem);
115
116         if (lvitem.state & LVIS_SELECTED)
117             break;
118     }
119
120     Count = SendMessageW(hProcessPageListCtrl, LVM_GETSELECTEDCOUNT, 0, 0);
121     dwProcessId = PerfDataGetProcessId(Index);
122     if ((Count != 1) || (dwProcessId == 0))
123         return;
124
125     if (MessageBoxW(hMainWnd, wszWarnMsg, wszWarnTitle, MB_YESNO|MB_ICONWARNING) != IDYES)
126         return;
127
128     hProcess = OpenProcess(PROCESS_TERMINATE, FALSE, dwProcessId);
129
130     if (!hProcess)
131     {
132         GetLastErrorText(wstrErrorText, sizeof(wstrErrorText)/sizeof(WCHAR));
133         MessageBoxW(hMainWnd, wstrErrorText,wszUnable2Terminate, MB_OK|MB_ICONSTOP);
134         return;
135     }
136
137     if (!TerminateProcess(hProcess, 0))
138     {
139         GetLastErrorText(wstrErrorText, sizeof(wstrErrorText)/sizeof(WCHAR));
140         MessageBoxW(hMainWnd, wstrErrorText,wszUnable2Terminate, MB_OK|MB_ICONSTOP);
141     }
142
143     CloseHandle(hProcess);
144 }