Why does this vb.net code fail?

J

jim

VB.net code to turn monitor on and off.......

<CODE>
Module Module1
Const HWND_BROADCAST As Integer = &HFFFF
Const SC_MONITORPOWER As Integer = &HF170
Const WM_SYSCOMMAND As Short = &H112S

Sub Main()
Dim instr As String = Command()
Select Case Command().ToLower
'Make sure it matches - and look at the commandline switch
Case "off"
TurnOff()
Case "on"
TurnOn()
Case "test"
TurnOff()
'turn off monitor
System.Threading.Thread.Sleep(10000)
'wait 10 seconds
TurnOn()
'turn on monitor
Case Else
MsgBox("Usage, [on]/[off]/[test] ", _
MsgBoxStyle.Information, _
"Need Command Switch")
End Select
End Sub

Private Function SendMessage(ByVal Handle As Int32, _
ByVal wMsg As Int32, ByVal wParam As Int32, _
ByVal lParam As Int32) As Int32

End Function

Sub StandBy()
SendMessage(HWND_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER, 1)
End Sub

Sub TurnOff()
SendMessage(HWND_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER, 2)
End Sub

Sub TurnOn()
SendMessage(HWND_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER, -1)
End Sub

End Module
</CODE>

According to the author (http://www.codeproject.com/useritems/Monitors.asp)
the code is supposed to allow you to turn off the monitor but it has no
effect at all on my XP Pro SP2 fully patched PC with LCD screen.

Any clues?
 
A

Armin Zingler

jim said:
VB.net code to turn monitor on and off.......

<CODE>
Module Module1
Const HWND_BROADCAST As Integer = &HFFFF
Const SC_MONITORPOWER As Integer = &HF170
Const WM_SYSCOMMAND As Short = &H112S

Sub Main()
Dim instr As String = Command()
Select Case Command().ToLower
'Make sure it matches - and look at the commandline
switch Case "off"
TurnOff()
Case "on"
TurnOn()
Case "test"
TurnOff()
'turn off monitor
System.Threading.Thread.Sleep(10000)
'wait 10 seconds
TurnOn()
'turn on monitor
Case Else
MsgBox("Usage, [on]/[off]/[test] ", _
MsgBoxStyle.Information, _
"Need Command Switch")
End Select
End Sub

Private Function SendMessage(ByVal Handle As Int32, _
ByVal wMsg As Int32, ByVal wParam As Int32, _
ByVal lParam As Int32) As Int32

End Function

Sub StandBy()
SendMessage(HWND_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER,
1) End Sub

Sub TurnOff()
SendMessage(HWND_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER,
2) End Sub

Sub TurnOn()
SendMessage(HWND_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER,
-1) End Sub

End Module
</CODE>

According to the author
(http://www.codeproject.com/useritems/Monitors.asp) the code is
supposed to allow you to turn off the monitor but it has no effect
at all on my XP Pro SP2 fully patched PC with LCD screen.

Any clues?


Your Funcstion SendMessage does Nothing. It is empty. Get the right
declaration:

http://www.google.com/search?as_q=S...as_dt=i&as_sitesearch=&as_rights=&safe=images


Armin
 
R

rowe_newsgroups

VB.net code to turn monitor on and off.......
<CODE>
Module Module1
Const HWND_BROADCAST As Integer = &HFFFF
Const SC_MONITORPOWER As Integer = &HF170
Const WM_SYSCOMMAND As Short = &H112S
Sub Main()
Dim instr As String = Command()
Select Case Command().ToLower
'Make sure it matches - and look at the commandline
switch Case "off"
TurnOff()
Case "on"
TurnOn()
Case "test"
TurnOff()
'turn off monitor
System.Threading.Thread.Sleep(10000)
'wait 10 seconds
TurnOn()
'turn on monitor
Case Else
MsgBox("Usage, [on]/[off]/[test] ", _
MsgBoxStyle.Information, _
"Need Command Switch")
End Select
End Sub
Private Function SendMessage(ByVal Handle As Int32, _
ByVal wMsg As Int32, ByVal wParam As Int32, _
ByVal lParam As Int32) As Int32
End Function
Sub StandBy()
SendMessage(HWND_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER,
1) End Sub
Sub TurnOff()
SendMessage(HWND_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER,
2) End Sub
Sub TurnOn()
SendMessage(HWND_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER,
-1) End Sub
End Module
</CODE>
According to the author
(http://www.codeproject.com/useritems/Monitors.asp) the code is
supposed to allow you to turn off the monitor but it has no effect
at all on my XP Pro SP2 fully patched PC with LCD screen.
Any clues?

Your Funcstion SendMessage does Nothing. It is empty. Get the right
declaration:

http://www.google.com/search?as_q=SendMessage+declare+function+intptr...

Armin

Or check pinvoke.net for the correct declaration:

http://www.pinvoke.net/default.aspx/user32/SendMessage.html

Thanks,

Seth Rowe
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top