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