Author: cfinck
Date: Wed Jan 9 01:52:56 2008
New Revision: 31677
URL:
http://svn.reactos.org/svn/reactos?rev=31677&view=rev
Log:
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.
Modified:
trunk/reactos/base/applications/taskmgr/priority.c
trunk/reactos/base/applications/taskmgr/priority.h
trunk/reactos/base/applications/taskmgr/taskmgr.c
trunk/reactos/base/applications/taskmgr/taskmgr.h
Modified: trunk/reactos/base/applications/taskmgr/priority.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/taskmgr/…
==============================================================================
--- trunk/reactos/base/applications/taskmgr/priority.c (original)
+++ trunk/reactos/base/applications/taskmgr/priority.c Wed Jan 9 01:52:56 2008
@@ -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,287 +51,27 @@
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);
+ GetLastErrorText(szText, 260);
+ LoadStringW(hInst, IDS_MSG_UNABLECHANGEPRIORITY, szTitle, 256);
+ MessageBoxW(hMainWnd, szText, szTitle, 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);
- }
-
- CloseHandle(hProcess);
-}
Modified: trunk/reactos/base/applications/taskmgr/priority.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/taskmgr/…
==============================================================================
--- trunk/reactos/base/applications/taskmgr/priority.h (original)
+++ trunk/reactos/base/applications/taskmgr/priority.h Wed Jan 9 01:52:56 2008
@@ -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 */
Modified: trunk/reactos/base/applications/taskmgr/taskmgr.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/taskmgr/…
==============================================================================
--- trunk/reactos/base/applications/taskmgr/taskmgr.c (original)
+++ trunk/reactos/base/applications/taskmgr/taskmgr.c Wed Jan 9 01:52:56 2008
@@ -212,22 +212,22 @@
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();
Modified: trunk/reactos/base/applications/taskmgr/taskmgr.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/taskmgr/…
==============================================================================
--- trunk/reactos/base/applications/taskmgr/taskmgr.h (original)
+++ trunk/reactos/base/applications/taskmgr/taskmgr.h Wed Jan 9 01:52:56 2008
@@ -124,7 +124,7 @@
LPTSTR GetLastErrorText( LPTSTR lpszBuf, DWORD dwSize );
#ifdef __cplusplus
-};
+}
#endif
#endif /* __TASKMGR_H__ */