diff options
author | John Ankarström <john@ankarstrom.se> | 2022-07-26 19:27:35 +0200 |
---|---|---|
committer | John Ankarström <john@ankarstrom.se> | 2022-07-26 19:27:35 +0200 |
commit | 547cbe578dcdb5aa5cfdac1cdb327f92bad21219 (patch) | |
tree | dc41dc107559a3ac2c87669b3616d8a33d221180 /c/main.cpp | |
parent | dccea47e9bc322d654902a1db4fc52cbf6dd0cd7 (diff) | |
download | EpisodeBrowser-547cbe578dcdb5aa5cfdac1cdb327f92bad21219.tar.gz |
Remove ANSI compatibility.
Even though it is a fun challange in many ways, I think that,
realistically, it is probably not worth the complexity. The
Prolog backend isn't ANSI-compatible either.
Diffstat (limited to 'c/main.cpp')
-rw-r--r-- | c/main.cpp | 125 |
1 files changed, 62 insertions, 63 deletions
@@ -48,17 +48,16 @@ void WndProcContextMenu(const HWND, unsigned short); static INT_PTR CALLBACK AboutDlgProc(HWND, UINT, WPARAM, LPARAM); static void UpdateTheme(); -template <typename T> -void TerminateMsg(const T* sz1, const T* sz2) noexcept +void TerminateMsg(const wchar_t* wsz1, const wchar_t* wsz2) noexcept { - std::basic_ostringstream<T> ss; - ss << AWTEXT(T, "Episode Browser was terminated due to "); - ss << sz1; - if (sz2) - ss << ": " << sz2; + std::wstringstream wss; + wss << L"Episode Browser was terminated due to "; + wss << wsz1; + if (wsz2) + wss << ": " << wsz2; else - ss << "."; - AWFUN(T, MessageBox)(g_hWnd, ss.str().c_str(), AWTEXT(T, "Fatal Error"), MB_ICONERROR); + wss << "."; + MessageBox(g_hWnd, wss.str().c_str(), L"Fatal Error", MB_ICONERROR); } void OnTerminate() noexcept @@ -66,17 +65,17 @@ void OnTerminate() noexcept try { std::rethrow_exception(std::current_exception()); } catch (const term_t& t) { - std::basic_string<TCHAR> tstr; - if (PlString(t, &tstr)) - TerminateMsg<TCHAR>(TEXT("a Prolog exception"), tstr.c_str()); + std::wstring wstr; + if (PlString(t, &wstr)) + TerminateMsg(L"a Prolog exception", wstr.c_str()); else - TerminateMsg<char>("a Prolog exception", NULL); + TerminateMsg(L"a Prolog exception", NULL); } catch (const Win32Error& e) { - TerminateMsg<TCHAR>(TEXT("a Windows error"), e.what<TCHAR>()); + TerminateMsg(L"a Windows error", e.WhatW()); } catch (const std::exception& e) { - TerminateMsg<char>("an exception", e.what()); + TerminateMsg(L"an exception", WstrFromSz(e.what()).c_str()); } catch (...) { - TerminateMsg<char>("an exception", NULL); + TerminateMsg(L"an exception", NULL); } _Exit(1); } @@ -111,7 +110,7 @@ int WINAPI WinMain(const HINSTANCE hInstance, const HINSTANCE, char* const, cons wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hbrBackground = (HBRUSH)COLOR_WINDOW; wc.lpszMenuName = MAKEINTRESOURCE(IDR_MENU); - wc.lpszClassName = TEXT("Episode Browser"); + wc.lpszClassName = L"Episode Browser"; wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION); require(RegisterClassEx(&wc)); @@ -122,8 +121,8 @@ int WINAPI WinMain(const HINSTANCE hInstance, const HINSTANCE, char* const, cons (HINSTANCE)NULL, GetCurrentThreadId())); const HWND hWnd = require(CreateWindowEx( 0, - TEXT("Episode Browser"), - TEXT("Episode Browser"), + L"Episode Browser", + L"Episode Browser", WS_OVERLAPPEDWINDOW|WS_CLIPCHILDREN, CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, (HWND)NULL, (HMENU)NULL, hInstance, (void*)NULL)); @@ -132,7 +131,7 @@ int WINAPI WinMain(const HINSTANCE hInstance, const HINSTANCE, char* const, cons g_hWndStatus = require(CreateWindowEx( 0, STATUSCLASSNAME, - (const TCHAR*)NULL, + (const wchar_t*)NULL, WS_CHILD|WS_VISIBLE|SBARS_SIZEGRIP, 0, 0, 0, 0, hWnd, (HMENU)IDR_STATUS, hInstance, (void*)NULL)); @@ -167,15 +166,15 @@ static LRESULT CALLBACK CBTProc(const int nCode, const WPARAM wParam, const LPAR g_hWnd = (HWND)wParam; /* Look up constants. */ - if (auto opLib = maybe_make<Library>(TEXT("User32.dll")); + if (auto opLib = maybe_make<Library>(L"User32.dll"); auto GetDpiForWindow = opLib->GetProcAddress<UINT(HWND)>("GetDpiForWindow")) g_iDPI = GetDpiForWindow(g_hWnd); - if (auto opLib = maybe_make<Library>(TEXT("uxtheme.dll")); + if (auto opLib = maybe_make<Library>(L"uxtheme.dll"); opLib->GetProcAddress<void>("SetWindowTheme")) g_bThemes = 1; - if (auto opLib = maybe_make<Library>(TEXT("User32.dll")); + if (auto opLib = maybe_make<Library>(L"User32.dll"); opLib->GetProcAddress<void>("SystemParametersInfo" WA)) { NONCLIENTMETRICS m; m.cbSize = sizeof(NONCLIENTMETRICS); @@ -282,10 +281,10 @@ LRESULT CALLBACK WndProc(const HWND hWnd, const UINT uMsg, const WPARAM wParam, if (Pl("episode_data","thread_running",g_aThread)) { i = (i+1)%4; SendMessage(g_hWndStatus, SB_SETTEXT, MAKEWPARAM(1,0), - (LPARAM)(i==0? TEXT("."): - i==1? TEXT(".."): - i==2? TEXT("..."): - TEXT(""))); + (LPARAM)(i==0? L".": + i==1? L"..": + i==2? L"...": + L"")); } else { i = 0; g_bThread = 0; @@ -309,46 +308,46 @@ LRESULT CALLBACK WndProc(const HWND hWnd, const UINT uMsg, const WPARAM wParam, case WM_MENUSELECT: switch (LOWORD(wParam)) { #define TIP(s) SendMessage(g_hWndStatus, SB_SETTEXT, MAKEWPARAM(0,0), (LPARAM)(s)); -#define OF(m, s) IDM_##m: TIP(TEXT(s)); break; - case OF(FILE_EXIT, "Close Episode Browser."); - case OF(FILE_REFRESH, "Quickly refresh episode list."); - case OF(FILE_FETCH_DATA, "Fetch episode data from the web (may take a few seconds)."); - case OF(FILE_FETCH_SCREENWRITERS, "Fetch screenwriter data from the web (may take a minute)."); - case OF(FILE_ABOUT, "Show information about Episode Browser."); - case OF(WATCH_LOCALLY, "Open local copy of episode, if available."); - case OF(WATCH_ONLINE, "Open episode in the web browser."); - case OF(TOGGLE, "Toggle watched/unwatched status."); - case OF(FORGET, "Reset watched/unwatched status."); - case OF(LOOKUP, "Fetch episode data from the web, such as date, source and hint."); - case OF(WIKI, "Show Detective Conan Wiki entry for episode."); - case OF(RATE10, "Rate episode 10/10."); - case OF(RATE9, "Rate episode 9/10."); - case OF(RATE8, "Rate episode 8/10."); - case OF(RATE7, "Rate episode 7/10."); - case OF(RATE6, "Rate episode 6/10."); - case OF(RATE5, "Rate episode 5/10."); - case OF(RATE4, "Rate episode 4/10."); - case OF(RATE3, "Rate episode 3/10."); - case OF(RATE2, "Rate episode 2/10."); - case OF(RATE1, "Rate episode 1/10."); - case OF(RATE0, "Remove episode rating."); +#define OF(m, s) IDM_##m: TIP(s); break; + case OF(FILE_EXIT, L"Close Episode Browser."); + case OF(FILE_REFRESH, L"Quickly refresh episode list."); + case OF(FILE_FETCH_DATA, L"Fetch episode data from the web (may take a few seconds)."); + case OF(FILE_FETCH_SCREENWRITERS, L"Fetch screenwriter data from the web (may take a minute)."); + case OF(FILE_ABOUT, L"Show information about Episode Browser."); + case OF(WATCH_LOCALLY, L"Open local copy of episode, if available."); + case OF(WATCH_ONLINE, L"Open episode in the web browser."); + case OF(TOGGLE, L"Toggle watched/unwatched status."); + case OF(FORGET, L"Reset watched/unwatched status."); + case OF(LOOKUP, L"Fetch episode data from the web, such as date, source and hint."); + case OF(WIKI, L"Show Detective Conan Wiki entry for episode."); + case OF(RATE10, L"Rate episode 10/10."); + case OF(RATE9, L"Rate episode 9/10."); + case OF(RATE8, L"Rate episode 8/10."); + case OF(RATE7, L"Rate episode 7/10."); + case OF(RATE6, L"Rate episode 6/10."); + case OF(RATE5, L"Rate episode 5/10."); + case OF(RATE4, L"Rate episode 4/10."); + case OF(RATE3, L"Rate episode 3/10."); + case OF(RATE2, L"Rate episode 2/10."); + case OF(RATE1, L"Rate episode 1/10."); + case OF(RATE0, L"Remove episode rating."); case IDM_VIEW_WATCHED: TIP(g_bViewWatched? - TEXT("Click to hide watched episodes."): - TEXT("Click to show watched episodes.")); + L"Click to hide watched episodes.": + L"Click to show watched episodes."); break; case IDM_VIEW_TV_ORIGINAL: TIP(g_bViewTVOriginal? - TEXT("Click to hide TV original episodes."): - TEXT("Click to show TV original episodes.")); + L"Click to hide TV original episodes.": + L"Click to show TV original episodes."); break; case IDM_VIEW_OTHERS: TIP(g_szLimitScreenwriter? - TEXT("Click to hide episodes by other screenwriters."): - TEXT("Click to show episodes by other screenwriters.")); + L"Click to hide episodes by other screenwriters.": + L"Click to show episodes by other screenwriters."); break; default: - TIP(TEXT("")); + TIP(L""); break; #undef OF #undef TIP @@ -380,7 +379,7 @@ void WndProcMainMenu(const HWND hWnd, unsigned short wCommand) Pl("episode_data","thread_create","update_screenwriters",&g_aThread); t: KillTimer(hWnd, IDR_TIMER); if (!prefer(SetTimer(hWnd, IDR_TIMER, 500, (TIMERPROC)NULL))) break; - SendMessage(g_hWndStatus, SB_SETTEXT, MAKEWPARAM(1,0), (LPARAM)TEXT(".")); + SendMessage(g_hWndStatus, SB_SETTEXT, MAKEWPARAM(1,0), (LPARAM)L"."); g_bThread = 1; break; case IDM_FILE_ABOUT: @@ -486,12 +485,12 @@ void WndProcContextMenu(const HWND, unsigned short wCommand) g_pElv->Redraw(); if (cNotFound == 1) { - EBMessageBox(TEXT("Episode could not be opened locally."), - TEXT("Error"), MB_ICONWARNING); + EBMessageBox(L"Episode could not be opened locally.", + L"Error", MB_ICONWARNING); } else if (cNotFound) { - std::basic_ostringstream<TCHAR> tss; - tss << cNotFound << TEXT(" episodes could not be opened locally."); - EBMessageBox(tss.str().c_str(), TEXT("Error"), MB_ICONWARNING); + std::wstringstream wss; + wss << cNotFound << L" episodes could not be opened locally."; + EBMessageBox(wss.str().c_str(), L"Error", MB_ICONWARNING); } else if (ID_SUBGROUP(wCommand) == IDG_CTX_RATE) { g_pElv->Sort(); g_pElv->ShowFocus(); |