23
Sample program to acquire power-on event notification
#include <windows.h>
static HANDLE hEventOn = NULL;
static HANDLE hThreadOn = NULL ;
DWORD WINAPI OnThread()
{
LONG WaitReturn;
While(1) {
WaitReturn = WaitForSingleObject(hEventon, INFINITE);
If (WaitReturn == WAIT_OBJECT_0) {
MessageBox(NULL, TEXT(“PowerONEvent”), TEXT(“Event”), MB_OK);
}
ResetEvent(hEventOn);
}
return 0;
}
BOOL Initialize()
{
DWORD ThreadIDOn;
hEventOn = CreateEvent(NULL, TRUE, FALSE, TEXT(“PA_OnEvent”));
if( !hEventOn )
{
return(FALSE);
}
hThreadOn = CreateThread(NULL, 0, OnThread, 0, 0, &ThreadIDOn);
if(!hThreadOn)
{
return(FALSE);
}
return(TRUE);
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
if(Initialize() ) {
MessageBox(NULL, TEXT(“Initialize Success”), TEXT(“Initialize”), MB_OK);
While(1) {
Sleep(1000);
}
return(TRUE);
}
else {
MessageBox(NULL, TEXT(“Initialize Error”), TEXT(“Initialize”), MB_OK);
return(FALSE);
}
}