Exemplo n.º 1
0
        /// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Title:          SET BRIGHTNESS
        /// Description:    this function gets the list of handles to all monitors and sets their brightness to the value NewBrightness.
        /// </summary>
        ///
        /// <param name="sender"></param>
        /// <param name="e"></param>
        ///
        private void SetBrightness(object sender, EventArgs e)
        {
            if (NewBrightness != CurrentBrightness)
            {
                try
                {
                    physicalMonitors = DisplayConfiguration.GetPhysicalMonitors(DisplayConfiguration.GetCurrentMonitor());

                    foreach (DisplayConfiguration.PHYSICAL_MONITOR physicalMonitor in physicalMonitors)
                    {
                        try
                        {
                            DisplayConfiguration.SetMonitorBrightness(physicalMonitor, NewBrightness);
                            DisplayConfiguration.SetMonitorContrast(physicalMonitor, NewBrightness);
                            CurrentBrightness = NewBrightness;
                        }
                        catch
                        {
                            System.Diagnostics.Debug.WriteLine("ERROR: cannot set brightness!");
                            labelStatus.Text = "could not set brightness!";
                        }
                    }
                }
                catch
                {
                    System.Diagnostics.Debug.WriteLine("ERROR: cannot find monitors!");
                    labelStatus.Text = "could not find monitors!";
                }
            }

            UpdateObjects(sender, e);
        }
Exemplo n.º 2
0
        private void StartBenchmarkButton_Click(object sender, RoutedEventArgs e)
        {
            DisplayConfiguration.PHYSICAL_MONITOR Handle = DisplayConfiguration.GetPhysicalMonitors(DisplayConfiguration.GetCurrentMonitor())[0];
            var    GetBrightnessWatch = System.Diagnostics.Stopwatch.StartNew();
            double Brightness         = DisplayConfiguration.GetMonitorBrightness(Handle);

            GetBrightnessWatch.Stop();

            var SetBrightnessWatchExtrems = System.Diagnostics.Stopwatch.StartNew();

            DisplayConfiguration.MonitorExtremums MonExtems = DisplayConfiguration.GetMonitorExtremums(Handle);
            uint dwMinimumBrightness = MonExtems.Min;
            uint dwMaximumBrightness = MonExtems.Max;

            DisplayConfiguration.SetMonitorBrightness(Handle, 1, dwMinimumBrightness, dwMaximumBrightness);
            SetBrightnessWatchExtrems.Stop();

            var SetBrightnessWatch = System.Diagnostics.Stopwatch.StartNew();

            DisplayConfiguration.SetMonitorBrightness(Handle, Brightness, dwMinimumBrightness, dwMaximumBrightness);
            SetBrightnessWatch.Stop();

            MessageBox.Show($"GetBrightness: {GetBrightnessWatch.ElapsedMilliseconds} ms.\n" +
                            $"SetBrightnessExtrems: {SetBrightnessWatchExtrems.ElapsedMilliseconds} ms.\n" +
                            $"SetBrightness: {SetBrightnessWatch.ElapsedMilliseconds} ms.\n\n" +
                            $"Total: {GetBrightnessWatch.ElapsedMilliseconds + SetBrightnessWatchExtrems.ElapsedMilliseconds + SetBrightnessWatch.ElapsedMilliseconds} ms.", "Benchmark Results");
        }