重启:KernelIoControl(IOCTL_HAL_REBOOT, NULL, 0, NULL, 0, NULL);
关机:SetSystemPowerState(NULL, POWER_STATE_OFF, POWER_FORCE);
待机:GwesPowerOffSystem();
具体的效果还要看系统底层的实现情况。
关闭(suspend)
方法1:
//虚拟关机键
::keybd_event(VK_OFF, 0, 0, 0);
::keybd_event(VK_OFF, 0, KEYEVENTF_KEYUP, 0);
方法2:
//调用未公开函数PowerOffSystem()
extern "C" __declspec(dllimport) void PowerOffSystem();
重起(soft reset)
//Soft reset the device
#include 〈winioctl.h〉
#define IOCTL_HAL_REBOOT CTL_CODE(FILE_DEVICE_HAL, 15,
METHOD_BUFFERED, FILE_ANY_ACCESS)
extern "C" __declspec(dllimport) BOOL KernelIoControl(
DWORD dwIoControlCode,
LPVOID lpInBuf,
DWORD nInBufSize,
LPVOID lpOutBuf,
DWORD nOutBufSize,
LPDWORD lpBytesReturned);
BOOL ResetDevice()
{
return KernelIoControl(IOCTL_HAL_REBOOT, NULL, 0, NULL, 0,
NULL);
}
硬起动(hard reset)
//注意!!!使用此段代码会将您的Pocket PC的用户数据全部清空,
//请勿非法使用,用者后果自负.
#include 〈winioctl.h〉
#define IOCTL_HAL_REBOOT CTL_CODE(FILE_DEVICE_HAL, 15,
METHOD_BUFFERED, FILE_ANY_ACCESS)
extern "C" __declspec(dllimport)void SetCleanRebootFlag(void);
extern "C" __declspec(dllimport) BOOL KernelIoControl(
DWORD dwIoControlCode,
LPVOID lpInBuf,
DWORD nInBufSize,
LPVOID lpOutBuf,
DWORD nOutBufSize,
LPDWORD lpBytesReturned);
BOOL HardResetDevice()
{
SetCleanRebootFlag();
return KernelIoControl(IOCTL_HAL_REBOOT, NULL, 0, NULL, 0, NULL);
}
另外wince 5.01 以后版本提供了重启的函数:ExitWindowsEx
This function shuts down the system.
BOOL ExitWindowsEx(
UINT uFlags,
DWORD dwReserved
);
Parameters
uFlags
[in] Specifies the type of shutdown. This parameter must be one of the following values.
Value Description
EWX_POWEROFF Shuts down the system and turns off the power.
Note This flag is not supported on a Windows Mobile-based Pocket PC.
EWX_REBOOT Shuts down the system and reboots.
dwReserved
[in] Reserved; this parameter is ignored.
Return Values
If the function succeeds, the return value is nonzero. If the function fails, the return value is zero.
Remarks
The ExitWindowsEx function returns as soon as it has initiated the shutdown. The shutdown then proceeds asynchronously.
Requirements
Pocket PC: Windows Mobile 5.0 and later.
Smartphone: Windows Mobile 5.0 and later.
OS Versions: Windows CE 5.01 and later.
Header: Aygshell.h.