Solved

Get monitor state

Posted on 2004-10-08
10
611 Views
Last Modified: 2010-04-05
Hello.

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 (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/win32_desktopmonitor.asp) 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.

/Snebal
0
Comment
Question by:Michael G
10 Comments
 
LVL 12

Expert Comment

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

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;

interface

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

type
  TForm1 = class(TForm)
    Memo1: TMemo;

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

    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

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

end.
0
 
LVL 12

Expert Comment

by:Ivanov_G
ID: 12270926
Yep, I know about this. I couldn't make it work with monitor turned off...
0
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 

Author Comment

by:Michael G
ID: 12271123
So it's not possible to detect if you turn off your monitor !?
0
 
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.
0
 

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 ...
begin
  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}
0
 

Author Comment

by:Michael G
ID: 13343683
0
 

Accepted Solution

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

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to use Hashing sha1 in Delphi 2010 4 266
Mydac connection data base issue 3 157
delphi exception 7 64
RESTRequest Parameter 4 30
A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

776 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