aboutsummaryrefslogtreecommitdiff
path: root/c/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'c/main.cpp')
-rw-r--r--c/main.cpp84
1 files changed, 38 insertions, 46 deletions
diff --git a/c/main.cpp b/c/main.cpp
index f428d49..b8303b5 100644
--- a/c/main.cpp
+++ b/c/main.cpp
@@ -20,8 +20,8 @@
int g_dpi = 96;
/* Cursors. */
-HCURSOR g_hcArrow = LoadCursor(NULL, IDC_ARROW);
-HCURSOR g_hcSizeNs = LoadCursor(NULL, IDC_SIZENS);
+HCURSOR g_hcArrow = LoadCursor(nullptr, IDC_ARROW);
+HCURSOR g_hcSizeNs = LoadCursor(nullptr, IDC_SIZENS);
/* Fonts. */
HFONT g_hfNormal;
@@ -100,19 +100,19 @@ int WINAPI WinMain(const HINSTANCE hInstance, const HINSTANCE, char* const, cons
std::set_terminate(OnTerminate);
/* Initialize Prolog. */
- char* argv[] = {const_cast<char*>("EpisodeBrowser"), NULL};
+ char* argv[] = {const_cast<char*>("EpisodeBrowser"), nullptr};
if (!PL_initialise(1, argv))
throw std::runtime_error("Could not initialize Prolog.");
if (!Pl("track_episodes","attach") || !Pl("episode_data","attach"))
throw std::runtime_error("Could not attach databases.");
- /* Initialize common controls, load menu and register window class. */
INITCOMMONCONTROLSEX icc;
icc.dwSize = sizeof(icc);
icc.dwICC = ICC_WIN95_CLASSES;
Require(InitCommonControlsEx(&icc));
- g_hMenuPopup = Require(LoadMenu((HINSTANCE)NULL, MAKEINTRESOURCE(IDR_POPUPMENU)));
+ /* Load context menu. */
+ g_hMenuPopup = Require(LoadMenu(nullptr, MAKEINTRESOURCE(IDR_POPUPMENU)));
g_hMenuPopup = Require(GetSubMenu(g_hMenuPopup, 0));
WNDCLASSEX wc;
@@ -120,35 +120,34 @@ int WINAPI WinMain(const HINSTANCE hInstance, const HINSTANCE, char* const, cons
wc.cbSize = sizeof(WNDCLASSEX);
wc.lpfnWndProc = WndProc;
wc.hInstance = hInstance;
- wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
+ wc.hIcon = LoadIcon(nullptr, IDI_APPLICATION);
wc.hCursor = g_hcArrow;
- wc.hbrBackground = (HBRUSH)COLOR_WINDOW;
+ wc.hbrBackground = reinterpret_cast<HBRUSH>(COLOR_WINDOW);
wc.lpszMenuName = MAKEINTRESOURCE(IDR_MENU);
wc.lpszClassName = L"Episode Browser";
- wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
+ wc.hIconSm = LoadIcon(nullptr, IDI_APPLICATION);
Require(RegisterClassEx(&wc));
/* Create window. A CBT hook is used to initialize important
* global variables before any messages are sent to the new
* window. It is vital that the hook is set up correctly. */
- const HHOOK hHook = Require(SetWindowsHookEx(WH_CBT, CBTProc,
- (HINSTANCE)NULL, GetCurrentThreadId()));
+ const HHOOK hHook = Require(SetWindowsHookEx(WH_CBT, CBTProc, nullptr, GetCurrentThreadId()));
const HWND hWnd = Require(CreateWindowEx(
0,
L"Episode Browser",
L"Episode Browser",
WS_OVERLAPPEDWINDOW|WS_CLIPCHILDREN,
CW_USEDEFAULT, CW_USEDEFAULT, 0, 0,
- (HWND)NULL, (HMENU)NULL, hInstance, (void*)NULL));
+ nullptr, nullptr, hInstance, nullptr));
Require(UnhookWindowsHookEx(hHook));
g_hWndStatus = Require(CreateWindowEx(
0,
STATUSCLASSNAME,
- (const wchar_t*)NULL,
+ nullptr,
WS_CHILD|WS_VISIBLE|SBARS_SIZEGRIP,
0, 0, 0, 0,
- hWnd, (HMENU)IDR_STATUS, hInstance, (void*)NULL));
+ hWnd, reinterpret_cast<HMENU>(IDR_STATUS), hInstance, nullptr));
ShowWindow(hWnd, nCmdShow);
@@ -158,7 +157,7 @@ int WINAPI WinMain(const HINSTANCE hInstance, const HINSTANCE, char* const, cons
g_elv->RestoreFocus();
MSG msg;
- while (GetMessage(&msg, NULL, 0, 0) > 0) {
+ while (GetMessage(&msg, nullptr, 0, 0) > 0) {
if (IsDialogMessage(hWnd, &msg)) continue;
TranslateMessage(&msg);
DispatchMessage(&msg);
@@ -177,24 +176,23 @@ static LRESULT CALLBACK CBTProc(const int nCode, const WPARAM wParam, const LPAR
* window -- before WndProc! This is important, as it
* initializes global variables that are used by WndProc. */
- g_hWnd = (HWND)wParam;
+ g_hWnd = reinterpret_cast<HWND>(wParam);
/* Look up DPI. */
if (auto lib = Library::Maybe(L"User32.dll");
auto GetDpiForWindow = lib->GetProcAddress<UINT(HWND)>("GetDpiForWindow"))
g_dpi = GetDpiForWindow(g_hWnd);
- /* Load fonts. */
+ /* Load normal font. */
if (auto lib = Library::Maybe(L"User32.dll");
lib->GetProcAddress<void>("SystemParametersInfoW")) {
- NONCLIENTMETRICS m;
- m.cbSize = sizeof(NONCLIENTMETRICS);
- Require(SystemParametersInfo(SPI_GETNONCLIENTMETRICS,
- sizeof(NONCLIENTMETRICS), &m, 0));
+ NONCLIENTMETRICS m = {sizeof(NONCLIENTMETRICS)};
+ Require(SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICS), &m, 0));
g_hfNormal = Require(CreateFontIndirect(&m.lfMessageFont));
} else
g_hfNormal = static_cast<HFONT>(Require(GetStockObject(DEFAULT_GUI_FONT)));
+ /* Load bold font. */
LOGFONT lf;
Require(GetObject(g_hfNormal, sizeof(LOGFONT), &lf));
lf.lfWeight = FW_BOLD;
@@ -230,16 +228,13 @@ LRESULT CALLBACK WndProc(const HWND hWnd, const UINT uMsg, const WPARAM wParam,
switch (uMsg) {
case WM_CREATE:
UpdateTheme();
- SetWindowPos(hWnd, NULL, -1, -1, Dpi(510), Dpi(412), SWP_NOZORDER|SWP_NOMOVE|SWP_NOACTIVATE);
+ SetWindowPos(hWnd, nullptr, -1, -1, Dpi(510), Dpi(412), SWP_NOZORDER|SWP_NOMOVE|SWP_NOACTIVATE);
SetFocus(g_elv->hWnd);
/* Set menu item checkmarks according to saved settings. */
- CheckMenuItem(GetMenu(hWnd), IDM_VIEW_WATCHED,
- g_bViewWatched? MF_CHECKED: MF_UNCHECKED);
- CheckMenuItem(GetMenu(hWnd), IDM_VIEW_TV_ORIGINAL,
- g_bViewTVOriginal? MF_CHECKED: MF_UNCHECKED);
- CheckMenuItem(GetMenu(hWnd), IDM_VIEW_OTHERS,
- g_limitScreenwriter[0]? MF_UNCHECKED: MF_CHECKED);
+ CheckMenuItem(GetMenu(hWnd), IDM_VIEW_WATCHED, g_bViewWatched? MF_CHECKED: MF_UNCHECKED);
+ CheckMenuItem(GetMenu(hWnd), IDM_VIEW_TV_ORIGINAL, g_bViewTVOriginal? MF_CHECKED: MF_UNCHECKED);
+ CheckMenuItem(GetMenu(hWnd), IDM_VIEW_OTHERS, g_limitScreenwriter[0]? MF_UNCHECKED: MF_CHECKED);
break;
case WM_CLOSE:
DestroyWindow(hWnd);
@@ -253,8 +248,8 @@ LRESULT CALLBACK WndProc(const HWND hWnd, const UINT uMsg, const WPARAM wParam,
UpdateLayout(LOWORD(lParam), HIWORD(lParam));
break;
case WM_GETMINMAXINFO:
- ((MINMAXINFO*)lParam)->ptMinTrackSize.x = Dpi(220);
- ((MINMAXINFO*)lParam)->ptMinTrackSize.y = Dpi(220);
+ reinterpret_cast<MINMAXINFO*>(lParam)->ptMinTrackSize.x = Dpi(220);
+ reinterpret_cast<MINMAXINFO*>(lParam)->ptMinTrackSize.y = Dpi(220);
break;
case WM_THEMECHANGED:
UpdateTheme();
@@ -262,13 +257,13 @@ LRESULT CALLBACK WndProc(const HWND hWnd, const UINT uMsg, const WPARAM wParam,
break;
case 0x02E0: /* WM_DPICHANGED */
{
- const RECT* const r = (RECT*)lParam;
+ const RECT* const r = reinterpret_cast<RECT*>(lParam);
/* Update DPI and cached metrics. */
g_dpi = HIWORD(wParam);
Metric<SM_CXVSCROLL> = GetSystemMetrics(SM_CXVSCROLL);
- Prefer(SetWindowPos(hWnd, (HWND)NULL,
+ Prefer(SetWindowPos(hWnd, nullptr,
r->left, r->top,
r->right-r->left,
r->bottom-r->top,
@@ -289,7 +284,7 @@ LRESULT CALLBACK WndProc(const HWND hWnd, const UINT uMsg, const WPARAM wParam,
}
break;
case WM_NOTIFY:
- switch (((NMHDR*)lParam)->idFrom) {
+ switch (reinterpret_cast<NMHDR*>(lParam)->idFrom) {
case IDC_EPISODELISTVIEW:
return g_elv->HandleNotify(lParam);
}
@@ -356,7 +351,7 @@ LRESULT CALLBACK WndProc(const HWND hWnd, const UINT uMsg, const WPARAM wParam,
const wchar_t** const vTip = group==IDG_MENU? vTipMenu: vTipCtx;
tip = vTip[ID_INDEX(command)];
}
- SendMessage(g_hWndStatus, SB_SETTEXT, MAKEWPARAM(0,0), (LPARAM)tip);
+ SendMessage(g_hWndStatus, SB_SETTEXT, MAKEWPARAM(0,0), reinterpret_cast<LPARAM>(tip));
break;
}
case WM_LBUTTONDOWN:
@@ -365,7 +360,7 @@ LRESULT CALLBACK WndProc(const HWND hWnd, const UINT uMsg, const WPARAM wParam,
case WM_SETCURSOR:
if (!g_dragDlv.HandleMove()) {
/* Use default cursor. */
- if ((HWND)wParam == hWnd)
+ if (reinterpret_cast<HWND>(wParam) == hWnd)
return DefWindowProc(hWnd, uMsg, wParam, lParam);
else
return 0;
@@ -395,23 +390,20 @@ void HandleMainMenu(const HWND hWnd, unsigned short command)
break;
case IDM_FILE_ABOUT:
DialogBox(
- GetModuleHandle(NULL),
+ GetModuleHandle(nullptr),
MAKEINTRESOURCE(IDD_ABOUT),
hWnd,
- AboutDlgProc
- );
+ AboutDlgProc);
break;
case IDM_VIEW_WATCHED:
- CheckMenuItem(GetMenu(hWnd), IDM_VIEW_WATCHED,
- g_bViewWatched? MF_UNCHECKED: MF_CHECKED);
+ CheckMenuItem(GetMenu(hWnd), IDM_VIEW_WATCHED, g_bViewWatched? MF_UNCHECKED: MF_CHECKED);
g_bViewWatched = !g_bViewWatched;
Pl("cfg","set_view_watched",g_bViewWatched);
g_elv->Update();
g_elv->EnsureFocusVisible();
break;
case IDM_VIEW_TV_ORIGINAL:
- CheckMenuItem(GetMenu(hWnd), IDM_VIEW_TV_ORIGINAL,
- g_bViewTVOriginal? MF_UNCHECKED: MF_CHECKED);
+ CheckMenuItem(GetMenu(hWnd), IDM_VIEW_TV_ORIGINAL, g_bViewTVOriginal? MF_UNCHECKED: MF_CHECKED);
g_bViewTVOriginal = !g_bViewTVOriginal;
Pl("cfg","set_view_tv_original",g_bViewTVOriginal);
g_elv->Update();
@@ -509,7 +501,7 @@ void WaitFor(const char* mod, const char* pred)
static_cast<wchar_t*>(activePred));
if (EBMessageBox(msg, L"Error", MB_YESNO|MB_ICONWARNING) != IDYES)
return;
- KillTimer(NULL, iTimer);
+ KillTimer(nullptr, iTimer);
bActive = 0;
g_elv->Update();
}
@@ -524,9 +516,9 @@ void WaitFor(const char* mod, const char* pred)
if (Pl("episode_data","thread_running",aThread)) {
i = (i+1)%4;
SendMessage(g_hWndStatus, SB_SETTEXT, MAKEWPARAM(1,0),
- (LPARAM)(i==0? L".": i==1? L"..": i==2? L"...": L""));
+ reinterpret_cast<LPARAM>(i==0? L".": i==1? L"..": i==2? L"...": L""));
} else {
- KillTimer(NULL, iTimer);
+ KillTimer(nullptr, iTimer);
i = 0;
bActive = 0;
g_elv->Update();
@@ -534,8 +526,8 @@ void WaitFor(const char* mod, const char* pred)
};
Plx(mod,"thread_create",pred,&aThread);
- SendMessage(g_hWndStatus, SB_SETTEXT, MAKEWPARAM(1,0), (LPARAM)L".");
- if (Prefer(iTimer = SetTimer(NULL, -1, 500, proc))) {
+ SendMessage(g_hWndStatus, SB_SETTEXT, MAKEWPARAM(1,0), reinterpret_cast<LPARAM>(L"."));
+ if (Prefer(iTimer = SetTimer(nullptr, -1, 500, proc))) {
activePred = WcharPtr::FromNarrow(pred);
bActive = 1;
}