文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>windows mobile 关机重启软件

windows mobile 关机重启软件

时间:2011-02-25  来源:pxeric

    全部代码:     

  1 using System; 
  3 using System.Collections.Generic;
  4 using System.ComponentModel;
  5 using System.Data;
  6 using System.Drawing;
  7 using System.Text;
  8 using System.Windows.Forms;
  9 using System.Threading;
 10 using System.Runtime.InteropServices;
 11 
 12 namespace ShutDown
 13 {
 14     public partial class Form1 : NonFullscreenForm
 15     {
 16         private SizeF MyAutoScaleFactor;
 17         private int second = 5;
 18         System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer();
 19         public Form1()
 20         {
 21             InitializeComponent();
 22             MyAutoScaleFactor = new SizeF(this.AutoScaleDimensions.Width / 96F, this.AutoScaleDimensions.Height / 96F);
 23             this.Height = (int)(MyAutoScaleFactor.Height * 82 - SystemInformation.MenuHeight);            
 24             AutoReset();
 25         }
 26         /// <summary>
 27         /// 5秒自动重启
 28         /// <remark>2011-02-23 14:15 By Eric</remark>
 29         /// </summary>
 30         public void AutoReset()
 31         {
 32             timer.Interval = 1000;
 33             timer.Enabled = true;
 34             timer.Tick += new EventHandler(timer_Tick);
 35         }
 36         /// <summary>
 37         /// 重启
 38         /// </summary>
 39         /// <param name="sender"></param>
 40         /// <param name="e"></param>
 41         private void btnReset_Click(object sender, EventArgs e)
 42         {
 43             SetSystemPowerState(null, SystemPowerStateFlags.POWER_STATE_RESET, POWER_FORCE);
 44         }
 45         /// <summary>
 46         /// timer事件
 47         /// <remark>2011/1/22 12:41 By Eric </remark>
 48         /// </summary>
 49         /// <param name="sender">The sender.</param>
 50         /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
 51         void timer_Tick(object sender, EventArgs e)
 52         {
 53             if (second > 0)
 54             {
 55                 second--;
 56                 label1.Text = second.ToString();
 57             }
 58             else
 59             {
 60                 timer.Enabled = false;
 61                 SetSystemPowerState(null, SystemPowerStateFlags.POWER_STATE_RESET, POWER_FORCE);
 62             }
 63         }
 64        
 65         /// <summary>
 66         /// 关机
 67         /// <remark>2011-02-23 14:51 By Eric </remark>
 68         /// </summary>
 69         /// <param name="sender">The sender.</param>
 70         /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
 71         private void btnShutdown_Click(object sender, EventArgs e)
 72         {
 73             HTCUtilDeviceOff(true);
 74         }
 75         /// <summary>
 76         /// 退出
 77         /// </summary>
 78         /// <param name="sender"></param>
 79         /// <param name="e"></param>
 80         private void btnExit_Click(object sender, EventArgs e)
 81         {
 82             Application.Exit();
 83         }
 84 
 85         #region SetSystemPowerState 重启关机
 86 
 87         [DllImport("Coredll.dll")]
 88         public static extern int SetSystemPowerState(string psState, SystemPowerStateFlags StateFlags, uint Options);
 89 
 90         public const uint POWER_FORCE = 0x00001000;
 91         public enum SystemPowerStateFlags : uint
 92         {
 93             POWER_STATE_ON = 0x00010000,  // on state
 94             POWER_STATE_OFF = 0x00020000,  // no power, full off
 95             POWER_STATE_CRITICAL = 0x00040000,  // critical off
 96             POWER_STATE_BOOT = 0x00080000,  // boot state
 97             POWER_STATE_IDLE = 0x00100000,  // idle state
 98             POWER_STATE_SUSPEND = 0x00200000,  // suspend state
 99             POWER_STATE_UNATTENDED = 0x00400000,  // Unattended state.
100             POWER_STATE_RESET = 0x00800000,  // reset state
101             POWER_STATE_USERIDLE = 0x01000000,  // user idle state
102             POWER_STATE_BACKLIGHTON = 0x02000000,  // device scree backlight on
103             POWER_STATE_PASSWORD = 0x10000000   // This state is password protected.
104         }
105         #endregion
106 
107         #region HTCUtil.dll 是HTC或多普达机型上的dll文件
108         [DllImport("HTCUtil.dll")]
109         private static extern int HTCUtilDeviceOff(bool Func); 
110         #endregion
111     }

112 }  


软件运行截图:

测试环境:多普达S910W(因调用了HTCUtil.dll,所以关机的功能只有多普达或HTC的机型才有用) 

软件下载:/Files/pxeric/ShutDown.rar 

 

PS:若有兄弟知道所有机型通用的关机方式请分享下,^_^ 

相关阅读 更多 +
排行榜 更多 +
方块枪战战场安卓版

方块枪战战场安卓版

飞行射击 下载
战斗火力射击安卓版

战斗火力射击安卓版

飞行射击 下载
空中防御战安卓版

空中防御战安卓版

飞行射击 下载