include/windows.foundation: Add double reference.
[wine.git] / programs / taskmgr / priority.c
blob31701d6532cbc3c4b664c1b81a7c3e071ad64b67
1 /*
2 * ReactOS Task Manager
4 * priority.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 void DoSetPriority(DWORD priority)
36 LVITEMW lvitem;
37 ULONG Index, Count;
38 DWORD dwProcessId;
39 HANDLE hProcess;
40 WCHAR wstrErrorText[256];
42 WCHAR wszWarnMsg[255];
43 WCHAR wszWarnTitle[255];
44 WCHAR wszUnable2Change[255];
46 LoadStringW(hInst, IDS_PRIORITY_CHANGE_MESSAGE, wszWarnMsg, ARRAY_SIZE(wszWarnMsg));
47 LoadStringW(hInst, IDS_WARNING_TITLE, wszWarnTitle, ARRAY_SIZE(wszWarnTitle));
48 LoadStringW(hInst, IDS_PRIORITY_UNABLE2CHANGE, wszUnable2Change, ARRAY_SIZE(wszUnable2Change));
50 Count = SendMessageW(hProcessPageListCtrl, LVM_GETITEMCOUNT, 0, 0);
51 for (Index=0; Index<Count; Index++)
53 lvitem.mask = LVIF_STATE;
54 lvitem.stateMask = LVIS_SELECTED;
55 lvitem.iItem = Index;
56 lvitem.iSubItem = 0;
58 SendMessageW(hProcessPageListCtrl, LVM_GETITEMW, 0, (LPARAM)&lvitem);
60 if (lvitem.state & LVIS_SELECTED)
61 break;
64 Count = SendMessageW(hProcessPageListCtrl, LVM_GETSELECTEDCOUNT, 0, 0);
65 dwProcessId = PerfDataGetProcessId(Index);
66 if ((Count != 1) || (dwProcessId == 0))
67 return;
69 if (MessageBoxW(hMainWnd, wszWarnMsg, wszWarnTitle, MB_YESNO|MB_ICONWARNING) != IDYES)
70 return;
72 hProcess = OpenProcess(PROCESS_SET_INFORMATION, FALSE, dwProcessId);
74 if (!hProcess)
76 GetLastErrorText(wstrErrorText, ARRAY_SIZE(wstrErrorText));
77 MessageBoxW(hMainWnd, wstrErrorText, wszUnable2Change, MB_OK|MB_ICONSTOP);
78 return;
81 if (!SetPriorityClass(hProcess, priority))
83 GetLastErrorText(wstrErrorText, ARRAY_SIZE(wstrErrorText));
84 MessageBoxW(hMainWnd, wstrErrorText, wszUnable2Change, MB_OK|MB_ICONSTOP);
87 CloseHandle(hProcess);
90 void ProcessPage_OnSetPriorityRealTime(void)
92 DoSetPriority(REALTIME_PRIORITY_CLASS);
95 void ProcessPage_OnSetPriorityHigh(void)
97 DoSetPriority(HIGH_PRIORITY_CLASS);
100 void ProcessPage_OnSetPriorityAboveNormal(void)
102 DoSetPriority(ABOVE_NORMAL_PRIORITY_CLASS);
105 void ProcessPage_OnSetPriorityNormal(void)
107 DoSetPriority(NORMAL_PRIORITY_CLASS);
110 void ProcessPage_OnSetPriorityBelowNormal(void)
112 DoSetPriority(BELOW_NORMAL_PRIORITY_CLASS);
115 void ProcessPage_OnSetPriorityLow(void)
117 DoSetPriority(IDLE_PRIORITY_CLASS);