mirror of https://github.com/libsdl-org/SDL.git
process(windows): fallback to GenerateConsoleCtrlEvent and TerminateProcess if necessary
This commit is contained in:
parent
89c3d31f70
commit
fdb8594339
|
|
@ -520,12 +520,12 @@ done:
|
|||
return result;
|
||||
}
|
||||
|
||||
static BOOL CALLBACK terminate_app(HWND hwnd, LPARAM proc_id)
|
||||
static BOOL CALLBACK terminate_app(HWND hwnd, LPARAM lparam)
|
||||
{
|
||||
DWORD current_proc_id = 0;
|
||||
DWORD current_proc_id = 0, *term_info = (DWORD *) lparam;
|
||||
GetWindowThreadProcessId(hwnd, ¤t_proc_id);
|
||||
if (current_proc_id == (DWORD) proc_id) {
|
||||
PostMessage(hwnd, WM_CLOSE, 0, 0);
|
||||
if (current_proc_id == term_info[0] && PostMessage(hwnd, WM_CLOSE, 0, 0)) {
|
||||
term_info[1]++;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
|
@ -533,9 +533,17 @@ static BOOL CALLBACK terminate_app(HWND hwnd, LPARAM proc_id)
|
|||
bool SDL_SYS_KillProcess(SDL_Process *process, bool force)
|
||||
{
|
||||
if (!force) {
|
||||
EnumWindows(terminate_app, (LPARAM) process->internal->process_information.dwProcessId);
|
||||
PostThreadMessage(process->internal->process_information.dwThreadId, WM_CLOSE, 0, 0);
|
||||
return true;
|
||||
// term_info[0] is the process ID, term_info[1] is number of successful tries
|
||||
DWORD term_info[2];
|
||||
term_info[0] = process->internal->process_information.dwProcessId;
|
||||
term_info[1] = 0;
|
||||
EnumWindows(terminate_app, (LPARAM) &term_info);
|
||||
if (term_info[1] || PostThreadMessage(process->internal->process_information.dwThreadId, WM_CLOSE, 0, 0)) {
|
||||
return true;
|
||||
}
|
||||
if (GenerateConsoleCtrlEvent(CTRL_BREAK_EVENT, term_info[0])) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (!TerminateProcess(process->internal->process_information.hProcess, 1)) {
|
||||
return WIN_SetError("TerminateProcess failed");
|
||||
|
|
|
|||
Loading…
Reference in New Issue