I'm currently dabbling into digital signage and I'm having troubles with a monitor turning off on me. My question is this : is there a way in C# code that I can tell if a monitor is currently on or off? I'm writing an alert system for me since I cannot correct the monitor's issue at this time.
I've tried looking into system.manager, system.environment, and systeminformation... but was unable to find anything which was able to tell me the monitor's current state.
Specs:
Monitor : Samsung TV
PC: Windows XP PRO 32-bit
Loading
naura paxPosted Jan 13, 2010, 3:52 AM
you need to define this function in your form class also .
//add this line at the top: using System.Runtime.InteropServices;
[DllImport("Kernel32.DLL", CharSet = CharSet.Auto,
SetLastError=true)]
private extern static
bool GetDevicePowerState(
IntPtr hDevice,
out bool fOn);
then call this function in your program, the return value of false (for fOn) means monitor is turned off, you'll need to pass the handle of the monitor device to this method ex.
public static void Main(String[] args)
{
bool fOn;
IntPtr hDC = PlatformInvokeUSER32.GetDC(PlatformInvokeUSER32.GetDesktopWindow());
if(GetDevicePowerState(Intptr,out fOn))
Consol.WriteLine("Off");
}
please check this cause i'm not so sure about how to get window handle.
wejden khaldiPosted Feb 23, 2012, 6:00 AM
Can you help me plz
Jacob SaylorPosted Jan 13, 2010, 12:31 PM
private int getDisplayStatus()
{
int status = 0;
SelectQuery query = new SelectQuery("SELECT Availability, DeviceID, ScreenHeight , ScreenWidth, Bandwidth FROM Win32_DesktopMonitor");
using( ManagementObjectSearcher searcher = new
ManagementObjectSearcher(query))
{
foreach(ManagementObject mo in searcher.Get())
{
Console.WriteLine("{0}, {1}, {2} - {3}",
mo.Properties["DeviceID"].Value.ToString(),
mo.Properties["Availability"].Value.ToString(), // WMI docs for possible values 3 is running full power
mo.Properties["ScreenHeight"].Value.ToString(),
mo.Properties["ScreenWidth"].Value.ToString());
}
}
return status;
}