在wince里面保存屏幕亮度的值保存在注册表HKEY_CURRENT_USER\ControlPanel\\Backlight\Brightness里面,值的范围是0-100,所以要改变屏幕的亮度,只要改变这个值,然后重新加载就行代码如下:
/// <summary> /// 调节屏幕的亮度 /// </summary> public class SetBackLight { public static void SetBright(string strValue) { SetBackLightValue(strValue); ReloadBackLight(); } public static int GetBacklightValue() { RegistryKey CUser = Registry.CurrentUser; RegistryKey Backlight = CUser.OpenSubKey("ControlPanel\\Backlight", true); return (int)Backlight.GetValue("Brightness", RegistryValueKind.DWord); } public static void SetBackLightValue(string strValue) { try { RegistryKey hkcu = Registry.CurrentUser; RegistryKey Backlight = hkcu.OpenSubKey("ControlPanel\\Backlight", true); Backlight.SetValue("Brightness", strValue, RegistryValueKind.DWord); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); } } public static bool ReloadBackLight() { bool ret = false; IntPtr scanEvent = NativeWin.CreateEvent(IntPtr.Zero, false, false, "BackLightChangeEvent"); if (scanEvent == null) { throw new Exception("CreateEvent失败"); } else { NativeWin.EventModify(scanEvent, EventFlags.SET); NativeWin.CloseHandle(scanEvent); ret = true; } return ret; } partial class NativeWin { [DllImport("coredll.dll", SetLastError = true, CharSet = CharSet.Auto)] internal static extern IntPtr CreateEvent(IntPtr lpEventAttributes, [In, MarshalAs(UnmanagedType.Bool)] bool bManualReset, [In, MarshalAs(UnmanagedType.Bool)] bool bIntialState, [In, MarshalAs(UnmanagedType.BStr)] string lpName); [DllImport("coredll.dll", SetLastError = true, CharSet = CharSet.Auto)] [return: MarshalAs(UnmanagedType.Bool)] internal static extern bool CloseHandle(IntPtr hObject); [DllImport("coredll.dll", SetLastError = true)] [return: MarshalAs(UnmanagedType.Bool)] internal static extern bool EventModify(IntPtr hEvent, [In, MarshalAs(UnmanagedType.U4)] EventFlags dEvent); } enum EventFlags : int { PULSE = 1, RESET = 2, SET = 3 } }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 周边上新:园子的第一款马克杯温暖上架