🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Returning from power saving, Windows message trouble

Started by
1 comment, last by Shaarigan 2 years, 5 months ago

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.

Crealysm game & engine development: http://www.crealysm.com

Looking for a passionate, disciplined and structured producer? PM me

Advertisement

I guess you have multiple attacking points to this. WMWINDOWPOSCHANGED is send whenever the window moves while WMSIZE is send on resizing. Both should be handled to see if you're still in fullscreen mode. Also WM_STYLECHANGED could be used to see if the window got a border and title bar again.

How do you switch into fullscreen mode, is it still the old way of calling ChangeDisplaySettings? If so, couldn't you hook into this and get notified when the DPS change again or query if you're still in the desired DPS?

This topic is closed to new replies.

Advertisement