Beispiel #1
0
    /// <summary>
    /// Sets raw brightness not represented in percentage.
    /// </summary>
    /// <param name="physicalMonitorHandle">Physical monitor handle</param>
    /// <param name="brightness">Raw brightness (not always 0 to 100)</param>
    /// <param name="useLowLevel">Whether to use low level function</param>
    /// <returns>True if successfully sets</returns>
    public static bool SetBrightness(SafePhysicalMonitorHandle physicalMonitorHandle, uint brightness)
    {
        if (physicalMonitorHandle is null)
        {
            throw new ArgumentNullException(nameof(physicalMonitorHandle));
        }

        if (physicalMonitorHandle.IsClosed)
        {
            Debug.WriteLine("Failed to set brightness. The physical monitor handle has been closed.");
            return(false);
        }

        if (!SetMonitorBrightness(
                physicalMonitorHandle,
                brightness))
        {
            Debug.WriteLine($"Failed to set brightness. ");
            return(false);
        }
        return(true);
    }
Beispiel #2
0
    public DdcMonitorItem(
        string deviceInstanceId,
        string description,
        byte displayIndex,
        byte monitorIndex,
        SafePhysicalMonitorHandle handle)
    {
        this._handle = handle ?? throw new ArgumentNullException(nameof(handle));
        if (string.IsNullOrWhiteSpace(deviceInstanceId))
        {
            throw new ArgumentNullException(nameof(deviceInstanceId));
        }
        if (string.IsNullOrWhiteSpace(description))
        {
            throw new ArgumentNullException(nameof(description));
        }

        this.DeviceInstanceId = deviceInstanceId;
        this.Description      = description;
        this.DisplayIndex     = displayIndex;
        this.MonitorIndex     = monitorIndex;
    }
Beispiel #3
0
 private static extern bool SetMonitorBrightness(
     SafePhysicalMonitorHandle hMonitor,
     uint dwNewBrightness);
Beispiel #4
0
 private static extern bool GetMonitorBrightness(
     SafePhysicalMonitorHandle hMonitor,
     out uint pdwMinimumBrightness,
     out uint pdwCurrentBrightness,
     out uint pdwMaximumBrightness);
Beispiel #5
0
 private static extern bool GetMonitorCapabilities(
     SafePhysicalMonitorHandle hMonitor,
     out MC_CAPS pdwMonitorCapabilities,
     out MC_SUPPORTED_COLOR_TEMPERATURE pdwSupportedColorTemperatures);
Beispiel #6
0
    /// <summary>
    /// Gets raw brightnesses not represented in percentage.
    /// </summary>
    /// <param name="physicalMonitorHandle">Physical monitor handle</param>
    /// <returns>
    /// <para>success: True if successfully gets</para>
    /// <para>minimum: Raw minimum brightness (not always 0)</para>
    /// <para>current: Raw current brightness (not always 0 to 100)</para>
    /// <para>maximum: Raw maximum brightness (not always 100)</para>
    /// </returns>
    /// <remarks>
    /// Raw minimum and maximum brightnesses will become meaningful when they are not standard
    /// values (0 and 100) and so raw current brightness needs to be converted to brightness
    /// in percentage using those values. They are used to convert brightness in percentage
    /// back to raw brightness when settings brightness as well.
    /// </remarks>
    public static (bool success, uint minimum, uint current, uint maximum) GetBrightness(SafePhysicalMonitorHandle physicalMonitorHandle)
    {
        if (physicalMonitorHandle is null)
        {
            throw new ArgumentNullException(nameof(physicalMonitorHandle));
        }

        if (physicalMonitorHandle.IsClosed)
        {
            Debug.WriteLine("Failed to get brightnesses. The physical monitor handle has been closed.");
            return(success : false, 0, 0, 0);
        }


        if (!GetMonitorBrightness(
                physicalMonitorHandle,
                out uint minimumBrightness,
                out uint currentBrightness,
                out uint maximumBrightness))
        {
            Debug.WriteLine($"Failed to get brightnesses. ");
            return(success : false, 0, 0, 0);
        }
        return(success : true,
               minimum : minimumBrightness,
               current : currentBrightness,
               maximum : maximumBrightness);
    }