473,395 Members | 1,987 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Why does this vb.net code fail?

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
3 2273
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
"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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: Dave Murray | last post by:
New to Python question, why does this fail? Thanks, Dave ---testcase.py--- import sys, urllib, htmllib def Checkit(URL): try: print "Opening", URL
1
by: DiskMan | last post by:
System: Redhat 7.2 Kernel-2.6.11.8 GCC-3.4.3 CCC-6.5.9 Binutils-2.15 Make-3.80 GTK/GLIB-2.6.7 For some reason my Linux box is suddenly having issues trying to read ;
2
by: John | last post by:
The following code works OK in IE 6.0 but does not work in Netscape 7. The image does not shift when one scrolls down but stays stationary in Netscape. Please help Thank you John function...
24
by: David Mathog | last post by:
If this: int i,sum; int *array; for(sum=0, i=0; i<len; i++){ sum += array; } is converted to this (never mind why for the moment):
19
by: James Harris | last post by:
My K&R 2nd ed has in the Reference Manual appendix, A7.4.8 sizeof yields the number of BYTES required to store an object of the type of its operand. What happens if C is running on a machine that...
2
by: peter | last post by:
Hi, I try to bind a DataTable to a DataGrid, but I receive the following error-message : 'The IListSource does not contain any data sources'. I have no clue what the problem might be, as I...
10
by: Gunnar G | last post by:
I'm having problem reading from the beginning of a file. Here is the code (more or less) ifstream codefin; ofstream codefout; while (not_annoyed)
9
by: David Thielen | last post by:
Hi; I am sure I am missing something here but I cannot figure it out. Below I have a program and I cannot figure out why the xpath selects that throw an exception fail. From what I know they...
14
by: Anoop | last post by:
Hi, I am new to this newsgroup and need help in the following questions. 1. I am workin' on a GUI application. Does C# provides Layout Managers the way Java does to design GUI? I know that it...
19
by: Angus | last post by:
I have a socket class CTestClientSocket which I am using to simulate load testing. I create multiple instances of the client like this: for (int i = 0; i < 5; i++) { CTestClientSocket* pTemp...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.