diff options
Diffstat (limited to 'c/main.cpp')
-rw-r--r-- | c/main.cpp | 42 |
1 files changed, 14 insertions, 28 deletions
@@ -28,15 +28,14 @@ int g_bViewWatched = 1; int g_bThread = 0; int g_iDPI = 96; static int g_cxVScroll; -void OnTerminate(void); +static void OnTerminate(void); static LRESULT CALLBACK CBTProc(int, WPARAM, LPARAM); static LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); static INT_PTR CALLBACK AboutDlgProc(HWND, UINT, WPARAM, LPARAM); static HWND CreateStatusBar(HWND, HINSTANCE); static void UpdateTheme(void); -int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, - LPSTR lpCmdLine, INT nCmdShow) +int WINAPI WinMain(const HINSTANCE hInstance, const HINSTANCE, const LPSTR lpCmdLine, const INT nCmdShow) { /* Exit gracefully on uncaught exception. */ std::set_terminate(OnTerminate); @@ -80,8 +79,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, g_hPopupMenu = LoadMenu(NULL, MAKEINTRESOURCE(IDR_POPUPMENU)); g_hPopupMenu = GetSubMenu(g_hPopupMenu, 0); - WNDCLASSEX wc; - memset(&wc, 0, sizeof(WNDCLASSEX)); + WNDCLASSEX wc = {0}; wc.cbSize = sizeof(WNDCLASSEX); wc.lpfnWndProc = WndProc; wc.hInstance = hInstance; @@ -97,10 +95,8 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, /* Create window. Note that a CBT hook is used to initialize * important global variables before any messages are sent to * the new window. */ - HHOOK hHook; - HWND hWnd; - hHook = SetWindowsHookEx(WH_CBT, CBTProc, 0, GetCurrentThreadId()); - hWnd = CreateWindowEx( + const HHOOK hHook = SetWindowsHookEx(WH_CBT, CBTProc, 0, GetCurrentThreadId()); + const HWND hWnd = CreateWindowEx( 0, TEXT("Episode Browser"), TEXT("Episode Browser"), @@ -133,7 +129,7 @@ void OnTerminate() { try { std::rethrow_exception(std::current_exception()); - } catch (term_t &t) { + } catch (const term_t &t) { TCHAR *tsz; if (PL_get_tchars(t, &tsz, CVT_WRITE)) { MessageBox(NULL, tsz, TEXT("Fatal Error"), MB_ICONERROR); @@ -178,7 +174,7 @@ static LRESULT CALLBACK CBTProc(int nCode, WPARAM wParam, LPARAM lParam) return 0; } -LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) +LRESULT CALLBACK WndProc(const HWND hWnd, const UINT uMsg, const WPARAM wParam, LPARAM lParam) { switch (uMsg) { case WM_CREATE: @@ -200,11 +196,9 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) DestroyWindow(hWnd); break; case WM_DESTROY: - { g_lpElv->SaveFocus(); PostQuitMessage(0); break; - } case WM_SIZE: SendMessage(g_hWndStatus, WM_SIZE, wParam, lParam); UpdateLayout(); @@ -221,7 +215,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) break; case 0x02E0: /* WM_DPICHANGED */ { - LPRECT lpr = (LPRECT)lParam; + const LPRECT lpr = (LPRECT)lParam; g_iDPI = HIWORD(wParam); SetWindowPos(hWnd, NULL, lpr->left, lpr->top, @@ -302,7 +296,6 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) ); break; case IDM_VIEW_WATCHED: - { CheckMenuItem(GetMenu(hWnd), IDM_VIEW_WATCHED, g_bViewWatched? MF_UNCHECKED: MF_CHECKED); g_bViewWatched = !g_bViewWatched; @@ -310,9 +303,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) g_lpElv->Update(); g_lpElv->EnsureFocusVisible(); break; - } case IDM_VIEW_TV_ORIGINAL: - { CheckMenuItem(GetMenu(hWnd), IDM_VIEW_TV_ORIGINAL, g_bViewTVOriginal? MF_UNCHECKED: MF_CHECKED); g_bViewTVOriginal = !g_bViewTVOriginal; @@ -320,16 +311,13 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) g_lpElv->Update(); g_lpElv->EnsureFocusVisible(); break; - } case IDM_VIEW_OTHERS: /* Show/hide other screenwriters. */ - { - int iEpFocus; if (g_szLimitScreenwriter[0]) { CheckMenuItem(GetMenu(hWnd), IDM_VIEW_OTHERS, MF_CHECKED); g_szLimitScreenwriter[0] = 0; } else { - iEpFocus = ListView_GetNextItem(g_lpElv->Handle(), -1, LVNI_FOCUSED); + const int iEpFocus = ListView_GetNextItem(g_lpElv->Handle(), -1, LVNI_FOCUSED); if (iEpFocus == -1) break; LVITEM lvi; @@ -349,7 +337,6 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) g_lpElv->Update(); g_lpElv->EnsureFocusVisible(); break; - } case IDM_WATCH_LOCALLY: case IDM_WATCH_ONLINE: case IDM_TOGGLE: @@ -469,7 +456,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) return 0; } -INT_PTR CALLBACK AboutDlgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) +INT_PTR CALLBACK AboutDlgProc(const HWND hWnd, const UINT uMsg, const WPARAM wParam, const LPARAM lParam) { switch (uMsg) { case WM_CLOSE: @@ -489,9 +476,9 @@ INT_PTR CALLBACK AboutDlgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam return TRUE; } -HWND CreateStatusBar(HWND hWndParent, HINSTANCE hInstance) +HWND CreateStatusBar(const HWND hWndParent, const HINSTANCE hInstance) { - HWND hWnd = CreateWindowEx( + return CreateWindowEx( 0, STATUSCLASSNAME, (LPCTSTR) NULL, @@ -502,7 +489,6 @@ HWND CreateStatusBar(HWND hWndParent, HINSTANCE hInstance) hInstance, NULL ); - return hWnd; } /***/ @@ -537,7 +523,7 @@ void UpdateLayout() SendMessage(g_lpDlv->Handle(), WM_SETREDRAW, TRUE, 0); /* Resize status bar parts. */ - int aParts[] = {rc.right-Dpi(55), rc.right}; + const int aParts[] = {rc.right-Dpi(55), rc.right}; SendMessage(g_hWndStatus, SB_SETPARTS, (WPARAM)sizeof(aParts), (LPARAM)aParts); } @@ -545,7 +531,7 @@ void UpdateLayout() void UpdateTheme() { if (!g_bThemes) return; - BOOL bThemeActive = IsThemeActive(); + const int bThemeActive = IsThemeActive(); g_lpDlv->UpdateTheme(bThemeActive); g_lpElv->UpdateTheme(bThemeActive); } |