1
我搜索了互聯網,發現了一個解決方案,如何從C#代碼更改設備亮度。它看起來像:Windows CE 6.0背光亮度控制
[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工作正常,沒有錯誤)。 Mb我需要舉辦其他一些活動?或者,如果沒有,我怎樣才能模擬設備電源狀態改變而不實際改變它?或者我怎樣才能強制註冊表的系統更新值? 感謝您的幫助。