modified dll/win32/kernel32/kernel32.rbuild
[reactos.git] / base / applications / taskmgr / priority.c
1 /*
2 * ReactOS Task Manager
3 *
4 * priority.c
5 *
6 * Copyright (C) 1999 - 2001 Brian Palmer <brianp@reactos.org>
7 * 2005 Klemens Friedl <frik85@reactos.at>
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 */
23
24 #include <precomp.h>
25
26 void DoSetPriority(DWORD priority)
27 {
28 LVITEM lvitem;
29 ULONG Index;
30 DWORD dwProcessId;
31 HANDLE hProcess;
32 WCHAR szText[260];
33 WCHAR szTitle[256];
34
35 for (Index=0; Index<(ULONG)ListView_GetItemCount(hProcessPageListCtrl); Index++)
36 {
37 ZeroMemory(&lvitem, sizeof(LVITEM));
38
39 lvitem.mask = LVIF_STATE;
40 lvitem.stateMask = LVIS_SELECTED;
41 lvitem.iItem = Index;
42
43 (void)ListView_GetItem(hProcessPageListCtrl, &lvitem);
44
45 if (lvitem.state & LVIS_SELECTED)
46 break;
47 }
48
49 dwProcessId = PerfDataGetProcessId(Index);
50
51 if ((ListView_GetSelectedCount(hProcessPageListCtrl) != 1) || (dwProcessId == 0))
52 return;
53
54 LoadStringW(hInst, IDS_MSG_TASKMGRWARNING, szTitle, 256);
55 LoadStringW(hInst, IDS_MSG_WARNINGCHANGEPRIORITY, szText, 260);
56 if (MessageBoxW(hMainWnd, szText, szTitle, MB_YESNO|MB_ICONWARNING) != IDYES)
57 return;
58
59 hProcess = OpenProcess(PROCESS_SET_INFORMATION, FALSE, dwProcessId);
60
61 if (!hProcess)
62 {
63 GetLastErrorText(szText, 260);
64 LoadStringW(hInst, IDS_MSG_UNABLECHANGEPRIORITY, szTitle, 256);
65 MessageBoxW(hMainWnd, szText, szTitle, MB_OK|MB_ICONSTOP);
66 return;
67 }
68
69 if (!SetPriorityClass(hProcess, priority))
70 {
71 GetLastErrorText(szText, 260);
72 LoadStringW(hInst, IDS_MSG_UNABLECHANGEPRIORITY, szTitle, 256);
73 MessageBoxW(hMainWnd, szText, szTitle, MB_OK|MB_ICONSTOP);
74 }
75
76 CloseHandle(hProcess);
77 }