API - colocar o monitor em stand by |
Top Previous Next |
|
If a device such as a monitor support Stand by mode then you can programmatically set the set in code. This will work with Windows95 and above.
To place a monitor into Stand by mode: SendMessage(Application.Handle, wm_SysCommand, SC_MonitorPower, 0) ;
To take it out of Stand by mode: SendMessage(Application.Handle, wm_SysCommand, SC_MonitorPower, -1) ;
Here is a snippet of code to try it out: On a new form, place a Command button, a timer and a ListBox.
Timer (use Object Inspector):
Enabled := False Interval := 15000
Add this event for the timer:
procedure TForm1.Timer1Timer(Sender: TObject);
begin ListBox1.Items.Add(FormatDateTime('h:mm:ss AM/PM',Time)) ; SendMessage(Application.Handle, wm_SysCommand, SC_MonitorPower, -1); end;
Command Button:
procedure TForm1.Button1Click(Sender: TObject);
begin ListBox1.Items.Add('--> ' + FormatDateTime('h:mm:ss AM/PM',Time)) ; Timer1.Enabled := not Timer1.Enabled ; SendMessage(Application.Handle, wm_SysCommand, SC_MonitorPower, 0) ; end;
After building the program I suggest exiting Delphi and execute the program from Explorer. Once you hit the Command Button the screen should go blank for 15 seconds.
Note: You should check in Control Panel if the computer supports power-saving features! Although many computers support this feature (Stand By), many have the feature disabled. |