Resolved Checking if computer turned off the monitor or not.

narasta

New member
Joined
Sep 28, 2021
Messages
2
Programming Experience
Beginner
Hello, I am trying using C# to enable a funcionality which allow an application to read current status of the Monitor. To determine if the monitor has been turned off or on by the computer to be exact.
screenshot-20210928121643.png

I have tried the above and in deed the event happens onpy when monitor is put into sleep or wokenn by by moving mouse/pressing a key on a keyboard. However the return value i get is always 2. I need also to thetermine the if the event was to suspend or to wake up the monitor. I have tried also different code snippets I have found on the internet but the one above gave best results so far. Not good enough though.

In theory the SC_MONITORPOWER (or the lParam to be percise) should return as follows:
screenshot-20210928121800.png

Yet it returns always a value of 2.

So far I am developing this on WIN10, but the target OS would be win7. As far as i know the Power Managament differs from win8 and up.
 
In the future, please post code in code tags, not as screenshots.
 
Is it possible that with the latest Win10 build that MS broke the API, and they now need to update the documentation? I would suggest putting in some feedback in MS's documentation page.

Of course, that still won't fix your issue where you aren't being notified when the monitor is being turn on or off. On one hand, if the monitor is off and you get another off notification, that logically can't be possible because the monitor is already off, so maybe keeping a boolean that you just toggle maybe the way to keep track. Admittedly, it's a kludgy solution.

You do realize that Win7 is out of support, right?
 
The reason I need the monitor state info is that target computer have a custom HDMI LCD panel connected. Unfortunatelly if it goes to sleep it will not turn of the backlight thus consuming power. The monitor will be operational like 5 minutes a day so the rest is pure waste of energy. In the system I have some custom usb-connected hardware to do other work but also have a funcionality to turn this backlight power on/off.

Using a toggled information would not be reliable because it can by mistake be toggled on wrong time thus resulting turning off the backlight when waking up the monitor.

Your suggestion have given me an idea to push the timeout to the custom hardware (regardless the setting in the windows). Then i would relay only on information that there has been an event (regardless if on/off). Then each time it comes just shut reset the timer and turn on the backlight till the timer goes off. If that would be a case i would also have to send an information to the hardware each time the mouse is used (in this case touchscreen touched) or keyboard press.

Support for older OSs is not an issue in this case as this is one time custom build device with corresponding software.

P.S. Sorry for posting an image of the code (I do not have an access to the code at the moment)
 
Back
Top Bottom