Programmatically prevent Windows screensaver from starting

后端 未结 13 2016
心在旅途
心在旅途 2020-12-03 00:58

Is there a recommended way to prevent the Windows screensaver from starting? The closest thing I\'ve found is this article, but what I would really like to do is just tell

13条回答
  •  抹茶落季
    2020-12-03 01:45

    This blog post details what you need to do in C++.

    The actual code snippet from the website:

    LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
    {
      switch (uMsg)                  
      {
        case WM_SYSCOMMAND:
        {
          switch (wParam)
          {
            case SC_SCREENSAVE:  
              return 0;
            case SC_MONITORPOWER:
              return 0;      
          }
          break;      
        }
    
        case WM_CLOSE:                
        {
          PostQuitMessage(0);            
          return 0;        
        }
      }
      return DefWindowProc(hWnd,uMsg,wParam,lParam);
    

    }

提交回复
热议问题