C # adjust screen brightness using WINCE

Source: Internet
Author: User

In wince, save the screen Brightness value in the Registry HKEY_CURRENT_USER \ ControlPanel \ Backlight \ Brightness. The value ranges from 0 to 100, so you need to change the screen Brightness, the Code is as follows:

/// <Summary> // adjust the screen brightness /// </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 failed");} 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, financialas (UnmanagedType. bool)] bool bManualReset, [In, financialas (UnmanagedType. bool)] bool bIntialState, [In, financialas (UnmanagedType. BStr)] string lpName); [DllImport ("coredll. dll ", SetLastError = true, CharSet = CharSet. auto)] [return: financialas (UnmanagedType. bool)] internal static extern bool CloseHandle (IntPtr hObject); [DllImport ("coredll. dll ", SetLastError = true)] [return: financialas (UnmanagedType. bool)] internal static extern bool EventModify (IntPtr hEvent, [In, financialas (UnmanagedType. u4)] EventFlags dEvent);} enum EventFlags: int {PULSE = 1, RESET = 2, SET = 3 }}

 


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.