Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to turn on/off the monitor(s)?

I wanted to be able to turn on/off my monitors from a Delphi script, from Windows XP to 7.

I have searched within the Delphi section on stackoverflow and didn't find the answer.

I also found many samples which doesn't work anymore on Windows 7 (only with XP).

like image 515
Whiler Avatar asked Sep 04 '11 10:09

Whiler


1 Answers

I have successfully tested this on Windows XP and Windows 7:

const
  MONITOR_ON      = -1;
  MONITOR_OFF     =  2;
  MONITOR_STANDBY =  1;

To turn off the monitor:

  SendMessage(Application.Handle, WM_SYSCOMMAND, SC_MONITORPOWER, MONITOR_OFF);

To turn on the monitor:

  SendMessage(Application.Handle, WM_SYSCOMMAND, SC_MONITORPOWER, MONITOR_ON);
like image 80
Whiler Avatar answered Oct 07 '22 17:10

Whiler