网上找了这方面的代码, C的
http://topic.csdn.net/t/20040714/16/3174713.html
谁给翻译下啊重载了WindowProc:
HANDLE hTimer=NULL;
LRESULT CMyDlg::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
// TODO: Add your specialized code here and/or call the base class
switch(message)
{
case WM_POWERBROADCAST:
switch(wParam)
{
case PBT_APMSUSPEND:
hTimer=::CreateWaitableTimer(NULL,TRUE, "WaitForResume ");
if(!hTimer)
{
MessageBox( "Fail to create waitable timer! ");
//break;
}
hTimer=OpenWaitableTimer(TIMER_ALL_ACCESS,TRUE, "WaitForResume ");
LARGE_INTEGER liDueTime;
liDueTime.QuadPart=nCounter*1000*1000*(-10);
if(!::SetWaitableTimer(hTimer,&liDueTime,0,NULL,NULL,TRUE))
{
MessageBox( "Fail to set waitable timer! ");
break;
}
if(SetPower(TRUE,TRUE)==RTN_ERROR)
{
DWORD Er=GetLastError();
CString bfr;
bfr.Format( "%d ",Er);
MessageBox( "Can not suspend! "+bfr);
}
break;
default:
break;
}
break;
}
default:
break;
}
return CDialog::WindowProc(message, wParam, lParam);
}
其中,nCounter是你想让系统唤醒的时间。
|