Put monitor in standby

J

Jeroen

Hi,

I need an application to let the display go into sleep/standby mode while
the computer stays on. But only between set time windows (e.g. at night).
The app shows data on large format plasmas and don't need to display
information outside opening hours. But the computer does receive information
updates when the displays are in standby mode.

How do I turn off the display using VB.NET 2005/2008 Express Edition?



Jeroen
 
R

Ryan

Hi,

I need an application to let the display go into sleep/standby mode while
the computer stays on. But only between set time windows (e.g. at night).
The app shows data on large format plasmas and don't need to display
information outside opening hours. But the computer does receive information
updates when the displays are in standby mode.

How do I turn off the display using VB.NET 2005/2008 Express Edition?

Jeroen

I dove into the exact same project a few months ago. I concluded
after a lot of searching on Google and newsgroups that the required
Windows API calls were not exposed in a managed environment such
as .NET. I gave up after that and am going to probably use a low tech
solution consisting of a programmable timer to turn the display on and
off by controlling the AC power. My displays are 17" LCDs, though,
that will probably not be damaged by having their power abrubtly
removed. I am not sure if it is okay for a Plasma to be shut off like
that. It could damage it to not go through a shutdown/cool down
procedure.

I would lovbe for someone to correct me about the .NET environment and
calling the power APIs.

-Ryan
 
S

ShaneO

Jeroen said:
Hi,

I need an application to let the display go into sleep/standby mode while
the computer stays on. But only between set time windows (e.g. at night).
The app shows data on large format plasmas and don't need to display
information outside opening hours. But the computer does receive information
updates when the displays are in standby mode.

How do I turn off the display using VB.NET 2005/2008 Express Edition?



Jeroen

The following code does what you're looking for (Watch for wrapping) -

Public Declare Function PostMessage Lib "user32.dll" _
Alias "PostMessageA" _
(ByVal hwnd As IntPtr, _
ByVal wMsg As Int32, _
ByVal wParam As Int32, _
ByVal lParam As Int32) As Int32

Public Const WM_SYSCOMMAND = &H112&
Public Const SC_MONITORPOWER = &HF170& ' (-1)=On; 1=stdby; 2=Off

To use simply call -

PostMessage(Me.Handle, WM_SYSCOMMAND, SC_MONITORPOWER, 2&)


Note that you can also programmatically turn the screen back-on.


ShaneO

There are 10 kinds of people - Those who understand Binary and those who
don't.
 
H

Herfried K. Wagner [MVP]

ShaneO said:
The following code does what you're looking for (Watch for wrapping) -

Public Declare Function PostMessage Lib "user32.dll" _
Alias "PostMessageA" _

=> 'Declare Auto Function' and drop the alias.
Public Const WM_SYSCOMMAND = &H112&
Public Const SC_MONITORPOWER = &HF170& ' (-1)=On; 1=stdby; 2=Off

Remove the trailing '&' which stands for 'Long'. However, the constants
should be of type 'Int32'.
 
J

Jeroen

Okay, I also found this one. But...

Me.Handle doesn't exist in a console app.


Jeroen
 
R

Ryan

Okay, I also found this one. But...

Me.Handle doesn't exist in a console app.

Jeroen

"Herfried K. Wagner [MVP]" <[email protected]> schreef in bericht




- Show quoted text -

Wow. That's fantastic and saves me a lot of trouble. It works just
like I hoped it would. Thanks, ShaneO.
 
S

ShaneO

Jeroen said:
Okay, I also found this one. But...

Me.Handle doesn't exist in a console app.
Sorry, my crystal ball must not be working properly, as I didn't detect
that your application was a Console app! :)

In this case use the Desktop hwnd. (Un-Tested)

From memory, use -

Function GetDesktopWindow Lib "user32" () As Long (using the correct
..NET syntax)

That should get you going.

ShaneO

There are 10 kinds of people - Those who understand Binary and those who
don't.
 
H

Herfried K. Wagner [MVP]

ShaneO said:
Function GetDesktopWindow Lib "user32" () As Long (using the correct .NET
syntax)

'As Long' => 'As IntPtr'. In addition, you'll have to use the 'Declare'
keyword ;-).
 

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