Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How to stop PC suspending or sleeping while app is running..

How to stop PC suspending or sleeping while app is running..

Scheduled Pinned Locked Moved C / C++ / MFC
jsontutorialquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    montiee
    wrote on last edited by
    #1

    Can anyone tell me the API I can use so that while my app is running it doesn't allow the OS to go into sleep or suspend mode? What must I do. Thanks!

    P 1 Reply Last reply
    0
    • M montiee

      Can anyone tell me the API I can use so that while my app is running it doesn't allow the OS to go into sleep or suspend mode? What must I do. Thanks!

      P Offline
      P Offline
      Perspx
      wrote on last edited by
      #2

      Assuming you're developing on Windows, take a look at the WM_POWERBROADCAST message (docs here) which is sent to all top-level window procedures when a power state is about to change. To prevent Windows going into standby/sleep mode, check whether the wParam is PBT_APMQUERYSUSPEND, and if so, return BROADCAST_QUERY_DENY when processing this message (Win 2k3, Win XP and Win 2k). However, for Windows Vista, use the SetThreadExecutionState() function (docs here), which can prevent the system entering sleep mode. It is also supported in Win XP and Win 2k Pro. Regards, --Perspx

      "The Blue Screen of Death, also known as The Blue Screen of Doom, the "Blue Screen of Fun", "Phatul Exception: The WRECKening" and "Windows Vista", is a multi award-winning game first developed in 1995 by Microsoft" - Uncyclopedia Introduction to Object-Oriented JavaScript

      M 1 Reply Last reply
      0
      • P Perspx

        Assuming you're developing on Windows, take a look at the WM_POWERBROADCAST message (docs here) which is sent to all top-level window procedures when a power state is about to change. To prevent Windows going into standby/sleep mode, check whether the wParam is PBT_APMQUERYSUSPEND, and if so, return BROADCAST_QUERY_DENY when processing this message (Win 2k3, Win XP and Win 2k). However, for Windows Vista, use the SetThreadExecutionState() function (docs here), which can prevent the system entering sleep mode. It is also supported in Win XP and Win 2k Pro. Regards, --Perspx

        "The Blue Screen of Death, also known as The Blue Screen of Doom, the "Blue Screen of Fun", "Phatul Exception: The WRECKening" and "Windows Vista", is a multi award-winning game first developed in 1995 by Microsoft" - Uncyclopedia Introduction to Object-Oriented JavaScript

        M Offline
        M Offline
        montiee
        wrote on last edited by
        #3

        Thanks for the pointers. I did end up using SetThreadExecutionState() as I really didn't need the fine control WndProc and it's power handling functionality offered. Nice and easy. Cheers!

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups