views:

1986

answers:

4

Hi,

I'm already using some code to turn off the monitor power but I'm still with a little problem.

The code works fine most of times but once a in a while, the monitor turns blank. What I mean by this is that the screen is totally black, you can't see anything, but you can see it's still lit. The LCD light is still turned on but the screen is completely black.

I have no idea why this happens, maybe some of you know why... This will never happen if I set Windows Power settings to turn the monitor off after X minutes, but I need an application to do this so I can call it with a shortcut whenever I want.

The code I'm using is something like this:

[System.Runtime.InteropServices.DllImport("user32.dll")]
private static extern int SendMessage(int hWnd, int hMsg, int wParam, int lParam);

const int WM_SYSCOMMAND   = 0x0112;
const int SC_MONITORPOWER = 0xF170;
const int HWND_BROADCAST  = 0xFFFF;

SendMessage(HWND_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER, 2);

Any ideas?

+1  A: 

Have you tested this on multiple machines? Could be a driver problem...

Rex M
Nope, only on mine. That's the one I want it to work on...
Nazgulled
+3  A: 

You don't want to be broadcasting that message to all windows. You are relying on every one of them to process it as you are expecting.

You need to create your own and only send the message to it so you can control the behavior.

There's a few solutions in the comments of this post by Raymond Chen: http://blogs.msdn.com/oldnewthing/archive/2006/06/13/629451.aspx

Mufaka
+1 broadcasting can cause lots of nasty issues.
Sam Saffron
I'll read that link when I get the chance and report back :)
Nazgulled
It didn't work... The LCD light doesn't turn off all the time :(
Nazgulled
A: 

Nothing worked, I created my own Window and used that Window handle and most of the times, the screen is turned off and it's completely black (LCD light turned off), but every once in a while, the LCD light doesn't turn off... :(

Nazgulled
A: 

i've got this problem too. machines often work ok, and then for no known reason, wont allow the screens to sleep. I can't find a concrete commonality.

It even happens when machines are logged out. Usually 1 reboot will clear the problem. Not always.

I've even seen the screens wake up and refuse to sleep again on a machine that was logged out, and no one interacted with it.

Obviously there is a some process or processes to blame, but how do you trace them?