There's actually two minor flaws in the sample code you posted on the Steam forums:
1. wParam needs to be ANDed with 0xFFF0 first.
MSDN wrote:
In WM_SYSCOMMAND messages, the four low-order bits of the wParam parameter are used internally by the system. To obtain the correct result when testing the value of wParam, an application must combine the value 0xFFF0 with the wParam value by using the bitwise AND operator.
2. The checks should only be done when emulation is actually active, otherwise if you leave emulation paused and walk away it'll never go into power saving mode.
There's also the minor detail that if you've got Windows set to lock the workstation when the screen saver kicks in, it will
ignore your program's request to not do so.
MSDN wrote:
If password protection is enabled by policy, the screen saver is started regardless of what an application does with the SC_SCREENSAVE notification—even if fails to pass it to DefWindowProc.
Thus, the correct code should probably look something like this (copy/pasted from Nintendulator):
Code:
case WM_SYSCOMMAND:
// disallow screen saver while emulating (doesn't work if password protected)
if (running && (((wParam & 0xFFF0) == SC_SCREENSAVE) || ((wParam & 0xFFF0) == SC_MONITORPOWER)))
return 0;
// otherwise, proceed to DefWindowProc