aboutsummaryrefslogtreecommitdiff
path: root/c/common.h
diff options
context:
space:
mode:
authorJohn Ankarström <john@ankarstrom.se>2022-07-20 21:27:30 +0200
committerJohn Ankarström <john@ankarstrom.se>2022-07-20 21:27:30 +0200
commit561ee240477e348efcd3670a5481ccb538d6724b (patch)
tree0bfee883963a390c657e627a2184068826168d6f /c/common.h
parent3f842c733568aa9068aa83fad52540eb98f334b1 (diff)
downloadEpisodeBrowser-561ee240477e348efcd3670a5481ccb538d6724b.tar.gz
Simplify UpdateLayout.
Diffstat (limited to 'c/common.h')
-rw-r--r--c/common.h25
1 files changed, 23 insertions, 2 deletions
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<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