1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

Windows: Fix Vista/7 compatibility

This commit is contained in:
reuk 2023-01-09 16:01:44 +00:00 committed by Tom Poole
parent e49fb38d44
commit ebc31e603b

View file

@ -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)
{}
@ -516,7 +533,7 @@ private:
void operator() (HPOWERNOTIFY ptr) const
{
if (ptr != nullptr)
UnregisterSuspendResumeNotification (ptr);
getFunctions().unregisterNotification (ptr);
}
};