MFC missing a WM_ message I need
I have an MFC Dialog app that needs to handle WM_POWERBROADCAST so I can avoid standby mode.
In VS2005, I click my Dialog Class in Class View, then in the Class's Properties on the right, I click the Messages Button to view the available messages. There are many WM_ messages, but nothing to do with power. WM_POWERBROADCAST is not in the list.
How do I handle WM_POWERBROADCAST in MFC?
Re: MFC missing a WM_ message I need
Handle it using ON_MESSAGE macro.
Or you may implement PreTranslateMessage.
Re: MFC missing a WM_ message I need
ok thanks I'll remember that :)
ps. I found an alternative way to avoid standby.
SetThreadExecutionState(ES_SYSTEM_REQUIRED);
SetThreadExecutionState(ES_DISPLAY_REQUIRED);
Re: MFC missing a WM_ message I need
Quote:
Originally Posted by Anarchi
ok thanks I'll remember that :)
ps. I found an alternative way to avoid standby.
SetThreadExecutionState(ES_SYSTEM_REQUIRED);
SetThreadExecutionState(ES_DISPLAY_REQUIRED);
That's very interesting. Thanks for sharing :)
Re: MFC missing a WM_ message I need
That makes a lot of sense, didn't know those were there! Cool!
Btw, if you ever need to use another message not already there, you should just be able to add it to your program's message map, then create the function to handle it.
Re: MFC missing a WM_ message I need
The API is really cool and useful if you need to control that in our application.
But, after search in MSDN I could not find anything to stop ScreenSaver from coming.
Hope someone could find API to supress Screen Saver, as Media Player does.
Re: MFC missing a WM_ message I need
SC_SCREENSAVE and WM_POWERBROADCAST are both sent when Windows calls its screensaver.
SC_SCREENSAVE is only sent to the application with current focus though, so you might have to use WM_POWERBROADCAST.
Re: MFC missing a WM_ message I need
I think this code also stops the screen saver but not 100% sure.
SetThreadExecutionState(ES_SYSTEM_REQUIRED);
SetThreadExecutionState(ES_DISPLAY_REQUIRED);
If you call these functions every 30 seconds, it may do the trick.
Otherwise you can simply use this code to disable the SSaver (I hope its ok to post codeproject code here):
http://www.codeproject.com/system/disablescreensave.asp
Re: MFC missing a WM_ message I need
Quote:
Originally Posted by Anarchi
(I hope its ok to post codeproject code here):
It is absolutely okay - Brad won't mind :cool:
Re: MFC missing a WM_ message I need
Quote:
Originally Posted by Anarchi
I think this code also stops the screen saver but not 100% sure.
SetThreadExecutionState(ES_SYSTEM_REQUIRED);
SetThreadExecutionState(ES_DISPLAY_REQUIRED);
If you call these functions every 30 seconds, it may do the trick.
No, these functions are not guaranteed to block screensavers.
Quote:
Originally Posted by MSDN
This function does not always stop the screen saver from executing when the computer is in use.
Re: MFC missing a WM_ message I need
You can set the power variables too, I'm not sure if you already tried that, and what total effect they'll have, I do know you can use them for blocking the screen going into standby mode, maybe it'll stop a screensaver?
SPI_SETPOWEROFFTIMEOUT
SPI_SETLOWPOWERTIMEOUT
Also, in the sysem parameters, you can set
SPI_SETSCREENSAVETIMEOUT.