Windows CE 6.0背光亮度控制

发布于 2024-10-19 16:33:42 字数 1546 浏览 1 评论 0原文

我在互联网上搜索并找到了一个解决方案,如何通过 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);
        }

    }

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

I searched the internet and found a solution, how to change device brightness from C# code. It looks like:

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

    }

The brightness value in registry is changed succesfully. And after I disconnect device from PC (or connect) the brightness changes too. But not at the moment, when actual value is set.
I might be missing something (RaiseBackLightChangeEvent works fine, there are no errors). Mb I need to rise some other event? Or if not, how can I simulate device power state changing without actual changing it? Or how can I force system update values from the registry?
Thanks for your help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

千笙结 2024-10-26 16:33:42

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

Backlight control is not standardized, it varies from one device to the other. In some devices changing the registry is enough, in other devices you need to fire a "named event" (you can use OpenNetcf for this), and even for those you still need to know the name of the event. For other devices there is not way of doing it. I guess your best choice would be to contact the manufacturer of your target device and ask them about the details on how they are dealing with this problem.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文