diff --git a/modules/juce_gui_basics/native/juce_win32_Windowing.cpp b/modules/juce_gui_basics/native/juce_win32_Windowing.cpp index 533f4bd386..f51b50acfd 100644 --- a/modules/juce_gui_basics/native/juce_win32_Windowing.cpp +++ b/modules/juce_gui_basics/native/juce_win32_Windowing.cpp @@ -498,6 +498,31 @@ static double getGlobalDPI() return (GetDeviceCaps (deviceContext.dc, LOGPIXELSX) + GetDeviceCaps (deviceContext.dc, LOGPIXELSY)) / 2.0; } +//============================================================================== +class ScopedSuspendResumeNotificationRegistration +{ +public: + ScopedSuspendResumeNotificationRegistration() = default; + + explicit ScopedSuspendResumeNotificationRegistration (HWND window) + : handle (SystemStats::getOperatingSystemType() >= SystemStats::Windows8_0 + ? RegisterSuspendResumeNotification (window, DEVICE_NOTIFY_WINDOW_HANDLE) + : nullptr) + {} + +private: + struct Destructor + { + void operator() (HPOWERNOTIFY ptr) const + { + if (ptr != nullptr) + UnregisterSuspendResumeNotification (ptr); + } + }; + + std::unique_ptr, Destructor> handle; +}; + //============================================================================== class ScopedThreadDPIAwarenessSetter::NativeImpl { @@ -1659,10 +1684,14 @@ public: if (updateCurrentMonitor()) VBlankDispatcher::getInstance()->updateDisplay (*this, currentMonitor); + + suspendResumeRegistration = ScopedSuspendResumeNotificationRegistration { hwnd }; } ~HWNDComponentPeer() override { + suspendResumeRegistration = {}; + VBlankDispatcher::getInstance()->removeListener (*this); // do this first to avoid messages arriving for this window before it's destroyed @@ -4595,6 +4624,7 @@ private: bool shouldIgnoreModalDismiss = false; RectangleList deferredRepaints; + ScopedSuspendResumeNotificationRegistration suspendResumeRegistration; //============================================================================== JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (HWNDComponentPeer)