Skip navigation

Q: how do i manually shut off my monitor in windows xp?

A: Reach for the switch. you know, the physical power switch?

Ah. But you want to do it PROGRAMMATICALLY. Well

// console application
#include <windows.h>

#define SCREENSAVER_START 1
#define MONITOR_OFF 2

int main( int argc, char** argv )
{
  int cmd = SCREENSAVER_START; // default when run
  // is to start screensaver.

  // if passed command line argument (no matter
  // what it is), just turn off the monitor instead.
  if( argc > 1 )
  {
    // could check argv,
    cmd = MONITOR_OFF;
  }

  switch( cmd )
  {
  case SCREENSAVER_START:
      SendMessage( HWND_TOPMOST,
                 WM_SYSCOMMAND,
                 SC_SCREENSAVE,
                 0 );  // send message to top most window
  // for screensaver to start.  that's just
  // how you programmatically start the screensaver
  // under windows!
                 break;

    case MONITOR_OFF:
        SendMessage( HWND_BROADCAST,
                 WM_SYSCOMMAND,
                 SC_MONITORPOWER,
                 (LPARAM)2 ); // turn off the monitor.
                 break;
  }
}


I keep this executable in my start menu. I create 2 shortcuts:

One called “monitor off” that has target

C:\Documents and Settings\All Users\Start Menu\Programs\Monitor Control\MonitorControl.exe” off

The other is called “screensaver start” and has target:

C:\Documents and Settings\All Users\Start Menu\Programs\Monitor Control\MonitorControl.exe”

because running the executable with no arguments starts the screensaver.

One Comment

  1. 감사합니다. ㅇ_ㅇ”’
    thank you!


Leave a comment