From ed8cd12aeaf8551cae050e14fa60520c29b9b2fe Mon Sep 17 00:00:00 2001 From: pagefault <> Date: Wed, 23 May 2001 19:44:48 +0000 Subject: [PATCH] Fixed cpu usage when zsnes is not active --- zsnes/src/win/winlink.cpp | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/zsnes/src/win/winlink.cpp b/zsnes/src/win/winlink.cpp index 62d2f64a..383710de 100644 --- a/zsnes/src/win/winlink.cpp +++ b/zsnes/src/win/winlink.cpp @@ -196,10 +196,19 @@ extern int CurKeyReadPos; extern int KeyBuffer[16]; } +BYTE IsActivated = 1; + extern "C" void CheckPriority() { - if (HighPriority == 1) SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS); - else SetPriorityClass(GetCurrentProcess(), NORMAL_PRIORITY_CLASS); + if (IsActivated == 1) + { + if (HighPriority == 1) SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS); + else SetPriorityClass(GetCurrentProcess(), NORMAL_PRIORITY_CLASS); + } + else + { + SetPriorityClass(GetCurrentProcess(), IDLE_PRIORITY_CLASS); + } } extern "C" void CheckAlwaysOnTop() @@ -402,6 +411,8 @@ LRESULT CALLBACK Main_Proc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) ValidateRect(hWnd,NULL); break; case WM_ACTIVATE: + IsActivated = 1; + CheckPriority(); if(LOWORD(wParam)==WA_INACTIVE) { ChangeDisplaySettings(NULL,0); @@ -428,7 +439,9 @@ LRESULT CALLBACK Main_Proc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) case WM_KILLFOCUS: ChangeDisplaySettings(NULL,0); InputDeAcquire(); - break; + IsActivated = 0; + CheckPriority(); + break; case WM_DESTROY: ChangeDisplaySettings(NULL,0); PostQuitMessage(0);