I had learned and tried wrote an win32 power-test-app.exe(the source code I will add to this mail end) to test that,
1,remote lan wake this machine, the power-test-app.exe will get 3 files: power_suspend.txt + power_resume_suspend.txt + power_resume_automatic.txt
2,using pwrtest.exe to do one-time sleep and auto-awake the machine, I also get the three files.
it seems the win10 result is not the same as microsoft said.
#include <windows.h>
#include<string>
void WINAPI SaveToFile(const wchar_t* fileName)
{
HANDLE hFile = CreateFile(fileName, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
SYSTEMTIME sys;
char buffer[256];
ZeroMemory(buffer, sizeof(buffer));
GetLocalTime(&sys);
sprintf_s(buffer, sizeof(buffer), "curren_time_is [%4d-%02d-%02d][%02d:%02d:%02d].[%03d]", sys.wYear, sys.wMonth, sys.wDay, sys.wHour, sys.wMinute, sys.wSecond, sys.wMilliseconds);
if (INVALID_HANDLE_VALUE != hFile)
{
WriteFile(hFile, buffer, sizeof(buffer), NULL, NULL);
FlushFileBuffers(hFile);
CloseHandle(hFile);
}
}
void WINAPI PowerEvent(WPARAM wParam)
{
switch (wParam)
{
case PBT_APMPOWERSTATUSCHANGE:
SaveToFile(L"power_status_change.txt");
break;
case PBT_APMRESUMEAUTOMATIC:
SaveToFile(L"power_resume_automatic.txt");
break;
case PBT_APMRESUMESUSPEND:
SaveToFile(L"power_resume_suspend.txt");
break;
case PBT_APMSUSPEND:
SaveToFile(L"power_suspend.txt");
break;
case PBT_POWERSETTINGCHANGE:
SaveToFile(L"power_setting_change.txt");
break;
default:
break;
}
}
const wchar_t myClassName[] = L"MyClassName";
// Step 4: the Window Procedure
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch (msg)
{
case WM_POWERBROADCAST:
PowerEvent(wParam);
break;
case WM_CLOSE:
DestroyWindow(hwnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, msg, wParam, lParam);
}
return 0;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
WNDCLASSEX wc;
HWND hwnd;
MSG Msg;
//Step 1: Registering the Window Class
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = 0;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
wc.lpszMenuName = NULL;
wc.lpszClassName = myClassName;
wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
if (!RegisterClassEx(&wc))
{
MessageBox(NULL, L"Window Registration Failed!", L"Error!",
MB_ICONEXCLAMATION | MB_OK);
return 0;
}
// Step 2: Creating the Window
hwnd = CreateWindowEx(
WS_EX_CLIENTEDGE,
myClassName,
L"Power Event Test 1.0",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, 400, 200,
NULL, NULL, hInstance, NULL);
if (hwnd == NULL)
{
MessageBox(NULL, L"Window Creation Failed!", L"Error!",
MB_ICONEXCLAMATION | MB_OK);
return 0;
}
ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);
// Step 3: The Message Loop
while (GetMessage(&Msg, NULL, 0, 0) > 0) //block function,get messages from the message loop,return-0 means WM_QUIT,return negative means error happened.
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return Msg.wParam;
}
by krishna.