Pulkit Gaur

dream - do - deserve

Controlling Monitor Power - Switch On / Switch Off

Filed under: Visual Basic at 03:28:25 On 2006-11-18

Nothing new ..

 

but this code fragment will allow you to control your terminal display to be switch on or off.

Well you may use it to schedule your monitor power after a predetmined time instead of screensaver - go greener :)

 

 

To use this code put this code in your form code and put 2 buttons on the form.

 

Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Any) As Long
Const SC_MONITORPOWER = &HF170&
Const MONITOR_ON = -1&
Const MONITOR_OFF = 2&
Const WM_SYSCOMMAND = &H112

Private Sub Command1_Click()
SendMessage Me.hWnd, WM_SYSCOMMAND, SC_MONITORPOWER, MONITOR_OFF
Command2.SetFocus
End Sub

Private Sub Command2_Click()
SendMessage Me.hWnd, WM_SYSCOMMAND, SC_MONITORPOWER, MONITOR_ON
End Sub