endproc.c 4.34 KB
Newer Older
1 2 3 4 5 6
/*
 *  ReactOS Task Manager
 *
 *  endproc.c
 *
 *  Copyright (C) 1999 - 2001  Brian Palmer  <brianp@reactos.org>
7
 *  Copyright (C) 2008  Vladimir Pankratov
8 9 10 11 12 13 14 15 16 17 18 19 20
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * 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 25 26

#include <stdio.h>
#include <stdlib.h>

27 28 29
#include <windows.h>
#include <commctrl.h>
#include <winnt.h>
30 31

#include "wine/unicode.h"
32 33 34
#include "taskmgr.h"
#include "perfdata.h"

35 36 37
static WCHAR wszWarnMsg[511];
static WCHAR wszWarnTitle[255];
static WCHAR wszUnable2Terminate[255];
38 39 40 41 42 43 44

static void load_message_strings(void)
{
    LoadStringW(hInst, IDS_TERMINATE_MESSAGE, wszWarnMsg, sizeof(wszWarnMsg)/sizeof(WCHAR));
    LoadStringW(hInst, IDS_TERMINATE_UNABLE2TERMINATE, wszUnable2Terminate, sizeof(wszUnable2Terminate)/sizeof(WCHAR));
    LoadStringW(hInst, IDS_WARNING_TITLE, wszWarnTitle, sizeof(wszWarnTitle)/sizeof(WCHAR));
}
45

46 47
void ProcessPage_OnEndProcess(void)
{
48
    LVITEMW          lvitem;
49
    ULONG            Index, Count;
50
    DWORD            dwProcessId;
51 52
    HANDLE           hProcess;
    WCHAR            wstrErrorText[256];
53

54 55
    load_message_strings();

56 57
    Count = SendMessageW(hProcessPageListCtrl, LVM_GETITEMCOUNT, 0, 0);
    for (Index=0; Index<Count; Index++)
58 59 60 61
    {
        lvitem.mask = LVIF_STATE;
        lvitem.stateMask = LVIS_SELECTED;
        lvitem.iItem = Index;
62
        lvitem.iSubItem = 0;
63

64
        SendMessageW(hProcessPageListCtrl, LVM_GETITEMW, 0, (LPARAM) &lvitem);
65 66 67 68 69

        if (lvitem.state & LVIS_SELECTED)
            break;
    }

70
    Count = SendMessageW(hProcessPageListCtrl, LVM_GETSELECTEDCOUNT, 0, 0);
71
    dwProcessId = PerfDataGetProcessId(Index);
72
    if ((Count != 1) || (dwProcessId == 0))
73 74
        return;

75
    if (MessageBoxW(hMainWnd, wszWarnMsg, wszWarnTitle, MB_YESNO|MB_ICONWARNING) != IDYES)
76 77 78 79 80 81
        return;

    hProcess = OpenProcess(PROCESS_TERMINATE, FALSE, dwProcessId);

    if (!hProcess)
    {
82 83
        GetLastErrorText(wstrErrorText, sizeof(wstrErrorText)/sizeof(WCHAR));
        MessageBoxW(hMainWnd, wstrErrorText,wszUnable2Terminate, MB_OK|MB_ICONSTOP);
84 85 86 87 88
        return;
    }

    if (!TerminateProcess(hProcess, 0))
    {
89 90
        GetLastErrorText(wstrErrorText, sizeof(wstrErrorText)/sizeof(WCHAR));
        MessageBoxW(hMainWnd, wstrErrorText,wszUnable2Terminate, MB_OK|MB_ICONSTOP);
91 92 93 94 95 96 97
    }

    CloseHandle(hProcess);
}

void ProcessPage_OnEndProcessTree(void)
{
98
    LVITEMW          lvitem;
99
    ULONG            Index, Count;
100
    DWORD            dwProcessId;
101 102
    HANDLE           hProcess;
    WCHAR            wstrErrorText[256];
103

104 105
    load_message_strings();

106 107
    Count = SendMessageW(hProcessPageListCtrl, LVM_GETITEMCOUNT, 0, 0);
    for (Index=0; Index<Count; Index++)
108 109 110 111
    {
        lvitem.mask = LVIF_STATE;
        lvitem.stateMask = LVIS_SELECTED;
        lvitem.iItem = Index;
112
        lvitem.iSubItem = 0;
113

114
        SendMessageW(hProcessPageListCtrl, LVM_GETITEMW, 0, (LPARAM) &lvitem);
115 116 117 118 119

        if (lvitem.state & LVIS_SELECTED)
            break;
    }

120
    Count = SendMessageW(hProcessPageListCtrl, LVM_GETSELECTEDCOUNT, 0, 0);
121
    dwProcessId = PerfDataGetProcessId(Index);
122
    if ((Count != 1) || (dwProcessId == 0))
123 124
        return;

125
    if (MessageBoxW(hMainWnd, wszWarnMsg, wszWarnTitle, MB_YESNO|MB_ICONWARNING) != IDYES)
126 127 128 129 130 131
        return;

    hProcess = OpenProcess(PROCESS_TERMINATE, FALSE, dwProcessId);

    if (!hProcess)
    {
132 133
        GetLastErrorText(wstrErrorText, sizeof(wstrErrorText)/sizeof(WCHAR));
        MessageBoxW(hMainWnd, wstrErrorText,wszUnable2Terminate, MB_OK|MB_ICONSTOP);
134 135 136 137 138
        return;
    }

    if (!TerminateProcess(hProcess, 0))
    {
139 140
        GetLastErrorText(wstrErrorText, sizeof(wstrErrorText)/sizeof(WCHAR));
        MessageBoxW(hMainWnd, wstrErrorText,wszUnable2Terminate, MB_OK|MB_ICONSTOP);
141 142 143 144
    }

    CloseHandle(hProcess);
}