2017-03-15 12:56:06 +00:00
|
|
|
#pragma once
|
|
|
|
#include <Windows.h>
|
|
|
|
|
|
|
|
namespace brightray {
|
|
|
|
|
2017-04-03 10:11:39 +00:00
|
|
|
struct NotificationData {
|
2018-04-18 01:46:27 +00:00
|
|
|
DesktopNotificationController* controller = nullptr;
|
2017-03-15 12:56:06 +00:00
|
|
|
|
2018-04-18 01:46:27 +00:00
|
|
|
std::wstring caption;
|
|
|
|
std::wstring body_text;
|
|
|
|
HBITMAP image = NULL;
|
2017-03-15 12:56:06 +00:00
|
|
|
|
2018-04-18 01:46:27 +00:00
|
|
|
NotificationData() = default;
|
2017-03-15 12:56:06 +00:00
|
|
|
|
2018-04-18 01:46:27 +00:00
|
|
|
~NotificationData() {
|
|
|
|
if (image)
|
|
|
|
DeleteObject(image);
|
|
|
|
}
|
2017-03-15 12:56:06 +00:00
|
|
|
|
2018-04-18 01:46:27 +00:00
|
|
|
NotificationData(const NotificationData& other) = delete;
|
|
|
|
NotificationData& operator=(const NotificationData& other) = delete;
|
2017-03-15 12:56:06 +00:00
|
|
|
};
|
|
|
|
|
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;
|
2017-03-15 12:56:06 +00:00
|
|
|
}
|
|
|
|
|
2017-04-03 10:11:39 +00:00
|
|
|
struct ScreenMetrics {
|
2018-04-18 01:46:27 +00:00
|
|
|
UINT dpi_x, dpi_y;
|
2017-04-05 09:53:37 +00:00
|
|
|
|
2018-04-18 01:46:27 +00:00
|
|
|
ScreenMetrics() {
|
|
|
|
typedef HRESULT WINAPI GetDpiForMonitor_t(HMONITOR, int, UINT*, UINT*);
|
2017-04-05 09:53:37 +00:00
|
|
|
|
2018-04-18 01:46:27 +00:00
|
|
|
auto GetDpiForMonitor = reinterpret_cast<GetDpiForMonitor_t*>(
|
|
|
|
GetProcAddress(GetModuleHandle(TEXT("shcore")), "GetDpiForMonitor"));
|
2017-03-15 12:56:06 +00:00
|
|
|
|
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;
|
2017-03-15 12:56:06 +00:00
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
}
|
2017-03-15 12:56:06 +00:00
|
|
|
};
|
|
|
|
|
2018-04-18 01:46:27 +00:00
|
|
|
} // namespace brightray
|