endproc.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /*
  2. * ReactOS Task Manager
  3. *
  4. * endproc.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 WCHAR wszWarnMsg[511];
  31. static WCHAR wszWarnTitle[255];
  32. static WCHAR wszUnable2Terminate[255];
  33. static void load_message_strings(void)
  34. {
  35. LoadStringW(hInst, IDS_TERMINATE_MESSAGE, wszWarnMsg, ARRAY_SIZE(wszWarnMsg));
  36. LoadStringW(hInst, IDS_TERMINATE_UNABLE2TERMINATE, wszUnable2Terminate, ARRAY_SIZE(wszUnable2Terminate));
  37. LoadStringW(hInst, IDS_WARNING_TITLE, wszWarnTitle, ARRAY_SIZE(wszWarnTitle));
  38. }
  39. void ProcessPage_OnEndProcess(void)
  40. {
  41. LVITEMW lvitem;
  42. ULONG Index, Count;
  43. DWORD dwProcessId;
  44. HANDLE hProcess;
  45. WCHAR wstrErrorText[256];
  46. load_message_strings();
  47. Count = SendMessageW(hProcessPageListCtrl, LVM_GETITEMCOUNT, 0, 0);
  48. for (Index=0; Index<Count; Index++)
  49. {
  50. lvitem.mask = LVIF_STATE;
  51. lvitem.stateMask = LVIS_SELECTED;
  52. lvitem.iItem = Index;
  53. lvitem.iSubItem = 0;
  54. SendMessageW(hProcessPageListCtrl, LVM_GETITEMW, 0, (LPARAM) &lvitem);
  55. if (lvitem.state & LVIS_SELECTED)
  56. break;
  57. }
  58. Count = SendMessageW(hProcessPageListCtrl, LVM_GETSELECTEDCOUNT, 0, 0);
  59. dwProcessId = PerfDataGetProcessId(Index);
  60. if ((Count != 1) || (dwProcessId == 0))
  61. return;
  62. if (MessageBoxW(hMainWnd, wszWarnMsg, wszWarnTitle, MB_YESNO|MB_ICONWARNING) != IDYES)
  63. return;
  64. hProcess = OpenProcess(PROCESS_TERMINATE, FALSE, dwProcessId);
  65. if (!hProcess)
  66. {
  67. GetLastErrorText(wstrErrorText, ARRAY_SIZE(wstrErrorText));
  68. MessageBoxW(hMainWnd, wstrErrorText,wszUnable2Terminate, MB_OK|MB_ICONSTOP);
  69. return;
  70. }
  71. if (!TerminateProcess(hProcess, 0))
  72. {
  73. GetLastErrorText(wstrErrorText, ARRAY_SIZE(wstrErrorText));
  74. MessageBoxW(hMainWnd, wstrErrorText,wszUnable2Terminate, MB_OK|MB_ICONSTOP);
  75. }
  76. CloseHandle(hProcess);
  77. }
  78. void ProcessPage_OnEndProcessTree(void)
  79. {
  80. LVITEMW lvitem;
  81. ULONG Index, Count;
  82. DWORD dwProcessId;
  83. HANDLE hProcess;
  84. WCHAR wstrErrorText[256];
  85. load_message_strings();
  86. Count = SendMessageW(hProcessPageListCtrl, LVM_GETITEMCOUNT, 0, 0);
  87. for (Index=0; Index<Count; Index++)
  88. {
  89. lvitem.mask = LVIF_STATE;
  90. lvitem.stateMask = LVIS_SELECTED;
  91. lvitem.iItem = Index;
  92. lvitem.iSubItem = 0;
  93. SendMessageW(hProcessPageListCtrl, LVM_GETITEMW, 0, (LPARAM) &lvitem);
  94. if (lvitem.state & LVIS_SELECTED)
  95. break;
  96. }
  97. Count = SendMessageW(hProcessPageListCtrl, LVM_GETSELECTEDCOUNT, 0, 0);
  98. dwProcessId = PerfDataGetProcessId(Index);
  99. if ((Count != 1) || (dwProcessId == 0))
  100. return;
  101. if (MessageBoxW(hMainWnd, wszWarnMsg, wszWarnTitle, MB_YESNO|MB_ICONWARNING) != IDYES)
  102. return;
  103. hProcess = OpenProcess(PROCESS_TERMINATE, FALSE, dwProcessId);
  104. if (!hProcess)
  105. {
  106. GetLastErrorText(wstrErrorText, ARRAY_SIZE(wstrErrorText));
  107. MessageBoxW(hMainWnd, wstrErrorText,wszUnable2Terminate, MB_OK|MB_ICONSTOP);
  108. return;
  109. }
  110. if (!TerminateProcess(hProcess, 0))
  111. {
  112. GetLastErrorText(wstrErrorText, ARRAY_SIZE(wstrErrorText));
  113. MessageBoxW(hMainWnd, wstrErrorText,wszUnable2Terminate, MB_OK|MB_ICONSTOP);
  114. }
  115. CloseHandle(hProcess);
  116. }