electron/brightray/browser/win/win32_desktop_notifications/common.h

61 lines
1.4 KiB
C
Raw Normal View History

#pragma once
#include <Windows.h>
namespace brightray {
struct NotificationData {
2018-04-18 01:46:27 +00:00
DesktopNotificationController* controller = nullptr;
2018-04-18 01:46:27 +00:00
std::wstring caption;
std::wstring body_text;
HBITMAP image = NULL;
2018-04-18 01:46:27 +00:00
NotificationData() = default;
2018-04-18 01:46:27 +00:00
~NotificationData() {
if (image)
DeleteObject(image);
}
2018-04-18 01:46:27 +00:00
NotificationData(const NotificationData& other) = delete;
NotificationData& operator=(const NotificationData& other) = delete;
};
2018-04-18 01:46:27 +00:00
template <typename T>
2017-10-06 20:25:44 +00:00
constexpr T ScaleForDpi(T value, unsigned dpi, unsigned source_dpi = 96) {
2018-04-18 01:46:27 +00:00
return value * dpi / source_dpi;
}
struct ScreenMetrics {
2018-04-18 01:46:27 +00:00
UINT dpi_x, dpi_y;
2018-04-18 01:46:27 +00:00
ScreenMetrics() {
typedef HRESULT WINAPI GetDpiForMonitor_t(HMONITOR, int, UINT*, UINT*);
2018-04-18 01:46:27 +00:00
auto GetDpiForMonitor = reinterpret_cast<GetDpiForMonitor_t*>(
GetProcAddress(GetModuleHandle(TEXT("shcore")), "GetDpiForMonitor"));
2018-04-18 01:46:27 +00:00
if (GetDpiForMonitor) {
auto monitor = MonitorFromPoint({}, MONITOR_DEFAULTTOPRIMARY);
if (GetDpiForMonitor(monitor, 0, &dpi_x, &dpi_y) == S_OK)
return;
}
2018-04-18 01:46:27 +00:00
HDC hdc = GetDC(NULL);
dpi_x = GetDeviceCaps(hdc, LOGPIXELSX);
dpi_y = GetDeviceCaps(hdc, LOGPIXELSY);
ReleaseDC(NULL, hdc);
}
template <class T>
T X(T value) const {
return ScaleForDpi(value, dpi_x);
}
template <class T>
T Y(T value) const {
return ScaleForDpi(value, dpi_y);
}
};
2018-04-18 01:46:27 +00:00
} // namespace brightray