c# WM5 电源管理 和 控制背景灯

1. 保持背光

        public enum DevicePowerState : int
        {

            Unspecified = -1,
            D0 = 0, // Full On: full power, full functionality
            D1, // Low Power On: fully functional at low power/performance
            D2, // Standby: partially powered with automatic wake
            D3, // Sleep: partially powered with device initiated wake
            D4, // Off: unpowered
        }

        [DllImport("CoreDll", SetLastError=true)]
        static  extern IntPtr  SetPowerRequirement(string DeviceName, DevicePowerState State, uint dwDeviceFlags, string Name, ulong Reserved);

        [DllImport("CoreDll", SetLastError = true)]
        static extern int ReleasePowerRequirement(IntPtr  hPowerReq);

 

示例:

           //保持背光

            hPower = SetPowerRequirement("BKL1:", DevicePowerState.D0, 1, null, 0);                

          //取消保持背光
            if (hPower != null)
                ReleasePowerRequirement(hPower);

 

2. 设置背光

   修改注册表

  //CurrentUser/ContorlPanel/BackLight/ACBrightness

  //CurrentUser/ContorlPanel/BackLight/Brightness

生成事件生效

        [DllImport("coredll.dll", SetLastError = true, CallingConvention = CallingConvention.Winapi, CharSet = CharSet.Auto)]
        public 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, CallingConvention = CallingConvention.Winapi, CharSet = CharSet.Auto)]
        [return: MarshalAs(UnmanagedType.Bool)]
        public static extern bool CloseHandle(IntPtr  hObject);

        [DllImport("coredll.dll", SetLastError = true)]
        [return: MarshalAs(UnmanagedType.Bool)]
        public static extern bool EventModify(IntPtr  hEvent, [In, MarshalAs(UnmanagedType.U4)] int dEvent);

//...

            IntPtr  hBackLightEvent = CreateEvent(IntPtr.Zero , false, true, "BackLightChangeEvent");
               if (hBackLightEvent != IntPtr.Zero )
               {
                   EventModify(hBackLightEvent, 3);
                   CloseHandle(hBackLightEvent);
               }

//

 

部分HTC机器,修改注册表无效,直接调用HTCdll(我的T3238 wm6.1测试通过)

        [DllImport("HTCUtil.dll")]
        private static extern int HTCUtilGetOnPowerBrightnessLevel(ref int pValue);

        [DllImport("HTCUtil.dll")]
        private static extern int HTCUtilGetOnBatteryBrightnessLevel(ref int pValue);

        [DllImport("HTCUtil.dll")]
        private static extern int HTCUtilSetOnPowerBrightnessLevel(ref int pValue);

        [DllImport("HTCUtil.dll")]
        private static extern int HTCUtilSetOnBatteryBrightnessLevel(ref int pValue);

        [DllImport("HTCUtil.dll")]
        private static extern int HTCUtilGetBacklightMinBrightness(ref int pValue);

        [DllImport("HTCUtil.dll")]
        private static extern int HTCUtilGetBacklightMaxBrightness(ref int pValue);

 

 

3.禁止系统待机

        [DllImport("CoreDll")]
        public static extern void SystemIdleTimerReset();
       
在合适的时间内,调用SystemIdleTimerReset() 清除计时器,使系统不会进入待机状态.

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值