/// <summary>
    /// Indicates current system power status information.
    /// <para><b>New in v1.3</b></para>
    /// </summary>
    public class PowerStatus
    {
#pragma warning disable 0649, 0169
        private byte mACLineStatus;
        private byte mBatteryFlag;
        private byte mBatteryLifePercent;
        private byte mReserved1;
        private uint mBatteryLifeTime;
        private uint mBatteryFullLifeTime;
        private byte mReserved2;
        private byte mBackupBatteryFlag;
        private byte mBackupBatteryLifePercent;
        private byte mReserved3;
        private uint mBackupBatteryLifeTime;
        private uint mBackupBatteryFullLifeTime;
#pragma warning restore 0649, 0169        internal PowerStatus()
        {
            Update(true);
        }        /// <summary>
        /// AC power status.
        /// </summary>
        public PowerLineStatus PowerLineStatus
        {
            get
            {
                Update();
                return (PowerLineStatus)mACLineStatus;
            }
        }        /// <summary>
        /// Gets the current battery charge status.
        /// </summary>
        public BatteryChargeStatus BatteryChargeStatus
        {
            get
            {
                Update();
                return (BatteryChargeStatus)mBatteryFlag;
            }
        }        /// <summary>
        /// Gets the approximate percentage of full battery time remaining.
        /// </summary>
        /// <res>TThe approximate percentage, from 0 to 100, of full battery time remaining, or 255 if the percentage is unknown.</res>
        public byte BatteryLifePercent
        {
            get
            {
                Update();
                return mBatteryLifePercent;
            }
        }        /// <summary>
        /// Gets the approximate number of seconds of battery time remaining.
        /// </summary>
        /// <value>The approximate number of seconds of battery life remaining, or -1 if the approximate remaining battery life is unknown.</value>
        public uint BatteryLifeRemaining
        {
            get
            {
                Update();
                return mBatteryLifeTime;
            }
        }        /// <summary>
        /// Gets the reported full charge lifetime of the primary battery power source in seconds.
        /// </summary>
        /// <value>The reported number of seconds of battery life available when the battery is fullly charged, or -1 if the battery life is unknown.</value>
        public uint BatteryFullLifeTime
        {
            get
            {
                Update();
                return mBatteryFullLifeTime;
            }
        }        /// <summary>
        /// Gets the backup battery charge status.
        /// </summary>
        public BatteryChargeStatus BackupBatteryChargeStatus
        {
            get
            {
                Update();
                return (BatteryChargeStatus)mBackupBatteryFlag;
            }
        }        /// <summary>
        /// Percentage of full backup battery charge remaining. Must be in the range 0 to 100.
        /// </summary>
        public byte BackupBatteryLifePercent
        {
            get
            {
                Update();
                return mBackupBatteryLifePercent;
            }
        }        /// <summary>
        /// Number of seconds of backup battery life remaining.
        /// </summary>
        public uint BackupBatteryLifeRemaining
        {
            get
            {
                Update();
                return mBackupBatteryLifeTime;
            }
        }        /// <summary>
        /// Number of seconds of backup battery life when at full charge. Or -1 If unknown.
        /// </summary>
        public uint BackupBatteryFullLifeTime
        {
            get
            {
                Update();
                return mBackupBatteryFullLifeTime;
            }
        }        private bool Update(bool update)
        {
            if (WINAPI.GetSystemPowerStatusEx(this, update) == false)
            {
                return false;
            }
            return true;
        }        private bool Update()
        {
            return Update(false);
        }    }}

