mirror of
https://github.com/reactos/reactos.git
synced 2024-12-29 10:35:28 +00:00
Get rid of much more duplicated code in taskmgr (patch by Carlo Bramini, carlo DOT bramix AT libero DOT it)
I also got rid of 6 other functions, which all just call the same function. See issue #2941 for more details. svn path=/trunk/; revision=31677
This commit is contained in:
parent
2d23d947cf
commit
25bc1b3427
4 changed files with 22 additions and 289 deletions
|
@ -23,20 +23,18 @@
|
|||
|
||||
#include <precomp.h>
|
||||
|
||||
WCHAR szTemp[256];
|
||||
WCHAR szTempA[256];
|
||||
|
||||
void ProcessPage_OnSetPriorityRealTime(void)
|
||||
void DoSetPriority(DWORD priority)
|
||||
{
|
||||
LVITEM lvitem;
|
||||
ULONG Index;
|
||||
DWORD dwProcessId;
|
||||
HANDLE hProcess;
|
||||
WCHAR strErrorText[260];
|
||||
WCHAR szText[260];
|
||||
WCHAR szTitle[256];
|
||||
|
||||
for (Index=0; Index<(ULONG)ListView_GetItemCount(hProcessPageListCtrl); Index++)
|
||||
{
|
||||
memset(&lvitem, 0, sizeof(LVITEM));
|
||||
ZeroMemory(&lvitem, sizeof(LVITEM));
|
||||
|
||||
lvitem.mask = LVIF_STATE;
|
||||
lvitem.stateMask = LVIS_SELECTED;
|
||||
|
@ -53,286 +51,26 @@ void ProcessPage_OnSetPriorityRealTime(void)
|
|||
if ((ListView_GetSelectedCount(hProcessPageListCtrl) != 1) || (dwProcessId == 0))
|
||||
return;
|
||||
|
||||
LoadStringW(hInst, IDS_MSG_WARNINGCHANGEPRIORITY, szTemp, 256);
|
||||
LoadStringW(hInst, IDS_MSG_TASKMGRWARNING, szTempA, 256);
|
||||
if (MessageBoxW(hMainWnd, szTemp, szTempA, MB_YESNO|MB_ICONWARNING) != IDYES)
|
||||
LoadStringW(hInst, IDS_MSG_TASKMGRWARNING, szTitle, 256);
|
||||
LoadStringW(hInst, IDS_MSG_WARNINGCHANGEPRIORITY, szText, 260);
|
||||
if (MessageBoxW(hMainWnd, szText, szTitle, MB_YESNO|MB_ICONWARNING) != IDYES)
|
||||
return;
|
||||
|
||||
hProcess = OpenProcess(PROCESS_SET_INFORMATION, FALSE, dwProcessId);
|
||||
|
||||
if (!hProcess)
|
||||
{
|
||||
GetLastErrorText(strErrorText, 260);
|
||||
LoadStringW(hInst, IDS_MSG_UNABLECHANGEPRIORITY, szTemp, 256);
|
||||
MessageBoxW(hMainWnd, strErrorText, szTemp, MB_OK|MB_ICONSTOP);
|
||||
GetLastErrorText(szText, 260);
|
||||
LoadStringW(hInst, IDS_MSG_UNABLECHANGEPRIORITY, szTitle, 256);
|
||||
MessageBoxW(hMainWnd, szText, szTitle, MB_OK|MB_ICONSTOP);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!SetPriorityClass(hProcess, REALTIME_PRIORITY_CLASS))
|
||||
if (!SetPriorityClass(hProcess, priority))
|
||||
{
|
||||
GetLastErrorText(strErrorText, 260);
|
||||
LoadStringW(hInst, IDS_MSG_UNABLECHANGEPRIORITY, szTemp, 256);
|
||||
MessageBoxW(hMainWnd, strErrorText, szTemp, MB_OK|MB_ICONSTOP);
|
||||
}
|
||||
|
||||
CloseHandle(hProcess);
|
||||
}
|
||||
|
||||
void ProcessPage_OnSetPriorityHigh(void)
|
||||
{
|
||||
LVITEM lvitem;
|
||||
ULONG Index;
|
||||
DWORD dwProcessId;
|
||||
HANDLE hProcess;
|
||||
WCHAR strErrorText[260];
|
||||
|
||||
for (Index=0; Index<(ULONG)ListView_GetItemCount(hProcessPageListCtrl); Index++)
|
||||
{
|
||||
memset(&lvitem, 0, sizeof(LVITEM));
|
||||
|
||||
lvitem.mask = LVIF_STATE;
|
||||
lvitem.stateMask = LVIS_SELECTED;
|
||||
lvitem.iItem = Index;
|
||||
|
||||
(void)ListView_GetItem(hProcessPageListCtrl, &lvitem);
|
||||
|
||||
if (lvitem.state & LVIS_SELECTED)
|
||||
break;
|
||||
}
|
||||
|
||||
dwProcessId = PerfDataGetProcessId(Index);
|
||||
|
||||
if ((ListView_GetSelectedCount(hProcessPageListCtrl) != 1) || (dwProcessId == 0))
|
||||
return;
|
||||
|
||||
LoadStringW(hInst, IDS_MSG_WARNINGCHANGEPRIORITY, szTemp, 256);
|
||||
LoadStringW(hInst, IDS_MSG_TASKMGRWARNING, szTempA, 256);
|
||||
if (MessageBoxW(hMainWnd, szTemp, szTempA, MB_YESNO|MB_ICONWARNING) != IDYES)
|
||||
return;
|
||||
|
||||
hProcess = OpenProcess(PROCESS_SET_INFORMATION, FALSE, dwProcessId);
|
||||
|
||||
if (!hProcess)
|
||||
{
|
||||
GetLastErrorText(strErrorText, 260);
|
||||
LoadStringW(hInst, IDS_MSG_UNABLECHANGEPRIORITY, szTemp, 256);
|
||||
MessageBoxW(hMainWnd, strErrorText, szTemp, MB_OK|MB_ICONSTOP);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!SetPriorityClass(hProcess, HIGH_PRIORITY_CLASS))
|
||||
{
|
||||
GetLastErrorText(strErrorText, 260);
|
||||
LoadStringW(hInst, IDS_MSG_UNABLECHANGEPRIORITY, szTemp, 256);
|
||||
MessageBoxW(hMainWnd, strErrorText, szTemp, MB_OK|MB_ICONSTOP);
|
||||
}
|
||||
|
||||
CloseHandle(hProcess);
|
||||
}
|
||||
|
||||
void ProcessPage_OnSetPriorityAboveNormal(void)
|
||||
{
|
||||
LVITEM lvitem;
|
||||
ULONG Index;
|
||||
DWORD dwProcessId;
|
||||
HANDLE hProcess;
|
||||
WCHAR strErrorText[260];
|
||||
|
||||
for (Index=0; Index<(ULONG)ListView_GetItemCount(hProcessPageListCtrl); Index++)
|
||||
{
|
||||
memset(&lvitem, 0, sizeof(LVITEM));
|
||||
|
||||
lvitem.mask = LVIF_STATE;
|
||||
lvitem.stateMask = LVIS_SELECTED;
|
||||
lvitem.iItem = Index;
|
||||
|
||||
(void)ListView_GetItem(hProcessPageListCtrl, &lvitem);
|
||||
|
||||
if (lvitem.state & LVIS_SELECTED)
|
||||
break;
|
||||
}
|
||||
|
||||
dwProcessId = PerfDataGetProcessId(Index);
|
||||
|
||||
if ((ListView_GetSelectedCount(hProcessPageListCtrl) != 1) || (dwProcessId == 0))
|
||||
return;
|
||||
|
||||
LoadStringW(hInst, IDS_MSG_WARNINGCHANGEPRIORITY, szTemp, 256);
|
||||
LoadStringW(hInst, IDS_MSG_TASKMGRWARNING, szTempA, 256);
|
||||
if (MessageBoxW(hMainWnd, szTemp, szTempA, MB_YESNO|MB_ICONWARNING) != IDYES)
|
||||
return;
|
||||
|
||||
hProcess = OpenProcess(PROCESS_SET_INFORMATION, FALSE, dwProcessId);
|
||||
|
||||
if (!hProcess)
|
||||
{
|
||||
GetLastErrorText(strErrorText, 260);
|
||||
LoadStringW(hInst, IDS_MSG_UNABLECHANGEPRIORITY, szTemp, 256);
|
||||
MessageBoxW(hMainWnd, strErrorText, szTemp, MB_OK|MB_ICONSTOP);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!SetPriorityClass(hProcess, ABOVE_NORMAL_PRIORITY_CLASS))
|
||||
{
|
||||
GetLastErrorText(strErrorText, 260);
|
||||
LoadStringW(hInst, IDS_MSG_UNABLECHANGEPRIORITY, szTemp, 256);
|
||||
MessageBoxW(hMainWnd, strErrorText, szTemp, MB_OK|MB_ICONSTOP);
|
||||
}
|
||||
|
||||
CloseHandle(hProcess);
|
||||
}
|
||||
|
||||
void ProcessPage_OnSetPriorityNormal(void)
|
||||
{
|
||||
LVITEM lvitem;
|
||||
ULONG Index;
|
||||
DWORD dwProcessId;
|
||||
HANDLE hProcess;
|
||||
WCHAR strErrorText[260];
|
||||
|
||||
for (Index=0; Index<(ULONG)ListView_GetItemCount(hProcessPageListCtrl); Index++)
|
||||
{
|
||||
memset(&lvitem, 0, sizeof(LVITEM));
|
||||
|
||||
lvitem.mask = LVIF_STATE;
|
||||
lvitem.stateMask = LVIS_SELECTED;
|
||||
lvitem.iItem = Index;
|
||||
|
||||
(void)ListView_GetItem(hProcessPageListCtrl, &lvitem);
|
||||
|
||||
if (lvitem.state & LVIS_SELECTED)
|
||||
break;
|
||||
}
|
||||
|
||||
dwProcessId = PerfDataGetProcessId(Index);
|
||||
|
||||
if ((ListView_GetSelectedCount(hProcessPageListCtrl) != 1) || (dwProcessId == 0))
|
||||
return;
|
||||
|
||||
LoadStringW(hInst, IDS_MSG_WARNINGCHANGEPRIORITY, szTemp, 256);
|
||||
LoadStringW(hInst, IDS_MSG_TASKMGRWARNING, szTempA, 256);
|
||||
if (MessageBoxW(hMainWnd, szTemp, szTempA, MB_YESNO|MB_ICONWARNING) != IDYES)
|
||||
return;
|
||||
|
||||
hProcess = OpenProcess(PROCESS_SET_INFORMATION, FALSE, dwProcessId);
|
||||
|
||||
if (!hProcess)
|
||||
{
|
||||
GetLastErrorText(strErrorText, 260);
|
||||
LoadStringW(hInst, IDS_MSG_UNABLECHANGEPRIORITY, szTemp, 256);
|
||||
MessageBoxW(hMainWnd, strErrorText, szTemp, MB_OK|MB_ICONSTOP);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!SetPriorityClass(hProcess, NORMAL_PRIORITY_CLASS))
|
||||
{
|
||||
GetLastErrorText(strErrorText, 260);
|
||||
LoadStringW(hInst, IDS_MSG_UNABLECHANGEPRIORITY, szTemp, 256);
|
||||
MessageBoxW(hMainWnd, strErrorText, szTemp, MB_OK|MB_ICONSTOP);
|
||||
}
|
||||
|
||||
CloseHandle(hProcess);
|
||||
}
|
||||
|
||||
void ProcessPage_OnSetPriorityBelowNormal(void)
|
||||
{
|
||||
LVITEM lvitem;
|
||||
ULONG Index;
|
||||
DWORD dwProcessId;
|
||||
HANDLE hProcess;
|
||||
WCHAR strErrorText[260];
|
||||
|
||||
for (Index=0; Index<(ULONG)ListView_GetItemCount(hProcessPageListCtrl); Index++)
|
||||
{
|
||||
memset(&lvitem, 0, sizeof(LVITEM));
|
||||
|
||||
lvitem.mask = LVIF_STATE;
|
||||
lvitem.stateMask = LVIS_SELECTED;
|
||||
lvitem.iItem = Index;
|
||||
|
||||
(void)ListView_GetItem(hProcessPageListCtrl, &lvitem);
|
||||
|
||||
if (lvitem.state & LVIS_SELECTED)
|
||||
break;
|
||||
}
|
||||
|
||||
dwProcessId = PerfDataGetProcessId(Index);
|
||||
|
||||
if ((ListView_GetSelectedCount(hProcessPageListCtrl) != 1) || (dwProcessId == 0))
|
||||
return;
|
||||
|
||||
LoadStringW(hInst, IDS_MSG_WARNINGCHANGEPRIORITY, szTemp, 256);
|
||||
LoadStringW(hInst, IDS_MSG_TASKMGRWARNING, szTempA, 256);
|
||||
if (MessageBoxW(hMainWnd, szTemp, szTempA, MB_YESNO|MB_ICONWARNING) != IDYES)
|
||||
return;
|
||||
|
||||
hProcess = OpenProcess(PROCESS_SET_INFORMATION, FALSE, dwProcessId);
|
||||
|
||||
if (!hProcess)
|
||||
{
|
||||
GetLastErrorText(strErrorText, 260);
|
||||
LoadStringW(hInst, IDS_MSG_UNABLECHANGEPRIORITY, szTemp, 256);
|
||||
MessageBoxW(hMainWnd, strErrorText, szTemp, MB_OK|MB_ICONSTOP);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!SetPriorityClass(hProcess, BELOW_NORMAL_PRIORITY_CLASS))
|
||||
{
|
||||
GetLastErrorText(strErrorText, 260);
|
||||
LoadStringW(hInst, IDS_MSG_UNABLECHANGEPRIORITY, szTemp, 256);
|
||||
MessageBoxW(hMainWnd, strErrorText, szTemp, MB_OK|MB_ICONSTOP);
|
||||
}
|
||||
|
||||
CloseHandle(hProcess);
|
||||
}
|
||||
|
||||
void ProcessPage_OnSetPriorityLow(void)
|
||||
{
|
||||
LVITEM lvitem;
|
||||
ULONG Index;
|
||||
DWORD dwProcessId;
|
||||
HANDLE hProcess;
|
||||
WCHAR strErrorText[260];
|
||||
|
||||
for (Index=0; Index<(ULONG)ListView_GetItemCount(hProcessPageListCtrl); Index++)
|
||||
{
|
||||
memset(&lvitem, 0, sizeof(LVITEM));
|
||||
|
||||
lvitem.mask = LVIF_STATE;
|
||||
lvitem.stateMask = LVIS_SELECTED;
|
||||
lvitem.iItem = Index;
|
||||
|
||||
(void)ListView_GetItem(hProcessPageListCtrl, &lvitem);
|
||||
|
||||
if (lvitem.state & LVIS_SELECTED)
|
||||
break;
|
||||
}
|
||||
|
||||
dwProcessId = PerfDataGetProcessId(Index);
|
||||
|
||||
if ((ListView_GetSelectedCount(hProcessPageListCtrl) != 1) || (dwProcessId == 0))
|
||||
return;
|
||||
|
||||
LoadStringW(hInst, IDS_MSG_WARNINGCHANGEPRIORITY, szTemp, 256);
|
||||
LoadStringW(hInst, IDS_MSG_TASKMGRWARNING, szTempA, 256);
|
||||
if (MessageBoxW(hMainWnd, szTemp, szTempA, MB_YESNO|MB_ICONWARNING) != IDYES)
|
||||
return;
|
||||
|
||||
hProcess = OpenProcess(PROCESS_SET_INFORMATION, FALSE, dwProcessId);
|
||||
|
||||
if (!hProcess)
|
||||
{
|
||||
GetLastErrorText(strErrorText, 260);
|
||||
LoadStringW(hInst, IDS_MSG_UNABLECHANGEPRIORITY, szTemp, 256);
|
||||
MessageBoxW(hMainWnd, strErrorText, szTemp, MB_OK|MB_ICONSTOP);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!SetPriorityClass(hProcess, IDLE_PRIORITY_CLASS))
|
||||
{
|
||||
GetLastErrorText(strErrorText, 260);
|
||||
LoadStringW(hInst, IDS_MSG_UNABLECHANGEPRIORITY, szTemp, 256);
|
||||
MessageBoxW(hMainWnd, strErrorText, szTemp, MB_OK|MB_ICONSTOP);
|
||||
GetLastErrorText(szText, 260);
|
||||
LoadStringW(hInst, IDS_MSG_UNABLECHANGEPRIORITY, szTitle, 256);
|
||||
MessageBoxW(hMainWnd, szText, szTitle, MB_OK|MB_ICONSTOP);
|
||||
}
|
||||
|
||||
CloseHandle(hProcess);
|
||||
|
|
|
@ -23,11 +23,6 @@
|
|||
#ifndef __PRIORITY_H
|
||||
#define __PRIORITY_H
|
||||
|
||||
void ProcessPage_OnSetPriorityRealTime(void);
|
||||
void ProcessPage_OnSetPriorityHigh(void);
|
||||
void ProcessPage_OnSetPriorityAboveNormal(void);
|
||||
void ProcessPage_OnSetPriorityNormal(void);
|
||||
void ProcessPage_OnSetPriorityBelowNormal(void);
|
||||
void ProcessPage_OnSetPriorityLow(void);
|
||||
void DoSetPriority(DWORD priority);
|
||||
|
||||
#endif /* __PRIORITY_H */
|
||||
|
|
|
@ -212,22 +212,22 @@ TaskManagerWndProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
|
|||
ProcessPage_OnSetAffinity();
|
||||
break;
|
||||
case ID_PROCESS_PAGE_SETPRIORITY_REALTIME:
|
||||
ProcessPage_OnSetPriorityRealTime();
|
||||
DoSetPriority(REALTIME_PRIORITY_CLASS);
|
||||
break;
|
||||
case ID_PROCESS_PAGE_SETPRIORITY_HIGH:
|
||||
ProcessPage_OnSetPriorityHigh();
|
||||
DoSetPriority(HIGH_PRIORITY_CLASS);
|
||||
break;
|
||||
case ID_PROCESS_PAGE_SETPRIORITY_ABOVENORMAL:
|
||||
ProcessPage_OnSetPriorityAboveNormal();
|
||||
DoSetPriority(ABOVE_NORMAL_PRIORITY_CLASS);
|
||||
break;
|
||||
case ID_PROCESS_PAGE_SETPRIORITY_NORMAL:
|
||||
ProcessPage_OnSetPriorityNormal();
|
||||
DoSetPriority(NORMAL_PRIORITY_CLASS);
|
||||
break;
|
||||
case ID_PROCESS_PAGE_SETPRIORITY_BELOWNORMAL:
|
||||
ProcessPage_OnSetPriorityBelowNormal();
|
||||
DoSetPriority(BELOW_NORMAL_PRIORITY_CLASS);
|
||||
break;
|
||||
case ID_PROCESS_PAGE_SETPRIORITY_LOW:
|
||||
ProcessPage_OnSetPriorityLow();
|
||||
DoSetPriority(IDLE_PRIORITY_CLASS);
|
||||
break;
|
||||
case ID_PROCESS_PAGE_DEBUGCHANNELS:
|
||||
ProcessPage_OnDebugChannels();
|
||||
|
|
|
@ -124,7 +124,7 @@ void TaskManager_OnTabWndSelChange(void);
|
|||
LPTSTR GetLastErrorText( LPTSTR lpszBuf, DWORD dwSize );
|
||||
|
||||
#ifdef __cplusplus
|
||||
};
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __TASKMGR_H__ */
|
||||
|
|
Loading…
Reference in a new issue