From b79936a0e68ada48a93363a478bbade4af16ca50 Mon Sep 17 00:00:00 2001 From: LoRd_MuldeR Date: Sun, 8 Feb 2015 22:22:23 +0100 Subject: [PATCH] Added suspend_process() function. --- include/MUtils/OSSupport.h | 5 ++++- src/OSSupport_Win32.cpp | 25 ++++++++++++++++++++++++- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/include/MUtils/OSSupport.h b/include/MUtils/OSSupport.h index ca1e03f..696a065 100644 --- a/include/MUtils/OSSupport.h +++ b/include/MUtils/OSSupport.h @@ -154,7 +154,10 @@ namespace MUtils MUTILS_API bool change_process_priority(const QProcess *proc, const int priority); //Process ID - MUTILS_API quint32 process_id(const QProcess *proc); + MUTILS_API quint32 process_id(const QProcess *const proc); + + //Suspend or resume processv + MUTILS_API bool suspend_process(const QProcess *proc, const bool suspend); //System timer resolution MUTILS_API bool setup_timer_resolution(const quint32 &interval = 1); diff --git a/src/OSSupport_Win32.cpp b/src/OSSupport_Win32.cpp index 4a2872b..22843cb 100644 --- a/src/OSSupport_Win32.cpp +++ b/src/OSSupport_Win32.cpp @@ -994,12 +994,35 @@ bool MUtils::OS::change_process_priority(const QProcess *proc, const int priorit // PROCESS ID /////////////////////////////////////////////////////////////////////////////// -quint32 MUtils::OS::process_id(const QProcess *proc) +quint32 MUtils::OS::process_id(const QProcess *const proc) { PROCESS_INFORMATION *procInf = proc->pid(); return (procInf) ? procInf->dwProcessId : NULL; } +/////////////////////////////////////////////////////////////////////////////// +// PROCESS SUSPEND/RESUME +/////////////////////////////////////////////////////////////////////////////// + +bool MUtils::OS::suspend_process(const QProcess *proc, const bool suspend) +{ + if(Q_PID pid = proc->pid()) + { + if(suspend) + { + return (SuspendThread(pid->hThread) != ((DWORD) -1)); + } + else + { + return (ResumeThread(pid->hThread) != ((DWORD) -1)); + } + } + else + { + return false; + } +} + /////////////////////////////////////////////////////////////////////////////// // SYSTEM TIMER ///////////////////////////////////////////////////////////////////////////////