解决方案 »

  1.   

    居然copy 错了 这个blog 啊 唉。using System;using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using System.Diagnostics;
    using System.Runtime.InteropServices;
    using System.Threading;
    using Kackman.FlashLight;
    using TestApp;
    using System.Reflection;namespace SmartDeviceProject2
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }        class ControlApplet
            {
                public static void ShowApplet(AppletType applet)
                {
                    ProcessStartInfo startInfo = new ProcessStartInfo();
                    startInfo.FileName = @"\Windows\ctlpnl.exe";
                    startInfo.Arguments = String.Format("cplmain.cpl,{0}", (byte)applet);
                    //startInfo.Arguments = "BTConfigCE.cpl,0 - Bluetooth";
                    Process.Start(startInfo);            }            public static void ShowApplet(AppletType applet, byte tabIndex)
                {
                    ProcessStartInfo startInfo = new ProcessStartInfo();
                    startInfo.FileName = @"\Windows\ctlpnl.exe";
                    startInfo.Arguments = String.Format("cplmain.cpl,{0},{1}", (byte)applet, tabIndex);
                    Process.Start(startInfo);
                }            public enum AppletType
                {
                    Contrast,
                    Password,
                    OwnerInformation,
                    Power,
                    Memory,
                    About,
                    Backlight,
                    AlignScreen,
                    InputMethod,
                    SoundsReminders,
                    RemovePrograms,
                    Menus,
                    Buttons,
                    TodaySettings,
                    PCConnections,
                    ModemConnections,
                    Clock,
                    NetworkConnections,
                    RegionalSettings,
                    Connections,
                    WirelessManager = 26
                }            #region Constant Fields
                public const byte CPAPPLET_OWNERINFO_IDENTIFICATION = 0;
                public const byte CPAPPLET_OWNERINFO_NOTES = 1;            public const byte CPAPPLET_MEMORY_MAIN = 0;
                public const byte CPAPPLET_MEMORY_RUNNINGPROGRAMS = 1;            public const byte CPAPPLET_ABOUT_VERSION = 0;
                public const byte CPAPPLET_ABOUT_DEVICEID = 1;
                public const byte CPAPPLET_ABOUT_COPYRIGHTS = 2;            public const byte CPAPPLET_BACKLIGHT_BATTERY = 0;
                public const byte CPAPPLET_BACKLIGHT_EXTERNAL = 1;            public const byte CPAPPLET_INPUT_INPUTMEHTOD = 0;
                public const byte CPAPPLET_INPUT_WORDCOMPLETION = 1;
                public const byte CPAPPLET_INPUT_OPTIONS = 2;            public const byte CPAPPLET_SNDANDREMINDERS_VOLUME = 0;
                public const byte CPAPPLET_SNDANDREMINDERS_SOUNDS = 1;
                public const byte CPAPPLET_SNDANDREMINDERS_REMINDERS = 2;            public const byte CPAPPLET_MENUS_STARTMENU = 0;
                public const byte CPAPPLET_MENUS_NEWMENU = 1;            public const byte CPAPPLET_BUTTONS_PROGRAMBUTTONS = 0;
                public const byte CPAPPLET_BUTTONS_UPDOWNCONTROL = 1;            public const byte CPAPPLET_MODEM_CONNECTIONS = 0;
                public const byte CPAPPLET_MODEM_DIALING = 1;            public const byte CPAPPLET_CLOCK_TIME = 0;
                public const byte CPAPPLET_CLOCK_ALARMS = 1;            public const byte CPAPPLET_RS_REGION = 0;
                public const byte CPAPPLET_RS_NUMBER = 1;
                public const byte CPAPPLET_RS_CURRENCY = 2;
                public const byte CPAPPLET_RS_TIME = 3;
                public const byte CPAPPLET_RS_DATE = 4;
                #endregion
            }        private void button1_Click(object sender, EventArgs e)
            {
                //    ControlApplet.ShowApplet(ControlApplet.AppletType.Clock,
                //ControlApplet.CPAPPLET_CLOCK_ALARMS);
                //ControlApplet.ShowApplet(ControlApplet.AppletType.AlignScreen);
                ControlApplet.ShowApplet(ControlApplet.AppletType.AlignScreen, 1);
                //HideTaskbar();
            }
            private const int SW_HIDE = 0x00;        private const int SW_SHOW = 0x0001;        [DllImport("coredll.dll", CharSet = CharSet.Auto)]
            private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);        [DllImport("coredll.dll", CharSet = CharSet.Auto)]
            private static extern bool ShowWindow(IntPtr hwnd, int nCmdShow);        [DllImport("coredll.dll", CharSet = CharSet.Auto)]
            private static extern bool EnableWindow(IntPtr hwnd, bool enabled);        [DllImport("coredll.dll")]
            private static extern IntPtr GetForegroundWindow();        public static void ShowTaskbar()
            {            IntPtr h = FindWindow("HHTaskBar", "");            ShowWindow(h, SW_SHOW);            EnableWindow(h, true);        }        public static void HideTaskbar()
            {            IntPtr h = FindWindow("HHTaskBar", "");            ShowWindow(h, SW_HIDE);            EnableWindow(h, false);        }        private void button2_Click(object sender, EventArgs e)
            {
                ShowTaskbar();
            }        private void button3_Click(object sender, EventArgs e)
            {            ControlApplet.ShowApplet(ControlApplet.AppletType.Backlight);
                Thread t = new Thread(new ThreadStart(hid));
                t.Start();        }        public string GetText(IntPtr hWnd)
            {
                // Allocate correct string length first
                StringBuilder sb = new StringBuilder(11 + 1);
                GetWindowText(hWnd, sb, sb.Capacity);
                return sb.ToString();
            }
            [DllImport("coredll.dll", CharSet = CharSet.Auto, SetLastError = true)]
            static extern int GetWindowText(IntPtr hWnd, StringBuilder lpString, int nMaxCount);        private void hid()
            {            while (true)
                {
                    Thread.Sleep(1000);                IntPtr h = GetForegroundWindow();                if (h != IntPtr.Zero)
                    {
                        string s = GetText(h);
                        SHFullScreenHelper.SHFullScreen(h, SHFullScreenHelper.SHFS_HIDESTARTICON);
                    }            }
                BarControl.HideStartButton();
            }        private void button4_Click(object sender, EventArgs e)
            {
                PowerStatus st = new PowerStatus();
                WINAPI.GetSystemPowerStatusEx(st, false);        }        public class SHFullScreenHelper
            {
                public const Int32 SHFS_SHOWSTARTICON = 0x0010;
                public const Int32 SHFS_HIDESTARTICON = 0x0020;            public const string formWindowClassName = "#NETCF_AGL_BASE_";            [DllImport("aygshell.dll")]
                public static extern Int32 SHFullScreen(IntPtr hWnd, Int32 dwState);            [DllImport("coredll.dll")]
                public static extern IntPtr FindWindow(string className, string
              windowName);            public static IntPtr GetWindowHandle(Form f)
                {
                    return FindWindow(formWindowClassName, f.Text);
                }            // This is only method we need to call - the other stuff is just helpers
                public static bool ShowStartIcon(Form f, bool bShow)
                {
                    Int32 dwFlag = bShow ? SHFS_SHOWSTARTICON : SHFS_HIDESTARTICON;
                    return SHFullScreen(GetWindowHandle(f), dwFlag) != 0;
                }
            }     
      

  2.   

       private void Form1_Activated(object sender, EventArgs e)
            {
                //ShowStartIcon(this, false); 
            }        private void button5_Click(object sender, EventArgs e)
            {            //IntPtr m_handle = IntPtr.Zero;            //m_handle = WINAPI.SetPowerRequirement("BKL1:", SmartDeviceProject2.WINAPI.PowerState.LOW, 1, IntPtr.Zero, 0);            //WINAPI.ReleasePowerRequirement(m_handle);            //m_handle = WINAPI.SetPowerRequirement("BKL1:", SmartDeviceProject2.WINAPI.PowerState.OFF, 1, IntPtr.Zero, 0);            BackLight b = new BackLight();
                b.BacklightBrightness = 150;            //SetBacklight(WINAPI.PowerState.OFF);
                //Thread.Sleep(500);
                //SetBacklight(WINAPI.PowerState.FULL);
                //Thread.Sleep(500);
                        }
            public static void SetBacklight(WINAPI.PowerState pwr)
            {
                WINAPI.DevicePowerNotify("BKL1:", pwr, 1);
            }
            private void button6_Click(object sender, EventArgs e)
            {
                int v = (int)0;
                WINAPI.waveOutGetVolume(IntPtr.Zero, ref v);
                WINAPI.Volumes vm = WINAPI.Volumes.HIGH;
                //OpenNETCF.Win32.Wave.waveOutSetVolume(IntPtr.Zero, (int)WINAPI.Volumes.NORMAL);            WINAPI.waveOutSetVolume(IntPtr.Zero, (int)WINAPI.Volumes.NORMAL);            OpenNETCF.Win32.TimeZoneInformation zo = new OpenNETCF.Win32.TimeZoneInformation();
                
                OpenNETCF.Win32.DateTimeEx.SetTimeZoneInformation(zo);
                    
            }        private void button7_Click(object sender, EventArgs e)
            {            TestApp.TimeZoneInformation tzi = ClassTime.GetTimeZone();            TestApp.TimeZoneInformation tz = new TestApp.TimeZoneInformation();
                //tz.standardName = "Pacific SA Standard Time";
                tz.standardName = "Tokyo Standard Time";
                //tz.bias = 240;
                          ClassTime.SetTimeZone(tz);            
            }
        }
    }