控制台程序如何捕获系统从睡眠/休眠唤醒消息?
我通过MFC程序可以捕获到,但用控制台程序却没反应,消息循环貌似没起作用,代码如下:
#include "stdafx.h"
#include <windows.h>
LRESULT CALLBACK WindowProc(HWND hwnd, // handle to window
UINT msg, // WM_POWERBROADCAST
WPARAM wParam, // PBT_APMRESUMEAUTOMATIC
LPARAM lParam) // zero
{
if ((msg == WM_POWERBROADCAST) && (wParam == PBT_APMRESUMEAUTOMATIC))
{
MessageBox(NULL, _T("System resumed automatically."), _T("Alert!"), MB_OK);
}
return DefWindowProc(NULL, msg, wParam, lParam);
}
int _tmain(int argc, _TCHAR* argv[])
{
//catch system wakeup message
MSG msg;
while(::GetMessage(&msg, NULL, 0, 0))
{
if(msg.message == WM_POWERBROADCAST)
printf(_T("WM_POWERBROADCAST"));
if (msg.wParam == PBT_APMRESUMEAUTOMATIC)
printf(_T("PBT_APMRESUMEAUTOMATIC"));
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
连printf()函数都没执行,哪位能解释下?
谢谢!