By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
460,035 Members | 937 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 460,035 IT Pros & Developers. It's quick & easy.

Why does this vb.net code fail?

P: n/a
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?

Aug 1 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
jim
I should have mentioned it is a console app.....sorry.....

"jim" <ji*@home.netwrote in message
news:Ip*****************@bignews1.bellsouth.net...
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?

Aug 1 '07 #2

P: n/a
"jim" <ji*@home.netschrieb
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=Se...s=&safe=images
Armin

Aug 1 '07 #3

P: n/a
On Aug 1, 7:14 am, "Armin Zingler" <az.nos...@freenet.dewrote:
"jim" <j...@home.netschrieb
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=Se...unction+intptr...

Armin
Or check pinvoke.net for the correct declaration:

http://www.pinvoke.net/default.aspx/...ndMessage.html

Thanks,

Seth Rowe

Aug 1 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.