From a34644439e560c4d70972039f9b51bd75ca461fd Mon Sep 17 00:00:00 2001 From: Richard Stanway Date: Sun, 7 Jul 2013 21:24:27 -0400 Subject: [PATCH] Make mouse foreground window check more reliable --- GraphicsCapture/GraphicsCaptureSource.cpp | 13 ++++++++++++- GraphicsCapture/GraphicsCaptureSource.h | 3 +++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/GraphicsCapture/GraphicsCaptureSource.cpp b/GraphicsCapture/GraphicsCaptureSource.cpp index cad709a7..a408a4f8 100644 --- a/GraphicsCapture/GraphicsCaptureSource.cpp +++ b/GraphicsCapture/GraphicsCaptureSource.cpp @@ -261,6 +261,8 @@ void GraphicsCaptureSource::EndCapture() captureCheckInterval = -1.0f; hwndCapture = NULL; targetProcessID = 0; + foregroundPID = 0; + foregroundCheckCount = 0; if(warningID) { @@ -726,7 +728,14 @@ void GraphicsCaptureSource::Render(const Vect2 &pos, const Vect2 &size) //---------------------------------------------------------- // draw mouse - if(bMouseCaptured && cursorTexture && GetForegroundWindow() == hwndCapture) + if (!foregroundCheckCount) + { + //only check for foreground window every 10 frames since this involves two syscalls + GetWindowThreadProcessId(GetForegroundWindow(), &foregroundPID); + foregroundCheckCount = 10; + } + + if(bMouseCaptured && cursorTexture && foregroundPID == targetProcessID) { Vect2 newCursorPos = Vect2(float(cursorPos.x-xHotspot), float(cursorPos.y-xHotspot)); Vect2 newCursorSize = Vect2(float(cursorTexture->Width()), float(cursorTexture->Height())); @@ -748,6 +757,8 @@ void GraphicsCaptureSource::Render(const Vect2 &pos, const Vect2 &size) DrawSprite(cursorTexture, 0xFFFFFFFF, newCursorPos.x, newCursorPos.y, newCursorPos.x+newCursorSize.x, newCursorPos.y+newCursorSize.y); } + + foregroundCheckCount--; } if(lastShader) diff --git a/GraphicsCapture/GraphicsCaptureSource.h b/GraphicsCapture/GraphicsCaptureSource.h index 2e42bd25..e6bb87ff 100644 --- a/GraphicsCapture/GraphicsCaptureSource.h +++ b/GraphicsCapture/GraphicsCaptureSource.h @@ -53,6 +53,9 @@ class GraphicsCaptureSource : public ImageSource float captureCheckInterval; + DWORD foregroundPID; + DWORD foregroundCheckCount; + void NewCapture(); void EndCapture();