06-16-2020, 08:00 PM
can this be converted to QM2?
C# code:
using System; using System.Collections.Generic;
using System.Runtime.InteropServices;
namespace swmon
{
class Program
{
static void Main(string[] args)
{
IntPtr hMonitor = MonitorFromWindow(IntPtr.Zero, MONITOR_DEFAULTTO.PRIMARY);
// get number of physical displays (assume only one for simplicity)
uint physicalMonitorCount = 0;
GetNumberOfPhysicalMonitorsFromHMONITOR(hMonitor, out physicalMonitorCount);
Physical_Monitor pmon = new Physical_Monitor();
bool success = GetPhysicalMonitorsFromHMONITOR(hMonitor, physicalMonitorCount, ref pmon);
success = SetVCPFeature(pmon.hPhysicalMonitor, (byte)0xDC, 21);
success = DestroyPhysicalMonitors(physicalMonitorCount, ref pmon);
//Console.ReadKey();
}
private const int PHYSICAL_MONITOR_DESCRIPTION_SIZE = 128;
[DllImport("User32")]
internal static extern IntPtr MonitorFromWindow(IntPtr hwnd, MONITOR_DEFAULTTO dwFlags);
[DllImport("Dxva2.dll")]
private static extern bool GetNumberOfPhysicalMonitorsFromHMONITOR(IntPtr hMonitor, out uint pdwNumberOfPhysicalMonitors);
[DllImport("Dxva2.dll")]
private static extern bool GetPhysicalMonitorsFromHMONITOR(IntPtr hMonitor, uint dwPhysicalMonitorArraySize, ref Physical_Monitor physicalMonitorArray);
[DllImport("Dxva2.dll")]
private static extern bool DestroyPhysicalMonitors(uint dwPhysicalMonitorArraySize, ref Physical_Monitor physicalMonitorArray);
[DllImport("Dxva2.dll")]
private static extern bool SetVCPFeature(IntPtr hMonitor, byte bVCPCode, int dwNewValue);
/// <summary>
/// Used for features with continuous values (values that can be anything in [0, maxValue]).
/// </summary>
[DllImport("Dxva2.dll")]
private static extern bool GetVCPFeatureAndVCPFeatureReply(IntPtr hMonitor, byte bVCPCode, ref IntPtr makeNull, out int currentValue, out int maxValue);
[StructLayout(LayoutKind.Sequential)]
private struct Physical_Monitor
{
public IntPtr hPhysicalMonitor;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = PHYSICAL_MONITOR_DESCRIPTION_SIZE)]
public string szPhysicalMonitorDescription;
}
internal enum MONITOR_DEFAULTTO
{
NULL = 0x00000000,
PRIMARY = 0x00000001,
NEAREST = 0x00000002,
}
}
}