473,765 Members | 2,061 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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().ToLow er
'Make sure it matches - and look at the commandline switch
Case "off"
TurnOff()
Case "on"
TurnOn()
Case "test"
TurnOff()
'turn off monitor
System.Threadin g.Thread.Sleep( 10000)
'wait 10 seconds
TurnOn()
'turn on monitor
Case Else
MsgBox("Usage, [on]/[off]/[test] ", _
MsgBoxStyle.Inf ormation, _
"Need Command Switch")
End Select
End Sub

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

End Function

Sub StandBy()
SendMessage(HWN D_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER , 1)
End Sub

Sub TurnOff()
SendMessage(HWN D_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER , 2)
End Sub

Sub TurnOn()
SendMessage(HWN D_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 2301
jim
I should have mentioned it is a console app.....sorry.. ...

"jim" <ji*@home.netwr ote in message
news:Ip******** *********@bigne ws1.bellsouth.n et...
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().ToLow er
'Make sure it matches - and look at the commandline switch
Case "off"
TurnOff()
Case "on"
TurnOn()
Case "test"
TurnOff()
'turn off monitor
System.Threadin g.Thread.Sleep( 10000)
'wait 10 seconds
TurnOn()
'turn on monitor
Case Else
MsgBox("Usage, [on]/[off]/[test] ", _
MsgBoxStyle.Inf ormation, _
"Need Command Switch")
End Select
End Sub

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

End Function

Sub StandBy()
SendMessage(HWN D_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER , 1)
End Sub

Sub TurnOff()
SendMessage(HWN D_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER , 2)
End Sub

Sub TurnOn()
SendMessage(HWN D_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.netsc hrieb
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().ToLow er
'Make sure it matches - and look at the commandline
switch Case "off"
TurnOff()
Case "on"
TurnOn()
Case "test"
TurnOff()
'turn off monitor
System.Threadin g.Thread.Sleep( 10000)
'wait 10 seconds
TurnOn()
'turn on monitor
Case Else
MsgBox("Usage, [on]/[off]/[test] ", _
MsgBoxStyle.Inf ormation, _
"Need Command Switch")
End Select
End Sub

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

End Function

Sub StandBy()
SendMessage(HWN D_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER ,
1) End Sub

Sub TurnOff()
SendMessage(HWN D_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER ,
2) End Sub

Sub TurnOn()
SendMessage(HWN D_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...@free net.dewrote:
"jim" <j...@home.nets chrieb
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().ToLow er
'Make sure it matches - and look at the commandline
switch Case "off"
TurnOff()
Case "on"
TurnOn()
Case "test"
TurnOff()
'turn off monitor
System.Threadin g.Thread.Sleep( 10000)
'wait 10 seconds
TurnOn()
'turn on monitor
Case Else
MsgBox("Usage, [on]/[off]/[test] ", _
MsgBoxStyle.Inf ormation, _
"Need Command Switch")
End Select
End Sub
Private Function SendMessage(ByV al Handle As Int32, _
ByVal wMsg As Int32, ByVal wParam As Int32, _
ByVal lParam As Int32) As Int32
End Function
Sub StandBy()
SendMessage(HWN D_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER ,
1) End Sub
Sub TurnOff()
SendMessage(HWN D_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER ,
2) End Sub
Sub TurnOn()
SendMessage(HWN D_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
3041
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
1306
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
2005
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 moveImage(e){ //shift image according to scroll
24
3820
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
2115
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 addresses larger words only? Shouldn't sizeof be defined to return the smallest number of 'storage units' required to store an object of the type of its operand? As a general point, is there a guide to what aspects of C would fail if run on a...
2
7798
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 can tell that the DataTable actually contains valid data. This is the code :
10
2397
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
2155
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 should work. Also the second nav.OuterXml appears to also be wrong to me. Can someone explain to me why this does not work? (This is an example from a program we have where xpath can be entered in two parts so we have to be able
14
4859
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 can be done using the designer but I intentionally don't want to use that. The one reason is that you cannot change the code generated by the designer. The other could be that you have more free hand and control to design your GUI. 2....
19
4200
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 = new CTestClientSocket(this, ip, port); pTemp->Connect(); m_collClients.push_back(pTemp);
0
9568
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10163
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10007
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9957
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8832
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5276
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5423
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3532
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2806
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.