mirror of
https://github.com/Maassoft/ColorControl.git
synced 2026-10-21 08:09:49 -05:00
124 lines
4.9 KiB
C#
124 lines
4.9 KiB
C#
using NWin32.NativeTypes;
|
|
using System.Runtime.InteropServices;
|
|
|
|
namespace ColorControl.Shared.Native;
|
|
|
|
public static class WinApi
|
|
{
|
|
[StructLayout(LayoutKind.Sequential, Pack = 4)]
|
|
public struct POWERBROADCAST_SETTING
|
|
{
|
|
public Guid PowerSetting;
|
|
public uint DataLength;
|
|
public byte Data;
|
|
}
|
|
|
|
[StructLayout(LayoutKind.Sequential)]
|
|
public struct ParentProcessUtilities
|
|
{
|
|
// These members must match PROCESS_BASIC_INFORMATION
|
|
internal IntPtr Reserved1;
|
|
internal IntPtr PebBaseAddress;
|
|
internal IntPtr Reserved2_0;
|
|
internal IntPtr Reserved2_1;
|
|
internal IntPtr UniqueProcessId;
|
|
internal IntPtr InheritedFromUniqueProcessId;
|
|
}
|
|
|
|
public const int ENUM_CURRENT_SETTINGS = -1;
|
|
public const int ENUM_REGISTRY_SETTINGS = -2;
|
|
|
|
public static int PBT_POWERSETTINGCHANGE = 32787;
|
|
|
|
public delegate void PCREATE_PROCESS_NOTIFY_ROUTINE(IntPtr ParentId, IntPtr ProcessId, bool Create);
|
|
|
|
[DllImport("user32.dll", SetLastError = true)]
|
|
public static extern bool RegisterHotKey(IntPtr hWnd, int id, int fsModifiers, int vlc);
|
|
|
|
[DllImport("user32.dll")]
|
|
public static extern bool UnregisterHotKey(IntPtr hWnd, int id);
|
|
|
|
[DllImport("user32.dll")]
|
|
public static extern bool EnumDisplaySettingsA(string deviceName, int modeNum, out DEVMODEA devMode);
|
|
|
|
[DllImport("kernel32.dll", SetLastError = true)]
|
|
[return: MarshalAs(UnmanagedType.Bool)]
|
|
public static extern bool AllocConsole();
|
|
|
|
[DllImport("kernel32.dll", SetLastError = true, ExactSpelling = true)]
|
|
public static extern bool AttachConsole(int processId);
|
|
|
|
[DllImport("kernel32.dll", SetLastError = true)]
|
|
[return: MarshalAs(UnmanagedType.Bool)]
|
|
public static extern bool FreeConsole();
|
|
|
|
[DllImport(@"User32", SetLastError = true)]
|
|
public static extern IntPtr RegisterPowerSettingNotification(IntPtr hRecipient, ref Guid PowerSettingGuid, Int32 Flags);
|
|
|
|
[DllImport("User32.dll", SetLastError = true)]
|
|
public static extern bool UnregisterPowerSettingNotification(IntPtr hWnd);
|
|
|
|
[DllImport("uxtheme.dll", CharSet = CharSet.Unicode)]
|
|
public static extern int SetWindowTheme(IntPtr hWnd, string pszSubAppName, string pszSubIdList);
|
|
|
|
[DllImport("uxtheme.dll", CharSet = CharSet.Unicode, EntryPoint = "#104")]
|
|
public static extern int RefreshImmersiveColorPolicyState();
|
|
|
|
[DllImport("uxtheme.dll", CharSet = CharSet.Unicode, EntryPoint = "#133")]
|
|
public static extern int AllowDarkModeForWindow(IntPtr hWnd, bool allow);
|
|
|
|
[DllImport("uxtheme.dll", CharSet = CharSet.Unicode, EntryPoint = "#135")]
|
|
public static extern int SetPreferredAppMode(int appMode);
|
|
|
|
[DllImport("uxtheme.dll", EntryPoint = "#136")]
|
|
public static extern void FlushMenuThemes();
|
|
|
|
[DllImport("dwmapi.dll", PreserveSig = true)]
|
|
public static extern int DwmSetWindowAttribute(IntPtr hwnd, int attr, ref int attrValue, int attrSize);
|
|
|
|
[DllImport("ntdll.dll")]
|
|
public static extern int NtQueryInformationProcess(IntPtr processHandle, int processInformationClass, ref ParentProcessUtilities processInformation, int processInformationLength, out int returnLength);
|
|
|
|
[DllImport("dwmapi.dll", EntryPoint = "#171")]
|
|
public static extern void DwmpSDRToHDRBoostPtr(IntPtr monitor, double brightness);
|
|
|
|
public enum MC_VCP_CODE_TYPE
|
|
{
|
|
MC_MOMENTARY,
|
|
MC_SET_PARAMETER
|
|
};
|
|
|
|
[DllImport("Dxva2.dll", SetLastError = true)]
|
|
[return: MarshalAs(UnmanagedType.Bool)]
|
|
public static extern bool GetVCPFeatureAndVCPFeatureReply(nint hMonitor, byte vcpCode, out MC_VCP_CODE_TYPE codeType, out uint currentValue, out uint maximumValue);
|
|
|
|
[DllImport("Dxva2.dll", SetLastError = true)]
|
|
[return: MarshalAs(UnmanagedType.Bool)]
|
|
public static extern bool SetVCPFeature(nint hMonitor, byte vcpCode, uint newValue);
|
|
|
|
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
|
|
public struct PHYSICAL_MONITOR
|
|
{
|
|
public IntPtr hPhysicalMonitor;
|
|
|
|
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]
|
|
public string szPhysicalMonitorDescription;
|
|
}
|
|
|
|
[DllImport("Dxva2.dll", SetLastError = true)]
|
|
[return: MarshalAs(UnmanagedType.Bool)]
|
|
public static extern bool GetNumberOfPhysicalMonitorsFromHMONITOR(IntPtr hMonitor, out uint pdwNumberOfPhysicalMonitors);
|
|
|
|
[DllImport("Dxva2.dll", SetLastError = true)]
|
|
[return: MarshalAs(UnmanagedType.Bool)]
|
|
public static extern bool GetPhysicalMonitorsFromHMONITOR(IntPtr hMonitor, uint dwPhysicalMonitorArraySize, [Out] PHYSICAL_MONITOR[] pPhysicalMonitorArray);
|
|
|
|
[DllImport("Dxva2.dll", SetLastError = true)]
|
|
[return: MarshalAs(UnmanagedType.Bool)]
|
|
public static extern bool DestroyPhysicalMonitors(uint dwPhysicalMonitorArraySize, [In] PHYSICAL_MONITOR[] pPhysicalMonitorArray);
|
|
|
|
[DllImport("Dxva2.dll", SetLastError = true)]
|
|
[return: MarshalAs(UnmanagedType.Bool)]
|
|
public static extern bool DestroyPhysicalMonitor(IntPtr hMonitor);
|
|
}
|