diff options
-rw-r--r-- | c/main.cpp | 28 |
1 files changed, 18 insertions, 10 deletions
@@ -22,14 +22,17 @@ #define YMAIN CW_USEDEFAULT #endif -/* Exit gracefully on uncaught exception. */ -static void OnTerminate() noexcept; -static auto UNUSED = std::set_terminate(OnTerminate); - /* main.cpp defines all global (non-template) variables used in the * program. `extern' is used to access them from other files, when * need be. */ +/* Exit gracefully on uncaught exception. */ +static auto _ = std::set_terminate([]() noexcept +{ + ShowException(L"Episode Browser was terminated due to an error: %s", L"Fatal Error", MB_ICONERROR); + _Exit(1); +}); + /* Looked-up constants. */ int g_dpi = 96; @@ -70,6 +73,7 @@ BOOL (*SetWindowTheme)(HWND, const wchar_t*, const wchar_t*); static void InitializeMainWindow(HWND); /* Process parent window commands. */ static LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); +static LRESULT CALLBACK HandleMsg(HWND, UINT, WPARAM, LPARAM); /* Process main menu commands. */ static void HandleMainMenu(HWND, WORD); /* Wait for thread. */ @@ -79,12 +83,6 @@ static INT_PTR CALLBACK AboutDlgProc(HWND, UINT, WPARAM, LPARAM); /* Try to style application according to current Windows theme. */ static void UpdateTheme(); -void OnTerminate() noexcept -{ - ShowException(L"Episode Browser was terminated due to an error: %s", L"Fatal Error", MB_ICONERROR); - _Exit(1); -} - int WINAPI WinMain(const HINSTANCE hInstance, const HINSTANCE, char* const, const int nCmdShow) { setbuf(stdout, nullptr); @@ -205,6 +203,16 @@ void InitializeMainWindow(const HWND hWnd) LRESULT CALLBACK WndProc(const HWND hWnd, const UINT uMsg, const WPARAM wParam, const LPARAM lParam) { + try { + return HandleMsg(hWnd, uMsg, wParam, lParam); + } catch (...) { + ShowException(L"The action was cancelled due to an error: %s"); + } + return DefWindowProc(hWnd, uMsg, wParam, lParam); +} + +LRESULT CALLBACK HandleMsg(const HWND hWnd, const UINT uMsg, const WPARAM wParam, const LPARAM lParam) +{ switch (uMsg) { case WM_CREATE: UpdateTheme(); |