pdh: Implement and test PdhLookupPerfIndexByName{A, W} and PdhLookupPerfNameByIndex...
[wine.git] / programs / taskmgr / priority.c
blobc27c76515a601892615f22dfb10832ce032a1c02
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, 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 static void DoSetPriority(DWORD priority)
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 lvitem.mask = LVIF_STATE;
47 lvitem.stateMask = LVIS_SELECTED;
48 lvitem.iItem = Index;
49 lvitem.iSubItem = 0;
51 SendMessage(hProcessPageListCtrl, LVM_GETITEM, 0, (LPARAM)&lvitem);
53 if (lvitem.state & LVIS_SELECTED)
54 break;
57 dwProcessId = PerfDataGetProcessId(Index);
59 if ((ListView_GetSelectedCount(hProcessPageListCtrl) != 1) || (dwProcessId == 0))
60 return;
62 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)
63 return;
65 hProcess = OpenProcess(PROCESS_SET_INFORMATION, FALSE, dwProcessId);
67 if (!hProcess)
69 GetLastErrorText(strErrorText, 260);
70 MessageBox(hMainWnd, strErrorText, _T("Unable to Change Priority"), MB_OK|MB_ICONSTOP);
71 return;
74 if (!SetPriorityClass(hProcess, priority))
76 GetLastErrorText(strErrorText, 260);
77 MessageBox(hMainWnd, strErrorText, _T("Unable to Change Priority"), MB_OK|MB_ICONSTOP);
80 CloseHandle(hProcess);
83 void ProcessPage_OnSetPriorityRealTime(void)
85 DoSetPriority(REALTIME_PRIORITY_CLASS);
88 void ProcessPage_OnSetPriorityHigh(void)
90 DoSetPriority(HIGH_PRIORITY_CLASS);
93 void ProcessPage_OnSetPriorityAboveNormal(void)
95 DoSetPriority(ABOVE_NORMAL_PRIORITY_CLASS);
98 void ProcessPage_OnSetPriorityNormal(void)
100 DoSetPriority(NORMAL_PRIORITY_CLASS);
103 void ProcessPage_OnSetPriorityBelowNormal(void)
105 DoSetPriority(BELOW_NORMAL_PRIORITY_CLASS);
108 void ProcessPage_OnSetPriorityLow(void)
110 DoSetPriority(IDLE_PRIORITY_CLASS);