aboutsummaryrefslogtreecommitdiff
path: root/c
diff options
context:
space:
mode:
authorJohn Ankarström <john@ankarstrom.se>2022-08-06 01:21:08 +0200
committerJohn Ankarström <john@ankarstrom.se>2022-08-06 01:21:08 +0200
commitcf8707bf2ede99d8543d806355eee088bdc1376b (patch)
tree0f1ffc52906d9f66f75631bd97dfb0dcf91989ad /c
parentc0024748e8ff2f46e5d37a054fa349f24ddc497f (diff)
downloadEpisodeBrowser-cf8707bf2ede99d8543d806355eee088bdc1376b.tar.gz
Use typedefs when interacting with Win32 API.
It's not like they're ever going to change the definition of WORD (knock on wood) -- but I guess it's proper to use them as if their definitions might change.
Diffstat (limited to 'c')
-rw-r--r--c/debug.cpp4
-rw-r--r--c/debug.h4
-rw-r--r--c/listview.cpp4
-rw-r--r--c/listview.h2
-rw-r--r--c/main.cpp18
-rw-r--r--c/win.cpp4
-rw-r--r--c/win.h15
7 files changed, 26 insertions, 25 deletions
diff --git a/c/debug.cpp b/c/debug.cpp
index 35f8933..6b5baff 100644
--- a/c/debug.cpp
+++ b/c/debug.cpp
@@ -66,9 +66,9 @@ Benchmark::~Benchmark()
}
}
-const char* WmName(const unsigned uMsg)
+const char* WmName(const UINT uMsg)
{
- static const unsigned vKey[] = {
+ static const UINT vKey[] = {
0, 1, 2, 3, 5, 6, 7, 8, 10, 11, 12, 13, 14, 15, 16, 17, 18,
19, 20, 21, 22, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34,
35, 36, 38, 39, 40, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51,
diff --git a/c/debug.h b/c/debug.h
index f58c700..e9cefa3 100644
--- a/c/debug.h
+++ b/c/debug.h
@@ -1,6 +1,8 @@
#ifndef DEBUG_H
#define DEBUG_H
+#include <windows.h>
+
/* Benchmark objects measure and print the time in microseconds
* between construction and destruction. Given a unique id, they also
* calculate a running average of the last `avgmax' instances of
@@ -21,6 +23,6 @@ struct Benchmark
};
/* Return name of given window message (WM_*). */
-const char* WmName(unsigned uMsg);
+const char* WmName(UINT uMsg);
#endif
diff --git a/c/listview.cpp b/c/listview.cpp
index 8224c0a..9ca088c 100644
--- a/c/listview.cpp
+++ b/c/listview.cpp
@@ -37,11 +37,11 @@ int ListView::Height()
void ListView::ResizeColumns(int) {}
-void ListView::UpdateTheme(const BOOL bThemeActive)
+void ListView::UpdateTheme(const bool bThemeActive)
{
const wchar_t* theme;
WORD action;
- extern BOOL (*SetWindowTheme)(HWND, LPCWSTR, LPCWSTR);
+ extern BOOL (*SetWindowTheme)(HWND, const wchar_t*, const wchar_t*);
if (!SetWindowTheme) return;
if (bThemeActive) {
diff --git a/c/listview.h b/c/listview.h
index 008f995..b0e49ee 100644
--- a/c/listview.h
+++ b/c/listview.h
@@ -17,7 +17,7 @@ struct ListView
* by default). */
virtual void ResizeColumns(int w);
/* Enable/disable "modern" theme. */
- virtual void UpdateTheme(BOOL bThemeActive);
+ virtual void UpdateTheme(bool bThemeActive);
virtual LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
protected:
WNDPROC m_proc0;
diff --git a/c/main.cpp b/c/main.cpp
index a672c51..a06002a 100644
--- a/c/main.cpp
+++ b/c/main.cpp
@@ -49,16 +49,16 @@ char g_limitScreenwriter[64];
/* Optional Windows functions. */
BOOL (*IsThemeActive)();
-BOOL (*SetWindowTheme)(HWND, LPCWSTR, LPCWSTR);
+BOOL (*SetWindowTheme)(HWND, const wchar_t*, const wchar_t*);
/* Initialize important global state on parent window creation. */
static LRESULT CALLBACK CBTProc(int, WPARAM, LPARAM);
/* Process parent window commands. */
static LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
/* Process main menu commands. */
-static void HandleMainMenu(HWND, unsigned short);
+static void HandleMainMenu(HWND, WORD);
/* Process context menu commands. */
-static void HandleContextMenu(HWND, unsigned short);
+static void HandleContextMenu(HWND, WORD);
/* Call Prolog predicate in other thread, if available. */
static void WaitFor(const char*, const char*);
/* Handle messages to Help > About dialog. */
@@ -291,7 +291,7 @@ LRESULT CALLBACK WndProc(const HWND hWnd, const UINT uMsg, const WPARAM wParam,
break;
case WM_COMMAND:
{
- const unsigned short command = LOWORD(wParam);
+ const WORD command = LOWORD(wParam);
switch (ID_GROUP(command)) {
case IDG_MENU:
HandleMainMenu(hWnd, command);
@@ -344,8 +344,8 @@ LRESULT CALLBACK WndProc(const HWND hWnd, const UINT uMsg, const WPARAM wParam,
/*IDM_RATE10*/L"Rate episode 10/10."
};
- const unsigned short command = LOWORD(wParam);
- const unsigned short group = ID_GROUP(command);
+ const WORD command = LOWORD(wParam);
+ const WORD group = ID_GROUP(command);
const wchar_t* tip = {0};
if (group) {
const wchar_t** const vTip = group==IDG_MENU? vTipMenu: vTipCtx;
@@ -373,7 +373,7 @@ LRESULT CALLBACK WndProc(const HWND hWnd, const UINT uMsg, const WPARAM wParam,
return 0;
}
-void HandleMainMenu(const HWND hWnd, unsigned short command)
+void HandleMainMenu(const HWND hWnd, WORD command)
{
switch (command) {
case IDM_FILE_EXIT:
@@ -429,7 +429,7 @@ void HandleMainMenu(const HWND hWnd, unsigned short command)
}
}
-void HandleContextMenu(const HWND, unsigned short command)
+void HandleContextMenu(const HWND, WORD command)
{
int cNotFound = 0;
@@ -556,7 +556,7 @@ INT_PTR CALLBACK AboutDlgProc(const HWND hWnd, const UINT uMsg, const WPARAM wPa
void UpdateTheme()
{
if (!IsThemeActive) return;
- const BOOL bThemeActive = IsThemeActive();
+ const bool bThemeActive = IsThemeActive();
g_dlv->UpdateTheme(bThemeActive);
g_elv->UpdateTheme(bThemeActive);
}
diff --git a/c/win.cpp b/c/win.cpp
index 19cfaab..593b340 100644
--- a/c/win.cpp
+++ b/c/win.cpp
@@ -65,7 +65,7 @@ Library::~Library()
FreeLibrary(m_hModule);
}
-int EBMessageBox(const wchar_t* const wszText, const wchar_t* const wszCaption, const unsigned uType)
+int EBMessageBox(const wchar_t* const wszText, const wchar_t* const wszCaption, const UINT uType)
{
extern HWND g_hWnd;
@@ -97,7 +97,7 @@ int EBMessageBox(const wchar_t* const wszText, const wchar_t* const wszCaption,
return r;
}
-int GetRelativeCursorPos(HWND hWnd, POINT* pt)
+int GetRelativeCursorPos(const HWND hWnd, POINT* const pt)
{
RECT rc;
if (!GetClientRect(hWnd, &rc)) return 0;
diff --git a/c/win.h b/c/win.h
index d36cbdf..ff38ce0 100644
--- a/c/win.h
+++ b/c/win.h
@@ -5,9 +5,11 @@
#include <windows.h>
/* Display message box centered in main window. */
-int EBMessageBox(const wchar_t* wszText, const wchar_t* wszCaption, unsigned uType);
+int EBMessageBox(const wchar_t* wszText, const wchar_t* wszCaption, UINT uType);
/* Retrieve mouse position relative to given window's client area. */
int GetRelativeCursorPos(HWND hWnd, POINT* pt);
+/* Cached values from GetSystemMetrics. */
+template <int I> auto Metric = GetSystemMetrics(I);
/* Exception for Windows API errors. */
struct Win32Error : public std::exception
@@ -45,10 +47,6 @@ T* Library::GetProcAddress(const char* const szProc) noexcept
return (T*)(void*)::GetProcAddress(m_hModule, szProc);
}
-/* Variable template for caching values from GetSystemMetrics. */
-template <int I>
-auto Metric = GetSystemMetrics(I);
-
/* Check result of Windows API call, throwing error on null. */
template <typename T>
inline T Require(const T x)
@@ -97,7 +95,7 @@ inline BOOL SetWindowRect(const HWND hWnd, const RECT r)
}
/* The following functions call uxtheme.dll functions, if uxtheme.dll
- * exists, and otherwise do nothing.. */
+ * exists, and otherwise do nothing. */
inline BOOL EBIsThemeActive()
{
@@ -105,9 +103,10 @@ inline BOOL EBIsThemeActive()
return IsThemeActive? IsThemeActive(): 0;
}
-inline BOOL EBSetWindowTheme(HWND hWnd, LPCWSTR pszSubAppName, LPCWSTR pszSubIdList)
+inline BOOL EBSetWindowTheme(const HWND hWnd, const wchar_t* const pszSubAppName,
+ const wchar_t* const pszSubIdList)
{
- extern BOOL (*SetWindowTheme)(HWND, LPCWSTR, LPCWSTR);
+ extern BOOL (*SetWindowTheme)(HWND, const wchar_t*, const wchar_t*);
return SetWindowTheme? SetWindowTheme(hWnd, pszSubAppName, pszSubIdList): 0;
}