wince軟件實現重啓待機

可以通過如下代碼實現:
    重啓: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.

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章