.NET CF 中关闭手持设备(支持PPC和SMARTPHONE) [DllImport("Coredll.dll")]
externstaticvoid PowerOffSystem();
privatevoid mIShutDown_Click(object sender, System.EventArgs e)
{
PowerOffSystem();
} .NET CF 中重启函数 using System.Runtime.InteropServices;
public const uint FILE_DEVICE_HAL = 0x00000101; public const uint METHOD_BUFFERED = 0; public const uint FILE_ANY_ACCESS = 0;
public uint CTL_CODE(uint DeviceType, uint Function, uint Method, uint Access) { ????return ((DeviceType << 16) | (Access << 14) | (Function << 2) | Method); }
[DllImport("Coredll.dll")] public extern static uint KernelIoControl ( ????uint dwIoControlCode, ????IntPtr lpInBuf, ????uint nInBufSize, ????IntPtr lpOutBuf, ????uint nOutBufSize, ????ref uint lpBytesReturned );
uint ResetPocketPC() { ????uint bytesReturned = 0; ????uint IOCTL_HAL_REBOOT = CTL_CODE(FILE_DEVICE_HAL, 15, ??????METHOD_BUFFERED, FILE_ANY_ACCESS); ????return KernelIoControl(IOCTL_HAL_REBOOT, IntPtr.Zero, 0, ??????IntPtr.Zero, 0, ref bytesReturned); }
private void Form1_Load(object sender, System.EventArgs e) { ????DialogResult r = MessageBox.Show ????( ????????"Are you sure you want to reset?", ????????"Test", ????????MessageBoxButtons.YesNo, ????????MessageBoxIcon.Question, ????????MessageBoxDefaultButton.Button2 ????);
????if (r == DialogResult.Yes) ????{ ????????ResetPocketPC(); ????} }
.NET CF中的硬启函数 [DllImport("Coredll.dll")]
externstaticint KernelIoControl2(int dwIoControlCode, IntPtr lpInBuf, int nInBufSize, IntPtr lpOutBuf, int nOutBufSize, refint lpBytesReturned);
[DllImport("Coredll.dll")]
externstaticvoid SetCleanRebootFlag();
publicvoid HardReset()
{
int IOCTL_HAL_REBOOT =0x101003C;
int bytesReturned =0;
SetCleanRebootFlag();
KernelIoControl2(IOCTL_HAL_REBOOT, IntPtr.Zero, 0, IntPtr.Zero, 0, ref bytesReturned);
}
.NET CF 中切换输入法 privateconstuint EM_SETINPUTMODE =0xDE;
privateconstuint EIM_SPELL =0;
privateconstuint EIM_AMBIG =1;
privateconstuint EIM_NUMBERS =2;
[DllImport("coredll.dll")]
privatestaticextern IntPtr GetFocus();
[DllImport("coredll.dll")]
privatestaticexternint SendMessage(IntPtr hWnd,uint Message, uint wParam, uint lParam);
publicstaticvoid txt_GotFocus(object sender, System.EventArgs e)
{
IntPtr hWnd;
hWnd = GetFocus();
SendMessage(hWnd, EM_SETINPUTMODE, 0, EIM_NUMBERS);
(sender as System.Windows.Forms.TextBox).SelectAll();
}
鼠标状态变换 [DllImport("coredll", SetLastError=true)]
internalstaticexternuint LoadCursor( uint zeroValue , uint cursorID );
[DllImport("coredll", SetLastError=true)]
internalstaticexternuint SetCursor( uint cursorHandle );
public Cursor(){}
publicstaticvoid ShowWaitCursor(bool bShowCursor)
{
uint cursorHandle =0;
if (bShowCursor)
{
constuint hourGlassCursorID =32514;
cursorHandle = LoadCursor(0, hourGlassCursorID);
}
SetCursor(cursorHandle);
}
获得设备ID号 #region 获得设备ID时所需要的变量及函数声明internalstatic Int32 METHOD_BUFFERED =0;
internalstatic Int32 FILE_ANY_ACCESS =0;
internalstatic Int32 FILE_DEVICE_HAL =0x00000101;
private System.Windows.Forms.MenuItem menuItem3;
private System.Windows.Forms.MenuItem menuItem4;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.TextBox tb_machineName;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.PictureBox pictureBox1;
internalstatic Int32 IOCTL_HAL_GET_DEVICEID = ((FILE_DEVICE_HAL) <<16) |
((FILE_ANY_ACCESS) <<14) | ((21) <<2) | (METHOD_BUFFERED);
[DllImport("coredll.dll",SetLastError=true)]
privatestaticexternbool KernelIoControl(Int32 IoControlCode, IntPtr
InputBuffer, Int32 InputBufferSize, byte[] OutputBuffer, Int32
OutputBufferSize, ref Int32 BytesReturned);
#endregion#region 获得设备的ID号privatestaticstring GetDeviceID()
{
int len =256;
int cb =0;
byte[] buffer =newbyte[256];
//uint ret; StringBuilder sb =new StringBuilder();
buffer[0] =0;
buffer[1] =1;
KernelIoControl(IOCTL_HAL_GET_DEVICEID, IntPtr.Zero, 0, buffer, len, ref cb);
Int32 dwPresetIDOffsset = BitConverter.ToInt32(buffer, 4);
Int32 dwPlatformIDOffset = BitConverter.ToInt32(buffer, 0xc);
Int32 dwPlatformIDSize = BitConverter.ToInt32(buffer, 0x10);
sb.Append(String.Format("{0:X8}-{1:X4}-{2:X4}-{3:X4}-",
BitConverter.ToInt32(buffer, dwPresetIDOffsset),
BitConverter.ToInt16(buffer, dwPresetIDOffsset+4),
BitConverter.ToInt16(buffer, dwPresetIDOffsset+6),
BitConverter.ToInt16(buffer, dwPresetIDOffsset+8)));
for(int i = dwPlatformIDOffset ; i < dwPlatformIDOffset + dwPlatformIDSize ; i ++)
{
sb.Append( String.Format("{0:X2}", buffer[i] ));
}
return sb.ToString();
}
#endregion
|