CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2009
    Location
    Portland, OR
    Posts
    1,488

    Is PBT_APMSUSPEND notification supposed to be sent out during forced sleep in XP?

    I'm not sure if I'm reading documentation correctly, so I'd appreciate if someone could clarify.

    I run the following API to put Windows XP SP3 into sleep (or standby mode) from a worker thread:

    Code:
    BOOL bForced = TRUE;
    SetSuspendState(FALSE, bForced, FALSE);
    Then in the main thread, while processing window messages:

    Code:
    LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
    {
        if(message == WM_POWERBROADCAST)
        {
            if(wParam == PBT_APMSUSPEND)
            {
                AddLogMsg(_T("SUSPEND event received"));
            }
            else if(wParam == PBT_APMRESUMEAUTOMATIC)
            {
                AddLogMsg(_T("RESUME event received"));
            }
        }
    
        //Do other processing
    }
    So when SetSuspendState is called with request for a 'forced' sleep mode, the PBT_APMSUSPEND notification is never broadcast. Only if I set forced parameter to FALSE I receive it.

    Any idea why?

    PS. PBT_APMRESUMEAUTOMATIC is received in either case.
    PS2. PBT_APMSUSPEND is always received when run on Windows Vista/7.

  2. #2
    Join Date
    Feb 2009
    Location
    Portland, OR
    Posts
    1,488

    Re: Is PBT_APMSUSPEND notification supposed to be sent out during forced sleep in XP?

    Guys, I made a short test project to illustrate the problem. (It's attached here as a MSVS 2008 solution.)

    Also a couple of screenshots:

    1. Invoking it as a non-forced sleep:
    Name:  scr_sleep_xp_1.png
Views: 1705
Size:  21.5 KB

    2. While keeping the first process alive, I start another one and perform forced sleep from it:
    Name:  scr_sleep_xp_2.png
Views: 1810
Size:  39.8 KB

    and this is where the logic breaks. As you can see, I not only miss my own notification of the system entering the sleep, but also other processes won't get it either.

    So my original question, is it done by design? And if so, how can my process (local service) get notified of a system entering a sleep mode on a Windows XP system?
    Attached Files Attached Files

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