aboutsummaryrefslogtreecommitdiff
path: root/c/win.h
diff options
context:
space:
mode:
Diffstat (limited to 'c/win.h')
-rw-r--r--c/win.h31
1 files changed, 20 insertions, 11 deletions
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 <optional>
#include <windows.h>
+/* 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<Library> Maybe(const wchar_t* lib);
+ /* Non-throwing named constructor. */
+ static std::optional<Library> Maybe(const wchar_t* lib) noexcept;
+
Library(const wchar_t* lib);
- ~Library();
- template <class T> T* GetProcAddress(const char* szProc);
+ ~Library() noexcept;
+
+ template <class T> T* GetProcAddress(const char* szProc) noexcept;
private:
- Library(HMODULE hModule);
+ /* Non-throwing constructor used by Maybe. */
+ Library(HMODULE hModule) noexcept;
HMODULE m_hModule;
};
template <typename T>
-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)();