CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1

    [RESOLVED] OnPowerBroadcast() not detecting sleep mode

    I'm using OnPowerBroadcast(), to detect when the computer goes to sleep or hibernates. I don't need to stop sleep, just clean up some things before sleep happens.

    So, in my MDI child view, I have the function...

    Code:
     
    BEGIN_MESSAGE_MAP(CMyView, CView)
      ...
     ON_WM_POWERBROADCAST()
    // ON_MESSAGE(WM_POWERBROADCAST, OnPowerBroadcast)
      ...
    END_MESSAGE_MAP()
    
    ...
    
    //LRESULT CMyView::OnPowerBroadcast(WPARAM wParam, LPARAM lParam)
    UINT CMyView::OnPowerBroadcast(UINT wParam, UINT lParam)
    {
        TRACE1("######################## Sleep notification %d!\n", wParam);
    }
    I've put other code into the handler, breakpoints, etc, and all kinds of stuff, but when I put the computer to sleep, it just doesn't seem to get the notification to my handler. You can also see that I've tried a different method of registering to recieve the message (in the commented out code), and this is no different.

    I've tried calling RegisterPowerSettingNotification(), but this only seems to work to notify for PBT_POWERSETTINGCHANGE, not for PBT_APMSUSPEND messages.

    I'm testing on Win7, but it needs to work on 7/vista/XP.

    Any ideas?

  2. #2

    Re: OnPowerBroadcast() not detecting sleep mode

    It's OK, I found the problem. Turns out the messages only go to the MainFrame, and I need to specifically pass them through to the child windows if I want them to be processed in the child windows.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured