priority.c 3.3 KB

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