软重起部分:
1、(推荐在Smartphone中使用)
参考:
http://www.pocketpcdn.com/articles/articles.php?&atb.set(a_id)=3937&atb.set(c_id)=66&atb.perform(details)=&
该 部分代码可直接拷贝到程序中,调用SoftReset()即执行重起功能;该段代码具有动态检测操作系统版本自动选择重起代码的功能,不需要程序中另写版 本判断代码。另外在SoftReset()中的版本判断代码实在程序执行时检测的,比以前用的#if _WIN32_WCE < 0x500 && ( defined(WIN32_PLATFORM_PSPC) ¦ ¦ defined(WIN32_PLATFORM_WFSP) )方式优越的多,关于它的具体使用方法,我会另发给大家。
该部分代码适用于Smartphone和PPC。(除PPC的MYPAL A730和HP iPAQ rx3115两种机型)
//源代码
#include <winioctl.h >
void SoftReset();
extern "C" __declspec(dllimport) BOOL KernelIoControl(DWORD dwIoControlCode, LPVOID lpInBuf, DWORD nInBufSize, LPVOID lpOutBuf, DWORD nOutBufSize, LPDWORD lpBytesReturned);
static void ResetWithExitWindows()
{
HMODULE hModule = ::LoadLibrary(TEXT("aygshell.dll"));
typedef BOOL (*ExitWindowsExFunction)(UINT uFlags, DWORD dwReserved);
ExitWindowsExFunction f = (ExitWindowsExFunction)::GetProcAddress(hModule, TEXT("ExitWindowsEx"));
#ifndef EWX_REBOOT
#define EWX_REBOOT 2
#endif
f(EWX_REBOOT, 0);
FreeLibrary(hModule);
}
static void ResetWithSetSystemPowerState()
{
typedef DWORD (*SetSystemPowerStateFunction)(LPCWSTR pwsSystemState, DWORD StateFlags, DWORD Options);
HMODULE hModule = ::LoadLibrary(TEXT("Coredll.dll"));
SetSystemPowerStateFunction f = (SetSystemPowerStateFunction)
::GetProcAddress(hModule, TEXT("SetSystemPowerState"));
#ifndef POWER_STATE_RESET
#define POWER_STATE_RESET DWORD(0x00800000)
#endif
f(NULL, POWER_STATE_RESET, 0);
::FreeLibrary(hModule);
}
static void ResetWithKernelIoControl()
{
#ifndef IOCTL_HAL_REBOOT
#define IOCTL_HAL_REBOOT CTL_CODE(FILE_DEVICE_HAL, 15, METHOD_BUFFERED, FILE_ANY_ACCESS)
#endif
KernelIoControl(IOCTL_HAL_REBOOT, NULL, 0, NULL, 0, NULL);
}
void SoftReset()
{
OSVERSIONINFO vi;
memset(&vi, 0, sizeof(vi));
vi.dwOSVersionInfoSize = sizeof(vi);
VERIFY(GetVersionEx(&vi));
if (vi.dwMajorVersion >= 5) {
ResetWithExitWindows();
} else if (vi.dwMajorVersion==4 && vi.dwMinorVersion >=20) {
ResetWithSetSystemPowerState();
} else {
ResetWithKernelIoControl();
}
}
2、重起(推荐在PPC中使用)
该方法可用于Smartphone的2003版本, PPC的2003、5.0版本。
//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);
}
WM5.0以上还可以用
if(MessageBox(NULL, _T("Reset your PDA?"), _T("Reset")Reset, MB_YESNO|MB_ICONQUESTION) == IDYES)
::ExitWindowsEx(EWX_REBOOT,0);
关机部分:
将这两句代码写在响应关机消息的地方,即可实现关机功能。适用PPC和Smartphone的2003、5.0版本。
虚拟关机键实现:
keybd_event(VK_OFF, 0, 0, 0); // down
keybd_event(VK_OFF, 0, 2, 0); // up
硬重起部分:
该方法只能用于PPC 2003。 PPC5.0和Smartphone2003、5.0都不能用。
#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);
}
软重启就是普通的重启,硬重启会格式化并重置到出厂状态。