Search code examples
winapisleeppower-managementmultiple-monitors

Make multiple monitors go to sleep with Windows API?


How exactly would I make both of my monitors go to sleep, I want to write an application myself because I'd like to add certain functionality, and so far I can't find anything on MSDN relating to making your display go to sleep.


Solution

  • You want something like:

    SendMessage(HWND_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER, (LPARAM) 2);
    

    It should work on dual monitors.

    Although it might be best not to use HWND_BROADCAST, but instead to use a HWND from your app's own window. You don't say what language you're using, but if it's C# or VB.NET, there are plenty of samples about demonstrating how to call this from those languages.