Hi all,
I'm struggling a bit with handling power saving in Windows, and then returning back to my Win32 application.
My application has a bool which makes the user decide to either ignore power saving or to handle it properly.
When it's set to ignore, I handle SC_MONITORPOWER myself, which works, the display won't go off:
case WM_SYSCOMMAND:
{
if(LOWORD(wParam) == SC_SCREENSAVE) { return 0; }; // catching the message prevents screensaver
if(mIgnorePowerSaving && (LOWORD(wParam) == SC_MONITORPOWER)) { return 0; }
return 1;
}
And in the case that I don't ignore power saving, I handle it like this:
// Pause application when monitoring goes out/ power saving occurs
case WM_POWERBROADCAST:
if(!mIgnorePowerSaving)
{
if(LOWORD(wParam) == PBT_POWERSETTINGCHANGE)
{
POWERBROADCAST_SETTING *tSetting = reinterpret_cast<POWERBROADCAST_SETTING*>(lParam);
if(tSetting->Data[0] == 0x0) // monitor off, send pause action
{
CLOG(DEBUG, "GAMEBASE") << "TRACK: PBT_POWERSETTINGCHANGE -> monitor off!";
mInputManager.AddAction(INPUT::CONTEXT::INGAME, INPUT::ACTION::PAUSE_GAME);
}
if(tSetting->Data[0] == 0x1) // monitor on - do nothing { }
{
CLOG(DEBUG, "GAMEBASE") << "TRACK: PBT_POWERSETTINGCHANGE -> monitor on!";
}
return 0;
}
}
return 1;
This all works, but there's 1 issue.
When the monitoring turns on again, I see the log line as expected (Monitor ON), but somehow Windows switches my application from fullscreen to windowed. I've added breakpoints and logs in all my own entrypoints that change from fullscreen to windowed, but none is triggered. This is confirmed by the fact that my fullscreen flag is still set to true, when the monitor turned on again.
The hacky way around this is easy, just force to set to fullscreen after the monitor on message, when the settings flag says it's in fullscreen.
But this doesn't feel like the proper way. Does anybody know what/ which message triggers this switching to windowed? So I can handle it properly.