473,395 Members | 1,656 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.

Turning monitor off- only works on some machines

I'm trying to get some VB.NET code to turn off the backlight of the LCD
monitor on a machine we've built.

The code

**********
' For switching off the backlight
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA"
(ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam
As Long) As Long
Const SC_MONITORPOWER As Long = &HF170&
Const MONITOR_ON As Long = -1&
Const MONITOR_OFF As Long = 2&
Const WM_SYSCOMMAND As Long = &H112

SendMessage Me.hWnd, WM_SYSCOMMAND, SC_MONITORPOWER, MONITOR_OFF
************

works on a desktop machine running XP Home and a CRT monitor, however on a
laptop running XP Pro, a desktop machine with LCD monitor and XP pro and a
test machine with LCD monitor running Windows 2000 it simply fails silently.
It is the same code copied across, so there is no possibility of a typing
error. On both misbehaving machines, I've verified that if I set the power
management from Display Properties to turn off the monitor, the display and
backlight do indeed switch off. The LCD monitor is integrated into the
Win2000 machine so I cannot see if this is some bizarre problem with LCD and
CRT displays.

Googling has not helped, so I'm hoping someone here can cast some light on
this.

--
Dr. Craig Graham, Software Engineer
Advanced Analysis and Integration Limited, UK. http://www.aail.co.uk/

Nov 20 '05 #1
4 5805
* "Craig Graham" <cr***@twolips-translations.co.uk> scripsit:
I'm trying to get some VB.NET code to turn off the backlight of the LCD
monitor on a machine we've built.

The code

**********
' For switching off the backlight
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA"
(ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam
As Long) As Long
Replace all 'As Long' with 'As Int32', 'hWnd' should be declared as 'IntPtr'.
Const SC_MONITORPOWER As Long = &HF170&
Const MONITOR_ON As Long = -1&
Const MONITOR_OFF As Long = 2&
Const WM_SYSCOMMAND As Long = &H112
Dito.

SendMessage Me.hWnd, WM_SYSCOMMAND, SC_MONITORPOWER, MONITOR_OFF
************


--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #2
I have the same problem with Visual Basic 6.0 and the declaration is the same
How can i do to solve my problem? Somethimes works, but i need to use it to turn on the monitor after the switching off by OS

Thank

----- Herfried K. Wagner [MVP] wrote: ----

* "Craig Graham" <cr***@twolips-translations.co.uk> scripsit
I'm trying to get some VB.NET code to turn off the backlight of the LC
monitor on a machine we've built
The cod
********* ' For switching off the backligh
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA
(ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lPara
As Long) As Lon


Replace all 'As Long' with 'As Int32', 'hWnd' should be declared as 'IntPtr'
Const SC_MONITORPOWER As Long = &HF170&> Const MONITOR_ON As Long = -1&> Const MONITOR_OFF As Long = 2&> Const WM_SYSCOMMAND As Long = &H11


Dito
SendMessage Me.hWnd, WM_SYSCOMMAND, SC_MONITORPOWER, MONITOR_OF

***********


--
Herfried K. Wagner [MVP
<http://www.mvps.org/dotnet>
Nov 20 '05 #3
* "=?Utf-8?B?QWxleA==?=" <al******************@sella.it> scripsit:
I have the same problem with Visual Basic 6.0 and the declaration is the same.
How can i do to solve my problem? Somethimes works, but i need to use it to turn on the monitor after the switching off by OS.


I don't understand your problem. VB.NET isn't just a new version of the
Visual Basic Classic programming language. It's a new programming
language and code which works in VB Classic often won't work in VB.NET.
The declaration for 'SendMessage' is different in VB.NET and in VB
Classic. Which programming language are you using?

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #4
Actually, I 'm using Visual Basic 6.0, but the problem is the same.
My declaration is:
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const WM_SYSCOMMAND = &H112&
Private Const SC_MONITORPOWER = &HF170&

The function doesn't work because it try to power on the monitor, but after few milliseconds come back to power off.
After stand by of monitor, how can I resume the monitor to power on?
Which API can I use to solve my problem?

Thanks

----- Herfried K. Wagner [MVP] wrote: -----

* "=?Utf-8?B?QWxleA==?=" <al******************@sella.it> scripsit:
I have the same problem with Visual Basic 6.0 and the declaration is the same.
How can i do to solve my problem? Somethimes works, but i need to use it to turn on the monitor after the switching off by OS.


I don't understand your problem. VB.NET isn't just a new version of the
Visual Basic Classic programming language. It's a new programming
language and code which works in VB Classic often won't work in VB.NET.
The declaration for 'SendMessage' is different in VB.NET and in VB
Classic. Which programming language are you using?

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: Lee | last post by:
Hello All, First of all I would like to say thank you for all of the help I have received here. I have been teaching myself Access for about 4 years now and I've always been able to find a...
2
by: Jack David | last post by:
Using the code below I am able to monitor a single directory for a new file and then kick-off a process to deal with the file. The question is??? How would I modify this code to be able to monitor...
7
by: Dave | last post by:
Is there a way to query the monitor status, to know if it is on or off in C#? I found that WM_SYSCOMMAND is sent to WndProc when the monitor goes on and off but im not sure to find out if that...
1
by: Micah Hastings | last post by:
The last time I did this was back in Visual Basic 6. Now I am using VB.NET 2005. When I use my code now, it turns off the monitor just fine. However when I move my mouse the monitor comes back...
0
by: Robert | last post by:
After failing on a yield/iterator-continuation problem in Python (see below) I tried the Ruby (1.8.2) language first time on that construct: The example tries to convert a block callback interface...
4
by: NormD | last post by:
I am running Windows XP, and IE version 6.0.2900 on my desktop. It has the ..Net Framework Service Pack 1 installed on it. Security was turned off on the machine using "CASPOL -s off". A .Net...
0
by: Ed | last post by:
I want to know when the screensaver has kicked in on my monitor so that I can turn off the desk light in my office. Under XP it has worked great. I use the following to check if screensaver is...
13
by: Cross | last post by:
I am developing an application that will show movies. When you wach a movie, you do not want the Power Option "Turn off monitor" to be anabled. Is there anyway to fix this from VB.net? (note that I...
5
by: jbenner | last post by:
I have opened a PMR for this with IBM, and am not asking for advice from the DB2 DBA community. I am posting this as an FYI that DB2 Health Monitor, even at the latest version of DB2, still can cause...
6
by: Rain | last post by:
Hi, I noticed the other day when I was trying to optimise the traffic on a particular web page that it had significant viewstate even though I had turned it off for most of the controls. So in...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
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...
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...

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.