notepad: Convert dialogs to po files.
[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  *  Copyright (C) 2008  Vladimir Pankratov
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22  */
23     
24 #define WIN32_LEAN_AND_MEAN    /* Exclude rarely-used stuff from Windows headers */
25 #include <windows.h>
26 #include <commctrl.h>
27 #include <stdlib.h>
28 #include <memory.h>
29 #include <stdio.h>
30 #include <winnt.h>
31     
32 #include "wine/unicode.h"
33 #include "taskmgr.h"
34 #include "perfdata.h"
35
36 static void DoSetPriority(DWORD priority)
37 {
38     LVITEMW          lvitem;
39     ULONG            Index, Count;
40     DWORD            dwProcessId;
41     HANDLE           hProcess;
42     WCHAR            wstrErrorText[256];
43
44     WCHAR    wszWarnMsg[255];
45     WCHAR    wszWarnTitle[255];
46     WCHAR    wszUnable2Change[255];
47
48     LoadStringW(hInst, IDS_PRIORITY_CHANGE_MESSAGE, wszWarnMsg, sizeof(wszWarnMsg)/sizeof(WCHAR));
49     LoadStringW(hInst, IDS_WARNING_TITLE, wszWarnTitle, sizeof(wszWarnTitle)/sizeof(WCHAR));
50     LoadStringW(hInst, IDS_PRIORITY_UNABLE2CHANGE, wszUnable2Change, sizeof(wszUnable2Change)/sizeof(WCHAR));
51
52     Count = SendMessageW(hProcessPageListCtrl, LVM_GETITEMCOUNT, 0, 0);
53     for (Index=0; Index<Count; Index++)
54     {
55         lvitem.mask = LVIF_STATE;
56         lvitem.stateMask = LVIS_SELECTED;
57         lvitem.iItem = Index;
58         lvitem.iSubItem = 0;
59
60         SendMessageW(hProcessPageListCtrl, LVM_GETITEMW, 0, (LPARAM)&lvitem);
61
62         if (lvitem.state & LVIS_SELECTED)
63             break;
64     }
65
66     Count = SendMessageW(hProcessPageListCtrl, LVM_GETSELECTEDCOUNT, 0, 0);
67     dwProcessId = PerfDataGetProcessId(Index);
68     if ((Count != 1) || (dwProcessId == 0))
69         return;
70
71     if (MessageBoxW(hMainWnd, wszWarnMsg, wszWarnTitle, MB_YESNO|MB_ICONWARNING) != IDYES)
72         return;
73
74     hProcess = OpenProcess(PROCESS_SET_INFORMATION, FALSE, dwProcessId);
75
76     if (!hProcess)
77     {
78         GetLastErrorText(wstrErrorText, sizeof(wstrErrorText)/sizeof(WCHAR));
79         MessageBoxW(hMainWnd, wstrErrorText, wszUnable2Change, MB_OK|MB_ICONSTOP);
80         return;
81     }
82
83     if (!SetPriorityClass(hProcess, priority))
84     {
85         GetLastErrorText(wstrErrorText, sizeof(wstrErrorText)/sizeof(WCHAR));
86         MessageBoxW(hMainWnd, wstrErrorText, wszUnable2Change, MB_OK|MB_ICONSTOP);
87     }
88
89     CloseHandle(hProcess);
90 }
91
92 void ProcessPage_OnSetPriorityRealTime(void)
93 {
94     DoSetPriority(REALTIME_PRIORITY_CLASS);
95 }
96
97 void ProcessPage_OnSetPriorityHigh(void)
98 {
99     DoSetPriority(HIGH_PRIORITY_CLASS);
100 }
101
102 void ProcessPage_OnSetPriorityAboveNormal(void)
103 {
104     DoSetPriority(ABOVE_NORMAL_PRIORITY_CLASS);
105 }
106
107 void ProcessPage_OnSetPriorityNormal(void)
108 {
109     DoSetPriority(NORMAL_PRIORITY_CLASS);
110 }
111
112 void ProcessPage_OnSetPriorityBelowNormal(void)
113 {
114     DoSetPriority(BELOW_NORMAL_PRIORITY_CLASS);
115 }
116
117 void ProcessPage_OnSetPriorityLow(void)
118 {
119     DoSetPriority(IDLE_PRIORITY_CLASS);
120 }