-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.h
51 lines (37 loc) · 1.41 KB
/
utils.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#pragma once
#include <Windows.h>
#include <wil/result.h>
//! \brief Calculates the width of a rectangle.
//!
//! \param r The rectangle to calculate the width for.
//!
//! \return The width of the rectangle. This value can be negative if the
//! rectangle isn't normalized.
//!
[[nodiscard]] constexpr inline auto width(RECT const& r) noexcept { return r.right - r.left; }
//! \brief Calculates the height of a rectangle.
//!
//! \param r The rectangle to calculate the height for.
//!
//! \return The height of the rectangle. This value can be negative if the
//! rectangle isn't normalized.
//!
[[nodiscard]] constexpr inline auto height(RECT const& r) noexcept { return r.bottom - r.top; }
inline void modify_style(HWND const wnd, DWORD style_add, DWORD style_remove = 0x0)
{
auto style { ::GetWindowLongPtrW(wnd, GWL_STYLE) };
THROW_LAST_ERROR_IF(style == 0);
style |= style_add;
style &= ~static_cast<LONG_PTR>(style_remove);
auto result { ::SetWindowLongPtrW(wnd, GWL_STYLE, style) };
THROW_LAST_ERROR_IF(result == 0);
}
inline void modify_style_ex(HWND const wnd, DWORD style_add, DWORD style_remove = 0x0)
{
auto style { ::GetWindowLongPtrW(wnd, GWL_EXSTYLE) };
THROW_LAST_ERROR_IF(style == 0);
style |= style_add;
style &= ~static_cast<LONG_PTR>(style_remove);
auto result { ::SetWindowLongPtrW(wnd, GWL_EXSTYLE, style) };
THROW_LAST_ERROR_IF(result == 0);
}