Catching WM_POWERBROADCAST message
-
Hello, In my App I need to do some processing prior to the system going into a sleep mode, and once again when waking up. I have tried a number of different ways of implementing this, but haven't succeeded in sucessfully intercepting the message. The code for the current implementation is included below. My app is SDI, OS is Win2000. LRESULT CADSL_LoggerView::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) { // TODO: Add your specialized code here and/or call the base class if(message == WM_POWERBROADCAST) { CString szMsg; BOOL bRC; switch (wParam) { case PBT_APMSUSPEND: szMsg.Format("Received PBT_APMSUSPEND"); g_pLogFile->Add(szMsg); bRC = KillTimer(ID_TIMER); szMsg.Format("KillTimer() returned %i",bRC); g_pLogFile->Add(szMsg); break; case PBT_APMRESUMESUSPEND: szMsg.Format("Received PBT_APMRESUMESUSPEND"); g_pLogFile->Add(szMsg); bRC = SetTimer(ID_TIMER,300000,TimerProcs); // 5 mins (300 secs) szMsg.Format("SetTimer(300000) returned %i",bRC); &n
-
Hello, In my App I need to do some processing prior to the system going into a sleep mode, and once again when waking up. I have tried a number of different ways of implementing this, but haven't succeeded in sucessfully intercepting the message. The code for the current implementation is included below. My app is SDI, OS is Win2000. LRESULT CADSL_LoggerView::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) { // TODO: Add your specialized code here and/or call the base class if(message == WM_POWERBROADCAST) { CString szMsg; BOOL bRC; switch (wParam) { case PBT_APMSUSPEND: szMsg.Format("Received PBT_APMSUSPEND"); g_pLogFile->Add(szMsg); bRC = KillTimer(ID_TIMER); szMsg.Format("KillTimer() returned %i",bRC); g_pLogFile->Add(szMsg); break; case PBT_APMRESUMESUSPEND: szMsg.Format("Received PBT_APMRESUMESUSPEND"); g_pLogFile->Add(szMsg); bRC = SetTimer(ID_TIMER,300000,TimerProcs); // 5 mins (300 secs) szMsg.Format("SetTimer(300000) returned %i",bRC); &n
-
check the power configuration settings of the operating system:~ If it doesnt work check it on another PC, maybe on your old PC isnt all modern enough X|
Press F1 for help or google it. Greetings from Germany
It is definitely not an OS problem - the system does hibernate. Also, I know the WM_POWERBROADCAST message does get issued, as I can see it being "caught" by another project ("PowerLog" downloaded from website). So, it's definitely something to do with my implementation. For instance, does my code snippet have to be included in any particular class of the project ?
Doug
-
It is definitely not an OS problem - the system does hibernate. Also, I know the WM_POWERBROADCAST message does get issued, as I can see it being "caught" by another project ("PowerLog" downloaded from website). So, it's definitely something to do with my implementation. For instance, does my code snippet have to be included in any particular class of the project ?
Doug
-
are you shure that your winproc is the active one of the main window?
Press F1 for help or google it. Greetings from Germany
There is only one view - normally hidden, I admit. Surely such a messsage (WM_POWERBROADCAST) still gets to a window even if it is hidden ? (or is this my problem ?)
Doug
-
Hello, In my App I need to do some processing prior to the system going into a sleep mode, and once again when waking up. I have tried a number of different ways of implementing this, but haven't succeeded in sucessfully intercepting the message. The code for the current implementation is included below. My app is SDI, OS is Win2000. LRESULT CADSL_LoggerView::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) { // TODO: Add your specialized code here and/or call the base class if(message == WM_POWERBROADCAST) { CString szMsg; BOOL bRC; switch (wParam) { case PBT_APMSUSPEND: szMsg.Format("Received PBT_APMSUSPEND"); g_pLogFile->Add(szMsg); bRC = KillTimer(ID_TIMER); szMsg.Format("KillTimer() returned %i",bRC); g_pLogFile->Add(szMsg); break; case PBT_APMRESUMESUSPEND: szMsg.Format("Received PBT_APMRESUMESUSPEND"); g_pLogFile->Add(szMsg); bRC = SetTimer(ID_TIMER,300000,TimerProcs); // 5 mins (300 secs) szMsg.Format("SetTimer(300000) returned %i",bRC); &n
For anybody that hits this problem, I thought that I would update this thread. By a process of trial and error, I found that the only class of my project that would recognise the WM_POWERBROADCAST message was CMainFrame (by overriding WindowProc() )
Doug