Suspended() and resumed() not being called?

I have override suspended and resumed functions in my Custom StandaloneFilterApp.cpp

void suspended() override 
{
    //code
}
void resumed() override 
{
    //code
}

I was hoping to get a call to suspended() when computer goes to sleep and a call to resumed() when computer wakes up from sleep. But I get not… Am I missing something?

Windows
Juce 7

One of the great things with JUCE is that you have the source code. You can either add logging or place breakpoints to help you debug this. There is a function called handlePowerBroadcast in juce_win32_Windowing.cpp, which handles calling suspended and resumed. It is called from peerWindowProc, which handles all the incoming Windows messages. This should help you understand if JUCE is somehow failing, or if the OS is not sending the expected messages, moving the solution forward. :slight_smile:

1 Like

Ok,
trying to set a brekpoint in juce_win32_Windowing.cpp at:

            case WM_POWERBROADCAST:
                handlePowerBroadcast (wParam);
                break;

it will not hit when computer goes to sleep.
I tried some other messages for example SC_MINIMIZE and it was received.

Well, that helps narrow the issue. And, taking a quick look at the JUCE sources I do not see the OS call to enable this message. There seems to be two different calls for this, one for the ‘classic’ power modes (RegisterPowerSettingNotification), and one for the ‘modern’ power modes (RegisterSuspendResumeNotification). Unless there is another way that these messages can be enabled, JUCE is missing them.

A little further reading seems to indicate that the classic mode doesn’t need to be registered for some messages to make it through, but that a system that does the modern mode will require registration.

Here is one of the discussions I looked at:
https://learn.microsoft.com/en-us/answers/questions/48395/cannot-receive-wm-powerbroadcast-message-on-win10.html

If you feel confident, you could test things by implementing the register call, and if that works you have given the JUCE devs some help.

You are correct JUCE is missing RegisterSuspendResumeNotification
if I add
RegisterSuspendResumeNotification(hwnd, DEVICE_NOTIFY_WINDOW_HANDLE);
in the file juce_win32_Windowing.cpp
inside the function
createWindow()
It starts to work :slight_smile:

1 Like

I don’t know the best way to alert the devs, but it should now be a quick fix for them. There is an unregister function too.

Tested also on MacOS Ventura 13.1 and suspended() and resumed() are not being called there either.

I do not see this even implemented for OS X. It looks like there is Android, iOS, and Windows support, but no OS X.

Thanks for reporting, suspend/resume should now be called on Windows: