From 561ee240477e348efcd3670a5481ccb538d6724b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Wed, 20 Jul 2022 21:27:30 +0200 Subject: Simplify UpdateLayout. --- c/common.h | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) (limited to 'c/common.h') diff --git a/c/common.h b/c/common.h index 01083b8..0343914 100644 --- a/c/common.h +++ b/c/common.h @@ -56,7 +56,7 @@ std::optional maybe_make(U... xs) /* Call Windows API function, throwing error on NULL. */ template -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 -inline T prefer(T x) +inline T prefer(const T x) { if (!x) { EBMessageBox(Win32Error().what(), @@ -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 -- cgit v1.2.3