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); }