mshtml: Handle IHlinkFrame service.
[wine/dcerpc.git] / programs / taskmgr / priority.c
blob7f76289a1fb41581096ffa7f735ee6b02935d83b
1 /*
2 * ReactOS Task Manager
4 * priority.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_OnSetPriorityRealTime(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: Changing the priority class of this process may\ncause undesired results including system instability. Are you\nsure you want to change the priority class?"), _T("Task Manager Warning"), MB_YESNO|MB_ICONWARNING) != IDYES)
64 return;
66 hProcess = OpenProcess(PROCESS_SET_INFORMATION, FALSE, dwProcessId);
68 if (!hProcess)
70 GetLastErrorText(strErrorText, 260);
71 MessageBox(hMainWnd, strErrorText, _T("Unable to Change Priority"), MB_OK|MB_ICONSTOP);
72 return;
75 if (!SetPriorityClass(hProcess, REALTIME_PRIORITY_CLASS))
77 GetLastErrorText(strErrorText, 260);
78 MessageBox(hMainWnd, strErrorText, _T("Unable to Change Priority"), MB_OK|MB_ICONSTOP);
81 CloseHandle(hProcess);
84 void ProcessPage_OnSetPriorityHigh(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: Changing the priority class of this process may\ncause undesired results including system instability. Are you\nsure you want to change the priority class?"), _T("Task Manager Warning"), MB_YESNO|MB_ICONWARNING) != IDYES)
112 return;
114 hProcess = OpenProcess(PROCESS_SET_INFORMATION, FALSE, dwProcessId);
116 if (!hProcess)
118 GetLastErrorText(strErrorText, 260);
119 MessageBox(hMainWnd, strErrorText, _T("Unable to Change Priority"), MB_OK|MB_ICONSTOP);
120 return;
123 if (!SetPriorityClass(hProcess, HIGH_PRIORITY_CLASS))
125 GetLastErrorText(strErrorText, 260);
126 MessageBox(hMainWnd, strErrorText, _T("Unable to Change Priority"), MB_OK|MB_ICONSTOP);
129 CloseHandle(hProcess);
132 void ProcessPage_OnSetPriorityAboveNormal(void)
134 LVITEM lvitem;
135 ULONG Index;
136 DWORD dwProcessId;
137 HANDLE hProcess;
138 TCHAR strErrorText[260];
140 for (Index=0; Index<(ULONG)ListView_GetItemCount(hProcessPageListCtrl); Index++)
142 memset(&lvitem, 0, sizeof(LVITEM));
144 lvitem.mask = LVIF_STATE;
145 lvitem.stateMask = LVIS_SELECTED;
146 lvitem.iItem = Index;
148 ListView_GetItem(hProcessPageListCtrl, &lvitem);
150 if (lvitem.state & LVIS_SELECTED)
151 break;
154 dwProcessId = PerfDataGetProcessId(Index);
156 if ((ListView_GetSelectedCount(hProcessPageListCtrl) != 1) || (dwProcessId == 0))
157 return;
159 if (MessageBox(hMainWnd, _T("WARNING: Changing the priority class of this process may\ncause undesired results including system instability. Are you\nsure you want to change the priority class?"), _T("Task Manager Warning"), MB_YESNO|MB_ICONWARNING) != IDYES)
160 return;
162 hProcess = OpenProcess(PROCESS_SET_INFORMATION, FALSE, dwProcessId);
164 if (!hProcess)
166 GetLastErrorText(strErrorText, 260);
167 MessageBox(hMainWnd, strErrorText, _T("Unable to Change Priority"), MB_OK|MB_ICONSTOP);
168 return;
171 if (!SetPriorityClass(hProcess, ABOVE_NORMAL_PRIORITY_CLASS))
173 GetLastErrorText(strErrorText, 260);
174 MessageBox(hMainWnd, strErrorText, _T("Unable to Change Priority"), MB_OK|MB_ICONSTOP);
177 CloseHandle(hProcess);
180 void ProcessPage_OnSetPriorityNormal(void)
182 LVITEM lvitem;
183 ULONG Index;
184 DWORD dwProcessId;
185 HANDLE hProcess;
186 TCHAR strErrorText[260];
188 for (Index=0; Index<(ULONG)ListView_GetItemCount(hProcessPageListCtrl); Index++)
190 memset(&lvitem, 0, sizeof(LVITEM));
192 lvitem.mask = LVIF_STATE;
193 lvitem.stateMask = LVIS_SELECTED;
194 lvitem.iItem = Index;
196 ListView_GetItem(hProcessPageListCtrl, &lvitem);
198 if (lvitem.state & LVIS_SELECTED)
199 break;
202 dwProcessId = PerfDataGetProcessId(Index);
204 if ((ListView_GetSelectedCount(hProcessPageListCtrl) != 1) || (dwProcessId == 0))
205 return;
207 if (MessageBox(hMainWnd, _T("WARNING: Changing the priority class of this process may\ncause undesired results including system instability. Are you\nsure you want to change the priority class?"), _T("Task Manager Warning"), MB_YESNO|MB_ICONWARNING) != IDYES)
208 return;
210 hProcess = OpenProcess(PROCESS_SET_INFORMATION, FALSE, dwProcessId);
212 if (!hProcess)
214 GetLastErrorText(strErrorText, 260);
215 MessageBox(hMainWnd, strErrorText, _T("Unable to Change Priority"), MB_OK|MB_ICONSTOP);
216 return;
219 if (!SetPriorityClass(hProcess, NORMAL_PRIORITY_CLASS))
221 GetLastErrorText(strErrorText, 260);
222 MessageBox(hMainWnd, strErrorText, _T("Unable to Change Priority"), MB_OK|MB_ICONSTOP);
225 CloseHandle(hProcess);
228 void ProcessPage_OnSetPriorityBelowNormal(void)
230 LVITEM lvitem;
231 ULONG Index;
232 DWORD dwProcessId;
233 HANDLE hProcess;
234 TCHAR strErrorText[260];
236 for (Index=0; Index<(ULONG)ListView_GetItemCount(hProcessPageListCtrl); Index++)
238 memset(&lvitem, 0, sizeof(LVITEM));
240 lvitem.mask = LVIF_STATE;
241 lvitem.stateMask = LVIS_SELECTED;
242 lvitem.iItem = Index;
244 ListView_GetItem(hProcessPageListCtrl, &lvitem);
246 if (lvitem.state & LVIS_SELECTED)
247 break;
250 dwProcessId = PerfDataGetProcessId(Index);
252 if ((ListView_GetSelectedCount(hProcessPageListCtrl) != 1) || (dwProcessId == 0))
253 return;
255 if (MessageBox(hMainWnd, _T("WARNING: Changing the priority class of this process may\ncause undesired results including system instability. Are you\nsure you want to change the priority class?"), _T("Task Manager Warning"), MB_YESNO|MB_ICONWARNING) != IDYES)
256 return;
258 hProcess = OpenProcess(PROCESS_SET_INFORMATION, FALSE, dwProcessId);
260 if (!hProcess)
262 GetLastErrorText(strErrorText, 260);
263 MessageBox(hMainWnd, strErrorText, _T("Unable to Change Priority"), MB_OK|MB_ICONSTOP);
264 return;
267 if (!SetPriorityClass(hProcess, BELOW_NORMAL_PRIORITY_CLASS))
269 GetLastErrorText(strErrorText, 260);
270 MessageBox(hMainWnd, strErrorText, _T("Unable to Change Priority"), MB_OK|MB_ICONSTOP);
273 CloseHandle(hProcess);
276 void ProcessPage_OnSetPriorityLow(void)
278 LVITEM lvitem;
279 ULONG Index;
280 DWORD dwProcessId;
281 HANDLE hProcess;
282 TCHAR strErrorText[260];
284 for (Index=0; Index<(ULONG)ListView_GetItemCount(hProcessPageListCtrl); Index++)
286 memset(&lvitem, 0, sizeof(LVITEM));
288 lvitem.mask = LVIF_STATE;
289 lvitem.stateMask = LVIS_SELECTED;
290 lvitem.iItem = Index;
292 ListView_GetItem(hProcessPageListCtrl, &lvitem);
294 if (lvitem.state & LVIS_SELECTED)
295 break;
298 dwProcessId = PerfDataGetProcessId(Index);
300 if ((ListView_GetSelectedCount(hProcessPageListCtrl) != 1) || (dwProcessId == 0))
301 return;
303 if (MessageBox(hMainWnd, _T("WARNING: Changing the priority class of this process may\ncause undesired results including system instability. Are you\nsure you want to change the priority class?"), _T("Task Manager Warning"), MB_YESNO|MB_ICONWARNING) != IDYES)
304 return;
306 hProcess = OpenProcess(PROCESS_SET_INFORMATION, FALSE, dwProcessId);
308 if (!hProcess)
310 GetLastErrorText(strErrorText, 260);
311 MessageBox(hMainWnd, strErrorText, _T("Unable to Change Priority"), MB_OK|MB_ICONSTOP);
312 return;
315 if (!SetPriorityClass(hProcess, IDLE_PRIORITY_CLASS))
317 GetLastErrorText(strErrorText, 260);
318 MessageBox(hMainWnd, strErrorText, _T("Unable to Change Priority"), MB_OK|MB_ICONSTOP);
321 CloseHandle(hProcess);