title: Windows CE 6.0 backlight brightness control
body: <p>I searched the internet and found a solution, how to change device brightness from C# code. It looks like:</p>
  
  <pre><code>[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);
          }
  
      }
  </code></pre>
  
  <p>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. </p>