471,319 Members | 1,676 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,319 software developers and data experts.

Monitor status

Is there a way to query the monitor status, to know if it is on or off
in C#? I found that WM_SYSCOMMAND is sent to WndProc when the monitor
goes on and off but im not sure to find out if that message is always
just about the monitor.

Thanks for any help.

Jan 5 '06 #1
7 12723
Nevermind...
WM_SYSCOMMAND does not notify WndProc. So does anyone know what does
notify WndProc when the monitor backlight comes back on?

Jan 5 '06 #2
> Is there a way to query the monitor status, to know if it is on or off
in C#? I found that WM_SYSCOMMAND is sent to WndProc when the monitor
goes on and off but im not sure to find out if that message is always
just about the monitor.

Thanks for any help.


How are you going to code if your monitor is off? ;)
Jan 5 '06 #3
Hi,

I think you asked this yesterday !
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Dave" <dc*****@gmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
Is there a way to query the monitor status, to know if it is on or off
in C#? I found that WM_SYSCOMMAND is sent to WndProc when the monitor
goes on and off but im not sure to find out if that message is always
just about the monitor.

Thanks for any help.

Jan 5 '06 #4
I did but no one answered my question. I think most people
misunderstood me.

When the machine is idle for 20 mins (or however long it is set in
Power Options) the monitor backlight turns off. The power button is
not pressed on the monitor. My application plays many different types
of media including movies and audio. But when they press a button to
make the monitor go to sleep (or the backlight turning off) everything
is paused. Now my problem is that when the mouse is moved or a key is
pressed the monitor automatically comes back on. I want to know when
this happens so that i can start the media files to play again.

Thanks again for the help.

Jan 5 '06 #5
If there is not a way to determine this, is there at least a way to
tell when the mouse is clicked? Anywhere on the screen?

Jan 5 '06 #6

"Dave" <dc*****@gmail.com> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.com...
I did but no one answered my question. I think most people
misunderstood me.

When the machine is idle for 20 mins (or however long it is set in
Power Options) the monitor backlight turns off. The power button is
not pressed on the monitor. My application plays many different types
of media including movies and audio. But when they press a button to
make the monitor go to sleep (or the backlight turning off) everything
is paused. Now my problem is that when the mouse is moved or a key is
pressed the monitor automatically comes back on. I want to know when
this happens so that i can start the media files to play again.

Thanks again for the help.


I assume you are talking about power management features that are enabled on
your system.
While it's not possible to detect when the monitor is turned off due to
power management actions, it's quite possible to detect when a system enters
the 'suspend' state and returns from suspend state.

The following simple console sample shows you how you can use
System.Managent to watch these power status events.
using System;
using System.ComponentModel;
using System.Runtime.InteropServices;
using System.Management;
class Program {
public static void Main() {
Program we = new Program();
ManagementEventWatcher w= null;
WqlEventQuery q = new WqlEventQuery();;
ManagementOperationObserver observer = new ManagementOperationObserver();
// Bind to local machine
ManagementScope scope = new ManagementScope("root\\CIMV2");
try {
q.EventClassName = "Win32_PowerManagementEvent";
Console.WriteLine(q.QueryString);
w = new ManagementEventWatcher(scope, q);

w.EventArrived += new EventArrivedEventHandler(we.UsbEventArrived);
w.Start();
Console.ReadLine(); // block main thread for test purposes only
}
finally {
w.Stop();
}
}
public void UsbEventArrived(object sender, EventArrivedEventArgs e) {
//Get the Event object and display it
foreach(PropertyData pd in e.NewEvent.Properties) {
Console.WriteLine("\n================Power event===================");
Console.WriteLine("{0}", pd.Value); // possible values 4, 7, 10, 11, 18
see WMI SDK docs
}
}
}
Willy.
Jan 5 '06 #7
Hi,

"Dave" <dc*****@gmail.com> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.com...
I did but no one answered my question. I think most people
misunderstood me.
U had some reply , from Willy and from me IIRC.
When the machine is idle for 20 mins (or however long it is set in
Power Options) the monitor backlight turns off. The power button is
not pressed on the monitor. My application plays many different types
of media including movies and audio. But when they press a button to
make the monitor go to sleep (or the backlight turning off) everything
is paused. Now my problem is that when the mouse is moved or a key is
pressed the monitor automatically comes back on. I want to know when
this happens so that i can start the media files to play again.


You can get a notification when the system enters suspends , the most
visible consequence of this is the display been turned off, but possible the
HDD is also stopped, etc.

What we said before is that it's a one way communication, from the computer
to the monitor, if you physically turn off the monitor the system gets no
notification.

Check willy post for some code to detect when the power notification
changes.

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
Jan 6 '06 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Michel G | last post: by
2 posts views Thread by Mike | last post: by
10 posts views Thread by Mark | last post: by
3 posts views Thread by AndersBj | last post: by
5 posts views Thread by Laetitia | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.