Angry Video Game Nerd Adventures

Angry Video Game Nerd Adventures

View Stats:
koitsu Sep 21, 2013 @ 4:18pm
Power saving profile (for screen blanking) kicks in while playing
More and more video games coming out these days appear to have this issue, and it's a disappointment because it's very simple to solve in Win32. I'm speaking about Windows systems, obviously.

If one's power profile settings include use of turning off the screen after N minutes (ex. on XP: Control Panel / Power Options / Power Schemes / Turn off monitor: After N minutes), the game does not inhibit this behaviour. So in my case, I have N set to 3, and after 3 minutes of playing my screen goes blank despite the game actively running/me pressing buttons on my joypad.

Solving this in Win32 code is *extremely* easy, costs virtually no CPU time, and is the Proper Way(tm) to solve the dilemma:

In your main WndProc CALLBACK routine, you need to handle a uMsg command of type WM_SYSCOMMAND + a wParam command of SC_MONITORPOWER or SC_SCREENSAVE and return 0 in that situation. That causes a person's power profile settings for screen blanking (SC_MONITORPOWER) and screen saver (SC_SCREENSAVE) to be inhibited (meaning they won't kick in) whenever your WndProc routine is called by the kernel (the kernel will attempt to call your WndProc with SC_MONITORPOWER when the timeout has been reached, same with a screen saver but for SC_SCREENSAVE). Example code:

LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch (uMsg) { case WM_SYSCOMMAND: { switch (wParam & 0xfff0) { case SC_MONITORPOWER: case SC_SCREENSAVE: return 0; } break; } } return DefWindowProc(hWnd, uMsg, wParam, lParam); }

The MSDN documentation for WM_SYSCOMMAND is here: http://msdn.microsoft.com/en-us/library/ms646360(VS.85).aspx

Also: please ***DO NOT*** solve this problem by using GetActivePwrScheme() followed by ReadPwrScheme() followed by adjusting VideoTimeoutAc / VideoTimeoutDc and then call SetActivePwrScheme(). This actually changes the power profile setting/scheme itself and is not the proper solution. What I described above is the correct solution.

I hope the authors of this game can implement this ASAP, as the only workaround is to manually go into the control panel and set the power profile setting to Never (0 minutes), and you have to remember to set it back when done playing.

Like I said: don't take it too personally, lots of games today make this mistake. It just indicates that there are too many developer teams who do not have their systems set to power off their monitors after N minutes, so QA/etc. never encounters the issue. Shame that.
Last edited by koitsu; Oct 6, 2013 @ 9:32pm
Date Posted: Sep 21, 2013 @ 4:18pm
Posts: 0