/// <summary> /// Setting up the monitors /// </summary> private Dxva2.PHYSICAL_MONITOR[] getMonitors(out Dxva2.PHYSICAL_MONITOR primaryMonitor) { primaryMonitor = new Dxva2.PHYSICAL_MONITOR(); var monitors = new List <Dxva2.PHYSICAL_MONITOR>(); try { var field = typeof(System.Windows.Forms.Screen).GetField("hmonitor", BindingFlags.NonPublic | BindingFlags.Instance); // enumerating the screens foreach (var screen in System.Windows.Forms.Screen.AllScreens) { var hMonitor = (IntPtr)field.GetValue(screen); // getting the number of monitors uint noOfMonitors = 0; if (Dxva2.GetNumberOfPhysicalMonitorsFromHMONITOR(hMonitor, ref noOfMonitors)) { // loading the monitor instances var screenMonitors = new Dxva2.PHYSICAL_MONITOR[noOfMonitors]; Dxva2.GetPhysicalMonitorsFromHMONITOR(hMonitor, noOfMonitors, screenMonitors); monitors.AddRange(screenMonitors); // setting the primary monitor if (screen.Primary && screenMonitors.Length > 0) { primaryMonitor = screenMonitors[0]; } } } } catch { } return(monitors.ToArray()); }
/// <summary> /// Returns the capabilities of the monitor /// </summary> private BrightnessInfo getCapabilities() { var info = new BrightnessInfo(); try { using (var monitors = new MonitorsCollector()) Dxva2.GetMonitorBrightness(monitors.Primary.hPhysicalMonitor, ref info.Minimum, ref info.Current, ref info.Maximum); info.Minimum = 0; info.Maximum = 100; } catch { } return(info); }
/// <summary> /// Sets the brightness level /// </summary> public bool SetBrightness(int brightness) { try { brightness = Math.Min(Math.Max(brightness, 0), 100); using (var monitors = new MonitorsCollector()) foreach (Dxva2.PHYSICAL_MONITOR m in monitors) { Dxva2.SetMonitorBrightness(m.hPhysicalMonitor, (short)brightness); } this.wmiDriver.SetBrightness(brightness); return(true); } catch { } return(false); }
public void Dispose() { Dxva2.DestroyPhysicalMonitors((uint)this.monitors.Length, this.monitors); }