Get monitor state

Posted on 2004-10-08
Last Modified: 2010-04-05

Is it possible to get the state of the monitor (turned on/off, standby)? If so, how do I do it?

The WMI (Windows Management Instrumentation) Win32_DesktopMonitor class ( contains the information I need (Availability), but the Win32_DesktopMonitor class does not update real time.

Are there any other way to get this information?

Thanks in advance.

Question by:Michael G
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 12

Expert Comment

ID: 12266053
You can handle WM_SYSCOMMAND. When monitor is being turned on/off the wParams is SC_MONITORPOWER      ...

Author Comment

by:Michael G
ID: 12269569
Thank you for your comment.

I have the following code which can tell me when powersafe gets activated, but it doesn't react if I turn off my monitor !?

unit Unit1;


  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

  TForm1 = class(TForm)
    Memo1: TMemo;

    procedure WMSysCommand(var Message : TWMSysCommand ); Message WM_SYSCOMMAND;
    { Private declarations }

    { Public declarations }

  Form1: TForm1;


{$R *.dfm}

procedure TForm1.WMSysCommand(var Message : TWMSysCommand);
// Intercept screen saver or power monitor message and do something ...
  if (Message.CmdType and $FFF0 = SC_SCREENSAVE) or
     (Message.CmdType and $FFF0 = SC_MONITORPOWER) then
     memo1.Lines.Add(datetimetostr(now)+ ': Powersafe activated or monitor power off')
  inherited; // let the message thru'
end; {WMSysCommand}

LVL 12

Expert Comment

ID: 12270926
Yep, I know about this. I couldn't make it work with monitor turned off...
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

by:Michael G
ID: 12271123
So it's not possible to detect if you turn off your monitor !?
LVL 17

Expert Comment

by:Wim ten Brink
ID: 12271996
Maybe some smarter monitors will signal the system that the monitor is turned off, but afaik, this is extremely uncommon. Many laptops will keep track of the monitor state of the LCD screen but I don't think this information is sent to the system. It's just used to turn off the monitor when you close the lid of the laptop.

Author Comment

by:Michael G
ID: 12865770
I never really solved the problem, but found a more or less working workaround.

I use a WMSysCommand, see below, to detect if powersave is activated, and then I use a global keyboard/mouse hook to detect user input that takes the monitor out of powersaving.

procedure TForm1.WMSysCommand(var Message : TWMSysCommand);
// Intercept screen saver or power monitor message and do something ...
  if  (Message.CmdType and $FFF0 = SC_SCREENSAVE) or(Message.CmdType and
$FFF0 = SC_MONITORPOWER) then begin

    memo1.Lines.Add(datetimetostr(now)+ ': powersave')
  end; {if}
  inherited; // let the message thru'
end; {WMSysCommand}

Author Comment

by:Michael G
ID: 13343683

Accepted Solution

OzzMod earned 0 total points
ID: 13369542
Closed, 500 points refunded.
Community Support Moderator (Graveyard shift)

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question