Windows CE 6.0背光亮度控制

时间:2011-03-02 14:44:24

标签: c# compact-framework embedded

我搜索了互联网并找到了一个解决方案,如何从C#代码更改设备亮度。它看起来像:

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

    [DllImport("coredll.Dll")]
    private static extern IntPtr CreateEvent(IntPtr lpEventAttributes, bool bManualReset, bool bInitialState, string lpName);

    [DllImport("coredll.Dll")]
    [return: MarshalAs(UnmanagedType.Bool)]
    private static extern bool CloseHandle(IntPtr hObject);

    private static bool SetEvent(IntPtr hEvent)
    {
        return EventModify(hEvent, (int)EventFlags.SET);
    }

    private void SetBacklightValue(string name, int v)
    {
        RegistryKey key = Registry.CurrentUser.OpenSubKey(@"ControlPanel\Backlight", true);
        if (key != null)
        {
            key.SetValue(name, v);
            key.Close();
        }
    }

    enum EventFlags
    {
        PULSE = 1,
        RESET = 2,
        SET = 3
    }

    private static void RaiseBackLightChangeEvent()
    {
        IntPtr hBackLightEvent = CreateEvent(IntPtr.Zero, false, false, "BackLightChangeEvent");
        if (hBackLightEvent != IntPtr.Zero)
        {
            bool result = SetEvent(hBackLightEvent);
            CloseHandle(hBackLightEvent);
        }

    }

注册表中的亮度值成功更改。在我断开设备与PC(或连接)之后,亮度也会发生变化。但目前还没有设定实际值。 我可能会遗漏一些东西(RaiseBackLightChangeEvent工作正常,没有错误)。我还需要举办一些其他活动吗?或者如果没有,我如何模拟设备电源状态变化而不实际改变它?或者我如何从注册表强制系统更新值? 谢谢你的帮助。

1 个答案:

答案 0 :(得分:2)

背光控制不是标准化的,它因设备而异。在某些设备中更改注册表就足够了,在其他设备中,您需要触发“命名事件”(您可以使用OpenNetcf),甚至对于那些您仍需要知道事件名称的设备。对于其他设备,没有办法做到这一点。我想您最好的选择是联系目标设备的制造商,并询问他们如何处理此问题的详细信息。