CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 11 of 11
  1. #1
    Join Date
    Nov 2001
    Posts
    244

    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?

  2. #2
    Join Date
    Mar 2003
    Location
    India {Mumbai};
    Posts
    3,871

    Re: MFC missing a WM_ message I need

    Handle it using ON_MESSAGE macro.
    Or you may implement PreTranslateMessage.
    My latest article: Explicating the new C++ standard (C++0x)

    Do rate the posts you find useful.

  3. #3
    Join Date
    Nov 2001
    Posts
    244

    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);

  4. #4
    Join Date
    Nov 2003
    Location
    Belgium
    Posts
    8,150

    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
    Marc Gregoire - NuonSoft (http://www.nuonsoft.com)
    My Blog
    Wallpaper Cycler 3.5.0.97

    Author of Professional C++, 4th Edition by Wiley/Wrox (includes C++17 features)
    ISBN: 978-1-119-42130-6
    [ http://www.facebook.com/professionalcpp ]

  5. #5
    Join Date
    Oct 2007
    Location
    Fredericksburg, VA
    Posts
    41

    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.

  6. #6
    Join Date
    Mar 2003
    Location
    India {Mumbai};
    Posts
    3,871

    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.
    My latest article: Explicating the new C++ standard (C++0x)

    Do rate the posts you find useful.

  7. #7
    Join Date
    Oct 2007
    Location
    Fredericksburg, VA
    Posts
    41

    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.

  8. #8
    Join Date
    Nov 2001
    Posts
    244

    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

  9. #9
    Join Date
    Mar 2003
    Location
    India {Mumbai};
    Posts
    3,871

    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
    My latest article: Explicating the new C++ standard (C++0x)

    Do rate the posts you find useful.

  10. #10
    Join Date
    Nov 2003
    Location
    Belgium
    Posts
    8,150

    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.
    Marc Gregoire - NuonSoft (http://www.nuonsoft.com)
    My Blog
    Wallpaper Cycler 3.5.0.97

    Author of Professional C++, 4th Edition by Wiley/Wrox (includes C++17 features)
    ISBN: 978-1-119-42130-6
    [ http://www.facebook.com/professionalcpp ]

  11. #11
    Join Date
    Oct 2007
    Location
    Fredericksburg, VA
    Posts
    41

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured