ntdll: Fix compacted legacy xsave area handling.
[wine/zf.git] / programs / taskmgr / endproc.c
blob498186212b72f3962613b01976674447ef61ea9b
1 /*
2 * ReactOS Task Manager
4 * endproc.c
6 * Copyright (C) 1999 - 2001 Brian Palmer <brianp@reactos.org>
7 * Copyright (C) 2008 Vladimir Pankratov
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.
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.
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
24 #include <stdio.h>
25 #include <stdlib.h>
27 #include <windows.h>
28 #include <commctrl.h>
29 #include <winnt.h>
31 #include "taskmgr.h"
32 #include "perfdata.h"
34 static WCHAR wszWarnMsg[511];
35 static WCHAR wszWarnTitle[255];
36 static WCHAR wszUnable2Terminate[255];
38 static void load_message_strings(void)
40 LoadStringW(hInst, IDS_TERMINATE_MESSAGE, wszWarnMsg, ARRAY_SIZE(wszWarnMsg));
41 LoadStringW(hInst, IDS_TERMINATE_UNABLE2TERMINATE, wszUnable2Terminate, ARRAY_SIZE(wszUnable2Terminate));
42 LoadStringW(hInst, IDS_WARNING_TITLE, wszWarnTitle, ARRAY_SIZE(wszWarnTitle));
45 void ProcessPage_OnEndProcess(void)
47 LVITEMW lvitem;
48 ULONG Index, Count;
49 DWORD dwProcessId;
50 HANDLE hProcess;
51 WCHAR wstrErrorText[256];
53 load_message_strings();
55 Count = SendMessageW(hProcessPageListCtrl, LVM_GETITEMCOUNT, 0, 0);
56 for (Index=0; Index<Count; Index++)
58 lvitem.mask = LVIF_STATE;
59 lvitem.stateMask = LVIS_SELECTED;
60 lvitem.iItem = Index;
61 lvitem.iSubItem = 0;
63 SendMessageW(hProcessPageListCtrl, LVM_GETITEMW, 0, (LPARAM) &lvitem);
65 if (lvitem.state & LVIS_SELECTED)
66 break;
69 Count = SendMessageW(hProcessPageListCtrl, LVM_GETSELECTEDCOUNT, 0, 0);
70 dwProcessId = PerfDataGetProcessId(Index);
71 if ((Count != 1) || (dwProcessId == 0))
72 return;
74 if (MessageBoxW(hMainWnd, wszWarnMsg, wszWarnTitle, MB_YESNO|MB_ICONWARNING) != IDYES)
75 return;
77 hProcess = OpenProcess(PROCESS_TERMINATE, FALSE, dwProcessId);
79 if (!hProcess)
81 GetLastErrorText(wstrErrorText, ARRAY_SIZE(wstrErrorText));
82 MessageBoxW(hMainWnd, wstrErrorText,wszUnable2Terminate, MB_OK|MB_ICONSTOP);
83 return;
86 if (!TerminateProcess(hProcess, 0))
88 GetLastErrorText(wstrErrorText, ARRAY_SIZE(wstrErrorText));
89 MessageBoxW(hMainWnd, wstrErrorText,wszUnable2Terminate, MB_OK|MB_ICONSTOP);
92 CloseHandle(hProcess);
95 void ProcessPage_OnEndProcessTree(void)
97 LVITEMW lvitem;
98 ULONG Index, Count;
99 DWORD dwProcessId;
100 HANDLE hProcess;
101 WCHAR wstrErrorText[256];
103 load_message_strings();
105 Count = SendMessageW(hProcessPageListCtrl, LVM_GETITEMCOUNT, 0, 0);
106 for (Index=0; Index<Count; Index++)
108 lvitem.mask = LVIF_STATE;
109 lvitem.stateMask = LVIS_SELECTED;
110 lvitem.iItem = Index;
111 lvitem.iSubItem = 0;
113 SendMessageW(hProcessPageListCtrl, LVM_GETITEMW, 0, (LPARAM) &lvitem);
115 if (lvitem.state & LVIS_SELECTED)
116 break;
119 Count = SendMessageW(hProcessPageListCtrl, LVM_GETSELECTEDCOUNT, 0, 0);
120 dwProcessId = PerfDataGetProcessId(Index);
121 if ((Count != 1) || (dwProcessId == 0))
122 return;
124 if (MessageBoxW(hMainWnd, wszWarnMsg, wszWarnTitle, MB_YESNO|MB_ICONWARNING) != IDYES)
125 return;
127 hProcess = OpenProcess(PROCESS_TERMINATE, FALSE, dwProcessId);
129 if (!hProcess)
131 GetLastErrorText(wstrErrorText, ARRAY_SIZE(wstrErrorText));
132 MessageBoxW(hMainWnd, wstrErrorText,wszUnable2Terminate, MB_OK|MB_ICONSTOP);
133 return;
136 if (!TerminateProcess(hProcess, 0))
138 GetLastErrorText(wstrErrorText, ARRAY_SIZE(wstrErrorText));
139 MessageBoxW(hMainWnd, wstrErrorText,wszUnable2Terminate, MB_OK|MB_ICONSTOP);
142 CloseHandle(hProcess);