Click here to Skip to main content
15,887,214 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
My problem is to get the status power of my desktop display in order to stop some applications when it is OFF (the computer being always ON, night as day)
Why under VB6? I explained a lot about that in the topic: https://www.codeproject.com/Messages/5956240/Re-Composite-video-or-s-video-in-VB6-using-msvidct (my name is Jacques THEBAULT).
Since this post, I successfully installed the last service pack (VB6SP6) and the last corrective file. I also got the MSDN files, even if they are not directly accessible from VB6 interface.
Nevertheless, I didn't succeed in using IMSVDevice.Power property...
However, I could read successfully MSVidCtl.Autosize property, which belongs to the same library: MSVidCtlLib.. (but which isn't of any interest for me!!!)
If someone has an explanation for that, or could give me another solution for my requirement, I'd be very grateful to him.
You'll find hereafter the code of my tries.

What I have tried:

VB
Private Sub Form_Load()

'Dim display As New IMSVidDevice  'NOK : utilisation incorrecte de New
Dim display As IMSVidDevice       'OK
'Dim display As New IMSVidDevice  'NOK : utilisation incorrecte de New

Dim p As Boolean
p = display.Power                 'NOK : variable objet non définie

Dim display2 As New MSVidCtl      'OK
p = display2.AutoSize             'OK
MsgBox p                          'OK

End Sub 
Posted
Updated 16-Aug-23 7:34am
v2

You have a bit of a problem.

There is nothing "Power" related in the MSVidCtl COM interfaces/classes. The MSVidCtl library is for video control, like TV output, tuning, Closed Captioning, DVD playback, ... It has nothing to do with monitors and their states, like power.

You actually don't have any reliable method to get the power state of the monitors. There are no standards in place for such information to be populated in Windows and there is nothing that says a vendor has to comply with any such standards, if they existed.
 
Share this answer
 
There is an article here on Code Project that is specific to this task. It is in C++ though: Determining the Monitor's On/Off (sleep) Status[^]

Otherwise, here is a Google Search with a number of helpful possibilities: how to get the windows monitor on/off power state api - Google Search[^]

I stopped using VB6 a couple of decades ago, so I can not check the following for you. A 3rd option is to ask ChatGpt to write the code for you. Here is the question to ask:
Determining the Monitor's On/Off (sleep) Status using VB6

Then after asking the first question, use the following:
use POWERBROADCAST to receive notifications when the power status changes

ChatGpt can be more wrong than right. The code it generated appears to be okay and worth a try.

UPDATE

After Dave's comment below, I have been doing some digging and have come to the conclusion that there are no Windows APIs that support modern monitors to detect power status change.

There was a Microsoft WindowsAPICodePack that included Monitor On support, amongst many other things. However Microsoft pulled it and removed all traces of it.

If you want to check it out, here is the discussion: Check if display is turned off by windows power management | StackOverflow[^] and following the links in the threads, points you to a copy of the original repo: GitHub - dbarros/WindowsAPICodePack: A fork of the Windows API Code Pack with additional fixes and features by yours truly.[^].
 
Share this answer
 
v5
Comments
Dave Kreskowiak 16-Aug-23 17:52pm    
That article doesn't work for getting the power state of the monitors, at least not my machine and my monitors are only 4 years old.
Graeme_Grant 16-Aug-23 18:16pm    
I can't comment as I am not a C++ developer. There are comments from 2020 that it works. I can only take it on face value.

My 3rd solution offers 2 solutions, one being the POWERBROADCAST. I don't trust ChatGpt, however let us see how the OP goes.
Dave Kreskowiak 16-Aug-23 19:09pm    
The power state used to be supported by the VESA standard, but I don't think that's in use anymore.
Graeme_Grant 16-Aug-23 21:49pm    
You could say the same about VB6!
CHill60 17-Aug-23 10:04am    
If only! VB6 - the "gift" that keeps on giving, and on, and on ... :laugh:
Hello everybody
Thanks for your quick answers.
To be more precise, I don't try to use a property of MSVidCtl class but to use the class IMSVidDevice, which isn't a member of MSVidCtl itself, but comes in the same time when referencing "MS Video Control 1.0 type library". THIS class has a boolean property "Power". I just cannot use it !!
In the same time I tried to get another boolean property from MSVidCtl (my little code) just to check my syntax. In this case it works well !!
So I wondered if it could be a bug of my VB6 version or if comes from my way of writing the code ? I applied the last service pack and corrective to my installed VB6 and it doesn't change anything.
I also, as suggested in your anwers, made a lot of investigations on the net and I din't find nothing which could solve my problem nor any API relative to that (I mean under VB6).
Of course I found some solutions with C++ or VB.net but, as I explained, I'm not ready to learn these languages.
Finally I think that I'm probably looking for the impossible !
 
Share this answer
 
Comments
Richard MacCutchan 17-Aug-23 11:25am    
This is not a Solution. You should use the Improve question link above, and add complete details there. Or if you want to reply to a specific person then use the Have a Question or Comment? link below their Solutin.
THEBAULT Jacques 17-Aug-23 11:50am    
OK Richard
Thank you
I just began to use the forum, but now I have understood the good way to communicate
Dave Kreskowiak 17-Aug-23 12:18pm    
IMSVidDevice is an interface, not a class, hence it starts with an 'I'. It's still part of the Video Control library, and yes, it has been deprecated for years now. That interface does not do what you think it does. You cannot use it to get the power state of your monitors.

The problem is you have to get an instance a MSVidDevice class representing the devices using Video Control. Your problem is if you use the IMSVidOutputDevices interface to try and get a MSVidDevice object to get its properties on, you'll find MSVidOutputDevices returns ZERO objects. If you don't have an object, you cannot get its Power property.
THEBAULT Jacques 18-Aug-23 6:12am    
Dave,
I agree with your last comment, but when I select "IMSVidDevice" or "IMSVidOutputDevice" in the VB6 object explorer, I read :

"Class IMSVidOutputDevice (or IMSVidDevice as well; I think these are two aliases)
Member of MSVidCtlLib
MS Video Control Output Device Interface"

and when selecting "Power" in its members :

"Property Power As Boolean
Member of MSVidCtlLib.IMSVidDevice"

So I had however some hope to find a solution with this "interface"

I also tried :

Dim disp As Object
Set disp = CreateObject("IMSVidOutputDevice")

and I got the following error : "activeX component cannot create the object".
Finally the result is always the same : I cannot get an object and therefore it's not possible to use the property Power.

To conclude, I've made a lot of research in the net, as well as various tries with the suggested possibilities, and I found only APIs or classes related to system power management, or devices power state (EXCEPT for displays !), and not any related to display power state, except the "class" (?) or interface mentioned above.
Furthemore I found many comments and advices saying that "it is not possible to get the power status of a modern monitor"...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900