PDA

View Full Version : Detecting if Monitor is On/Off



Ron
October 13th, 2002, 12:55 PM
I think its possible to catch WM_POWERBROADCAST Messages, but if there is a function that lets you query the state,.. hmm a quick google on this doesn't give any results either.

Although I did find this

GetDevicePowerState
here
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/hardware/power_2c4z.asp

But can we get a handle to the display ?

Ron
October 13th, 2002, 12:55 PM
I have a feeling it should be something like this:


dr := '\.somedevicenamehere';
d := CreateFile(PCHAR(dr),GENERIC_READ, 0,nil,OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL,0);

But I have no idea what the name of the device should be.

-Ron

<font size=-1>[ This Message was edited by: RonB on 2002-03-26 21:34 ]</font>

Ron
October 13th, 2002, 12:55 PM
That one returns a name and a hDC.

The name is not very trustable. Fails on some hardware, and the hDC is not the right handle i guess.

Ron
October 13th, 2002, 12:55 PM
It really should be possible :smile: It would be crazy if it isn't, Windows knows about the power state of the monitor, thus we should be able to query it somehow.... did you try google ?

Ron
October 13th, 2002, 12:55 PM
SendMessage(Settings.MainWindow, WM_SYSCOMMAND, SC_MONITORPOWER, 2);

Ron
October 13th, 2002, 12:55 PM
HANDLE disp;

disp = CreateFile( "\\.\Display1",GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,F ILE_ATTRIBUTE_READONLY,NULL);

if ( disp == INVALID_HANDLE_VALUE )
{
printf("Error openingn");
return 0;
}


if ( GetDevicePowerState(disp) )
{
printf("Onn");
}
else
{
printf("Offn");
}

CloseHandle(disp);
return 0;


So this is what we have so far, the only problem is as reported we don't get access to the //./display1 file. Maybe something with privileges.

<font size=-1>[ This Message was edited by: RonB on 2002-03-27 18:52 ]</font>

MMcM
October 13th, 2002, 12:55 PM
There are a number of google messages from people who were unable to find a way to do just this. http://groups.google.com/groups?q=getdevicepowerstate&hl=en

mattwire
October 13th, 2002, 12:55 PM
Does anyone know of any way to detect whether the monitor is currently On or Off?
The Monitor Plugin allows you to turn the monitor on/off but the monitor can be turned on by mouse movement etc meaning that monitor on/off functions by remote get out of sync when using states.

mattwire
October 13th, 2002, 12:55 PM
I wondered about using GetDC(NULL) as this should retrieve a handle to the screen. I guess its the wrong type of screen though!
VC++ crashed when I tested it.

mattwire
October 13th, 2002, 12:55 PM
I wonder whether EnumDisplayDevices would retrieve the name of the device?

mattwire
October 13th, 2002, 12:55 PM
Shame, it seems like it's gonna be impossible-ish!
I could probably 'guess' that the monitor is back on by changing a register when any key pressed/mouse moved.
Do we have any mouse plugins?
Or any way to detect mouse movement?
Or will I have to code something?

mattwire
October 13th, 2002, 12:55 PM
Yep, I've checked Google - nothing!
What API's do you use to turn the monitor off? (it might give me a base to find what I need!).

mattwire
October 13th, 2002, 12:55 PM
It sounds like there's no way to get access to \.display1 because people on google seem to have been unsuccessful.
I found this in the directX 8.1 SDK:
"IMSVidDevice.Power" which should return the powerstate as boolean of the device - just one small problem - it says 'WinXP only'...:sad: