Turning monitor off- only works on some machines

C

Craig Graham

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.
 
H

Herfried K. Wagner [MVP]

* "Craig Graham said:
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'.
 
G

Guest

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 said:
I'm trying to get some VB.NET code to turn off the backlight of the LC
monitor on a machine we've built
' 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'
 
H

Herfried K. Wagner [MVP]

* "=?Utf-8?B?QWxleA==?= said:
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?
 
G

Guest

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==?= said:
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?
 

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