From 2ac7d06a503b256b290678f5bba158bf7d219bdd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Thu, 4 Aug 2022 16:26:27 +0200 Subject: Add comments. --- c/win.h | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) (limited to 'c/win.h') diff --git a/c/win.h b/c/win.h index 1615985..baafbf0 100644 --- a/c/win.h +++ b/c/win.h @@ -4,15 +4,17 @@ #include #include +/* Display message box centered in main window. */ int EBMessageBox(const wchar_t* wszText, const wchar_t* wszCaption, unsigned uType); +/* Retrieve mouse position relative to given window's client area. */ int GetRelativeCursorPos(HWND hWnd, POINT* pt); -/* Win32Error: Exception for Windows API errors. */ +/* Exception for Windows API errors. */ struct Win32Error : public std::exception { - Win32Error(); - Win32Error(DWORD code); - ~Win32Error(); + Win32Error() noexcept; + Win32Error(DWORD code) noexcept; + ~Win32Error() noexcept; const char* what() const noexcept override; const wchar_t* What() const noexcept; DWORD code; @@ -21,20 +23,24 @@ private: wchar_t* m_wszMsg = NULL; }; -/* Library: Wrapper for loading and freeing dynamically linked libraries. */ +/* Wrapper for loading and freeing dynamically linked libraries. */ struct Library { - static std::optional Maybe(const wchar_t* lib); + /* Non-throwing named constructor. */ + static std::optional Maybe(const wchar_t* lib) noexcept; + Library(const wchar_t* lib); - ~Library(); - template T* GetProcAddress(const char* szProc); + ~Library() noexcept; + + template T* GetProcAddress(const char* szProc) noexcept; private: - Library(HMODULE hModule); + /* Non-throwing constructor used by Maybe. */ + Library(HMODULE hModule) noexcept; HMODULE m_hModule; }; template -T* Library::GetProcAddress(const char* const szProc) +T* Library::GetProcAddress(const char* const szProc) noexcept { return (T*)(void*)::GetProcAddress(m_hModule, szProc); } @@ -69,7 +75,7 @@ inline int Dpi(const int i) return MulDiv(i, g_dpi, 96); } -/* Get window rectangle relative to parent. */ +/* Retrieve given window's rectangle relative to parent's client area. */ inline BOOL GetRelativeRect(const HWND hWnd, RECT* const rr) { if (!GetClientRect(hWnd, rr)) return 0; @@ -90,6 +96,9 @@ inline BOOL SetWindowRect(const HWND hWnd, const RECT r) return SetWindowRect(hWnd, r.left, r.top, r.right, r.bottom); } +/* The following functions call uxtheme.dll functions, if uxtheme.dll + * exists, and otherwise do nothing.. */ + inline BOOL EBIsThemeActive() { extern BOOL (*IsThemeActive)(); -- cgit v1.2.3