notepad: Change file not saved alert title to match Windows' notepad.exe.
[wine] / programs / taskmgr / priority.c
1 /*
2  *  ReactOS Task Manager
3  *
4  *  priority.c
5  *
6  *  Copyright (C) 1999 - 2001  Brian Palmer  <brianp@reactos.org>
7  *
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.
12  *
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.
17  *
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
21  */
22     
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>
32     
33 #include "taskmgr.h"
34 #include "perfdata.h"
35
36 static void DoSetPriority(DWORD priority)
37 {
38     LVITEM            lvitem;
39     ULONG            Index;
40     DWORD            dwProcessId;
41     HANDLE            hProcess;
42     TCHAR            strErrorText[260];
43
44     for (Index=0; Index<(ULONG)ListView_GetItemCount(hProcessPageListCtrl); Index++)
45     {
46         memset(&lvitem, 0, sizeof(LVITEM));
47
48         lvitem.mask = LVIF_STATE;
49         lvitem.stateMask = LVIS_SELECTED;
50         lvitem.iItem = Index;
51
52         SendMessage(hProcessPageListCtrl, LVM_GETITEM, 0, (LPARAM)&lvitem);
53
54         if (lvitem.state & LVIS_SELECTED)
55             break;
56     }
57
58     dwProcessId = PerfDataGetProcessId(Index);
59
60     if ((ListView_GetSelectedCount(hProcessPageListCtrl) != 1) || (dwProcessId == 0))
61         return;
62
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;
65
66     hProcess = OpenProcess(PROCESS_SET_INFORMATION, FALSE, dwProcessId);
67
68     if (!hProcess)
69     {
70         GetLastErrorText(strErrorText, 260);
71         MessageBox(hMainWnd, strErrorText, _T("Unable to Change Priority"), MB_OK|MB_ICONSTOP);
72         return;
73     }
74
75     if (!SetPriorityClass(hProcess, priority))
76     {
77         GetLastErrorText(strErrorText, 260);
78         MessageBox(hMainWnd, strErrorText, _T("Unable to Change Priority"), MB_OK|MB_ICONSTOP);
79     }
80
81     CloseHandle(hProcess);
82 }
83
84 void ProcessPage_OnSetPriorityRealTime(void)
85 {
86     DoSetPriority(REALTIME_PRIORITY_CLASS);
87 }
88
89 void ProcessPage_OnSetPriorityHigh(void)
90 {
91     DoSetPriority(HIGH_PRIORITY_CLASS);
92 }
93
94 void ProcessPage_OnSetPriorityAboveNormal(void)
95 {
96     DoSetPriority(ABOVE_NORMAL_PRIORITY_CLASS);
97 }
98
99 void ProcessPage_OnSetPriorityNormal(void)
100 {
101     DoSetPriority(NORMAL_PRIORITY_CLASS);
102 }
103
104 void ProcessPage_OnSetPriorityBelowNormal(void)
105 {
106     DoSetPriority(BELOW_NORMAL_PRIORITY_CLASS);
107 }
108
109 void ProcessPage_OnSetPriorityLow(void)
110 {
111     DoSetPriority(IDLE_PRIORITY_CLASS);
112 }