Skip to content

Commit

Permalink
Windows: Fix Vista/7 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
reuk committed Jan 12, 2023
1 parent f4f8f8e commit 164c912
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions modules/juce_gui_basics/native/juce_win32_Windowing.cpp
Expand Up @@ -501,12 +501,29 @@ static double getGlobalDPI()
//==============================================================================
class ScopedSuspendResumeNotificationRegistration
{
static auto& getFunctions()
{
struct Functions
{
using Register = HPOWERNOTIFY (WINAPI*) (HANDLE, DWORD);
using Unregister = BOOL (WINAPI*) (HPOWERNOTIFY);

Register registerNotification = (Register) getUser32Function ("RegisterSuspendResumeNotification");
Unregister unregisterNotification = (Unregister) getUser32Function ("UnregisterSuspendResumeNotification");

bool isValid() const { return registerNotification != nullptr && unregisterNotification != nullptr; }
};

static Functions functions;
return functions;
}

public:
ScopedSuspendResumeNotificationRegistration() = default;

explicit ScopedSuspendResumeNotificationRegistration (HWND window)
: handle (SystemStats::getOperatingSystemType() >= SystemStats::Windows8_0
? RegisterSuspendResumeNotification (window, DEVICE_NOTIFY_WINDOW_HANDLE)
: handle (getFunctions().isValid()
? getFunctions().registerNotification (window, DEVICE_NOTIFY_WINDOW_HANDLE)
: nullptr)
{}

Expand All @@ -516,7 +533,7 @@ class ScopedSuspendResumeNotificationRegistration
void operator() (HPOWERNOTIFY ptr) const
{
if (ptr != nullptr)
UnregisterSuspendResumeNotification (ptr);
getFunctions().unregisterNotification (ptr);
}
};

Expand Down

0 comments on commit 164c912

Please sign in to comment.