diff options
Diffstat (limited to 'c/common.h')
-rw-r--r-- | c/common.h | 25 |
1 files changed, 23 insertions, 2 deletions
@@ -56,7 +56,7 @@ std::optional<T> maybe_make(U... xs) /* Call Windows API function, throwing error on NULL. */ template <typename T> -inline T require(T x) +inline T require(const T x) { if (!x) throw Win32Error(); return x; @@ -64,7 +64,7 @@ inline T require(T x) /* Call Windows API function, showing a warning on NULL. */ template <typename T> -inline T prefer(T x) +inline T prefer(const T x) { if (!x) { EBMessageBox(Win32Error().what<TCHAR>(), @@ -88,4 +88,25 @@ inline int Cmp(const int a, const int b) return -1; } +/* Get window rectangle relative to parent. */ +inline BOOL GetRelativeRect(const HWND hWnd, RECT* const pRr) +{ + if (!GetClientRect(hWnd, pRr)) return 0; + return MapWindowPoints(hWnd, GetParent(hWnd), (POINT*)pRr, 2); +} + +inline BOOL SetWindowRect(const HWND hWnd, + const long left, const long top, const long right, const long bottom) +{ + return MoveWindow(hWnd, + left, top, + right-left, bottom-top, + TRUE); +} + +inline BOOL SetWindowRect(const HWND hWnd, const RECT r) +{ + return SetWindowRect(hWnd, r.left, r.top, r.right, r.bottom); +} + #endif |