aboutsummaryrefslogtreecommitdiff
path: root/c
diff options
context:
space:
mode:
Diffstat (limited to 'c')
-rw-r--r--c/datalistview.cpp8
-rw-r--r--c/episodelistview.cpp34
-rw-r--r--c/layout.cpp7
-rw-r--r--c/listview.cpp17
-rw-r--r--c/main.cpp84
-rw-r--r--c/pl.h2
-rw-r--r--c/wcharptr.cpp2
-rw-r--r--c/win.cpp16
-rw-r--r--c/win.h12
9 files changed, 88 insertions, 94 deletions
diff --git a/c/datalistview.cpp b/c/datalistview.cpp
index bd5c8d9..531dc2c 100644
--- a/c/datalistview.cpp
+++ b/c/datalistview.cpp
@@ -12,19 +12,19 @@
#include "pl.h"
DataListView::DataListView(const HWND hWndParent)
- : ListView(hWndParent, (HMENU)IDC_DATALISTVIEW, LVS_NOCOLUMNHEADER)
+ : ListView(hWndParent, reinterpret_cast<HMENU>(IDC_DATALISTVIEW), LVS_NOCOLUMNHEADER)
{
LVCOLUMN lvc;
lvc.mask = LVCF_WIDTH|LVCF_TEXT|LVCF_SUBITEM;
lvc.iSubItem = DLVSIKEY;
- lvc.pszText = (wchar_t*)L"Key";
+ lvc.pszText = const_cast<wchar_t*>(L"Key");
lvc.cx = Dpi(42);
ListView_InsertColumn(hWnd, DLVSIKEY, &lvc);
lvc.iSubItem = DLVSIVALUE;
- lvc.pszText = (wchar_t*)L"Value";
+ lvc.pszText = const_cast<wchar_t*>(L"Value");
lvc.cx = 500;
ListView_InsertColumn(hWnd, DLVSIVALUE, &lvc);
}
@@ -58,7 +58,7 @@ void DataListView::ShowEpisode(const int iEpisode)
const term_t t = PL_new_term_refs(arity);
if (!PlPut(t, iEpisode)) return;
- Query q (NULL, PL_predicate("episode_datum", arity, "episode_data"), t);
+ Query q (nullptr, PL_predicate("episode_datum", arity, "episode_data"), t);
LVITEM lviKey = {LVIF_TEXT};
LVITEM lviValue = {LVIF_TEXT};
diff --git a/c/episodelistview.cpp b/c/episodelistview.cpp
index c22b109..3ecaab1 100644
--- a/c/episodelistview.cpp
+++ b/c/episodelistview.cpp
@@ -12,23 +12,23 @@
#include "win.h"
EpisodeListView::EpisodeListView(const HWND hWndParent)
- : ListView(hWndParent, (HMENU)IDC_EPISODELISTVIEW, 0)
+ : ListView(hWndParent, reinterpret_cast<HMENU>(IDC_EPISODELISTVIEW), 0)
{
LVCOLUMN lvc;
lvc.mask = LVCF_WIDTH|LVCF_TEXT|LVCF_SUBITEM;
lvc.iSubItem = ELVSIEPISODE;
- lvc.pszText = (wchar_t*)L"#";
+ lvc.pszText = const_cast<wchar_t*>(L"#");
lvc.cx = Dpi(42);
ListView_InsertColumn(hWnd, ELVSIEPISODE, &lvc);
lvc.iSubItem = ELVSITITLE;
- lvc.pszText = (wchar_t*)L"Title";
+ lvc.pszText = const_cast<wchar_t*>(L"Title");
lvc.cx = 500;
ListView_InsertColumn(hWnd, ELVSITITLE, &lvc);
lvc.iSubItem = ELVSIRATING;
- lvc.pszText = (wchar_t*)L"/";
+ lvc.pszText = const_cast<wchar_t*>(L"/");
lvc.cx = Dpi(30);
ListView_InsertColumn(hWnd, ELVSIRATING, &lvc);
@@ -45,7 +45,7 @@ void EpisodeListView::EnsureFocusVisible()
LRESULT EpisodeListView::HandleNotify(const LPARAM lParam)
{
- const NMLISTVIEW* const nm = (NMLISTVIEW*)lParam;
+ const NMLISTVIEW* const nm = reinterpret_cast<NMLISTVIEW*>(lParam);
switch (nm->hdr.code) {
case LVN_ITEMCHANGED: /* Select/focus episode. */
@@ -67,7 +67,7 @@ LRESULT EpisodeListView::HandleNotify(const LPARAM lParam)
}
case LVN_KEYDOWN: /* Navigate episodes by keyboard. */
{
- const NMLVKEYDOWN *const nm = (NMLVKEYDOWN*)lParam;
+ const NMLVKEYDOWN *const nm = reinterpret_cast<NMLVKEYDOWN*>(lParam);
switch (nm->wVKey) {
case VK_LEFT:
SelectUnwatched(-1);
@@ -80,7 +80,7 @@ LRESULT EpisodeListView::HandleNotify(const LPARAM lParam)
}
case NM_CUSTOMDRAW: /* Make unwatched episodes bold. */
{
- const NMLVCUSTOMDRAW* const nm = (NMLVCUSTOMDRAW*)lParam;
+ const NMLVCUSTOMDRAW* const nm = reinterpret_cast<NMLVCUSTOMDRAW*>(lParam);
switch (nm->nmcd.dwDrawStage) {
case CDDS_PREPAINT:
return CDRF_NOTIFYITEMDRAW;
@@ -119,7 +119,7 @@ LRESULT EpisodeListView::HandleNotify(const LPARAM lParam)
const DWORD pos = GetMessagePos();
Require(TrackPopupMenu(g_hMenuPopup, TPM_RIGHTBUTTON,
LOWORD(pos), HIWORD(pos), 0,
- m_hWndParent, (const RECT*)NULL));
+ m_hWndParent, nullptr));
break;
}
}
@@ -129,7 +129,7 @@ LRESULT EpisodeListView::HandleNotify(const LPARAM lParam)
void EpisodeListView::Redraw()
{
- RedrawWindow(hWnd, NULL, NULL,
+ RedrawWindow(hWnd, nullptr, nullptr,
RDW_ERASE|RDW_FRAME|RDW_INVALIDATE|RDW_ALLCHILDREN);
}
@@ -230,17 +230,17 @@ void EpisodeListView::ShowFocus()
void EpisodeListView::Sort()
{
- ListView_SortItemsEx(hWnd, EpisodeListView::SortProc, (LPARAM)this);
+ ListView_SortItemsEx(hWnd, EpisodeListView::SortProc, reinterpret_cast<LPARAM>(this));
}
int CALLBACK EpisodeListView::SortProc(const LPARAM iItem1, const LPARAM iItem2, const LPARAM extra)
{
- EpisodeListView* const elv = (EpisodeListView*)extra;
+ EpisodeListView* const elv = reinterpret_cast<EpisodeListView*>(extra);
- LVITEM lvi1 = {LVIF_PARAM, (int)iItem1};
+ LVITEM lvi1 = {LVIF_PARAM, static_cast<int>(iItem1)};
if (!ListView_GetItem(elv->hWnd, &lvi1)) return 0;
- LVITEM lvi2 = {LVIF_PARAM, (int)iItem2};
+ LVITEM lvi2 = {LVIF_PARAM, static_cast<int>(iItem2)};
if (!ListView_GetItem(elv->hWnd, &lvi2)) return 0;
/* abs(m_iSortCol) is the 1-based index of the column to sort by.
@@ -395,7 +395,7 @@ void EpisodeListView::Update()
extern HWND g_hWndStatus;
wchar_t disp[16];
swprintf_s(disp, sizeof(disp)/sizeof(*disp), L"%d", cItem);
- SendMessage(g_hWndStatus, SB_SETTEXT, MAKEWPARAM(1,0), (LPARAM)disp);
+ SendMessage(g_hWndStatus, SB_SETTEXT, MAKEWPARAM(1,0), reinterpret_cast<LPARAM>(disp));
SendMessage(hWnd, WM_SETREDRAW, TRUE, 0);
}
@@ -411,7 +411,7 @@ void EpisodeListView::UpdateItem(const int iItem, const LPARAM lParam)
r: int rating;
if (!Pl("episode_data","episode_rating",lParam,&rating)) {
- ListView_SetItemText(hWnd, iItem, ELVSIRATING, (wchar_t*)L"");
+ ListView_SetItemText(hWnd, iItem, ELVSIRATING, const_cast<wchar_t*>(L""));
return;
}
@@ -432,8 +432,8 @@ LRESULT CALLBACK EpisodeListView::WndProc(const HWND hWnd, const UINT uMsg,
* handled by the NM_RETURN case in HandleNotify. */
const LRESULT lResult = CallWindowProc(m_proc0, hWnd, uMsg, wParam, lParam);
- if (lParam && ((MSG*)lParam)->message == WM_KEYDOWN
- && ((MSG*)lParam)->wParam == VK_RETURN)
+ MSG* const msg = reinterpret_cast<MSG*>(lParam);
+ if (lParam && msg->message == WM_KEYDOWN && msg->wParam == VK_RETURN)
return DLGC_WANTMESSAGE;
return lResult;
}
diff --git a/c/layout.cpp b/c/layout.cpp
index 5fe5da4..24ad11f 100644
--- a/c/layout.cpp
+++ b/c/layout.cpp
@@ -31,10 +31,11 @@ void UpdateLayout(int w, int h)
/* Resize status bar parts. */
const int aParts[] = {rc.right-Dpi(55), rc.right};
- SendMessage(g_hWndStatus, SB_SETPARTS, (WPARAM)sizeof(aParts), (LPARAM)aParts);
+ SendMessage(g_hWndStatus, SB_SETPARTS,
+ reinterpret_cast<WPARAM>(sizeof(aParts)), reinterpret_cast<LPARAM>(aParts));
SendMessage(g_hWnd, WM_SETREDRAW, TRUE, 0);
- RedrawWindow(g_hWnd, NULL, NULL,
+ RedrawWindow(g_hWnd, nullptr, nullptr,
RDW_ERASE|RDW_FRAME|RDW_INVALIDATE|RDW_ALLCHILDREN);
}
@@ -61,7 +62,7 @@ void DlvDragger::Drag(const int, const int y)
h = rrDlv.bottom-y;
g_dlv->SetHeight(h);
UpdateLayout();
- RedrawWindow(g_hWnd, NULL, NULL,
+ RedrawWindow(g_hWnd, nullptr, nullptr,
RDW_ERASE|RDW_FRAME|RDW_INVALIDATE|RDW_ALLCHILDREN|RDW_UPDATENOW);
}
diff --git a/c/listview.cpp b/c/listview.cpp
index 82c6df6..0392941 100644
--- a/c/listview.cpp
+++ b/c/listview.cpp
@@ -20,12 +20,13 @@ ListView::ListView(const HWND hWndParent, const HMENU hMenu, const DWORD dwStyle
L"",
dwStyle|WS_CHILD|WS_VISIBLE|WS_VSCROLL|WS_TABSTOP|LVS_REPORT|LVS_SHOWSELALWAYS,
0, 0, 0, 0,
- hWndParent, hMenu, GetModuleHandle(NULL), this));
- m_proc0 = (WNDPROC)SetWindowLongPtr(hWnd, GWLP_WNDPROC, (LONG_PTR)::WndProc);
+ hWndParent, hMenu, GetModuleHandle(nullptr), this));
+ m_proc0 = reinterpret_cast<WNDPROC>(SetWindowLongPtr(
+ hWnd, GWLP_WNDPROC, reinterpret_cast<LONG_PTR>(::WndProc)));
- Require(SetProp(hWnd, L"this", (HANDLE)this));
+ Require(SetProp(hWnd, L"this", reinterpret_cast<HANDLE>(this)));
ListView_SetExtendedListViewStyle(hWnd, LVS_EX_FULLROWSELECT|LVS_EX_DOUBLEBUFFER);
- SendMessage(hWnd, WM_SETFONT, (WPARAM)g_hfNormal, MAKELPARAM(FALSE, 0));
+ SendMessage(hWnd, WM_SETFONT, reinterpret_cast<WPARAM>(g_hfNormal), MAKELPARAM(FALSE, 0));
}
int ListView::Height()
@@ -47,12 +48,12 @@ void ListView::UpdateTheme(const BOOL bThemeActive)
theme = L"Explorer";
action = UIS_SET;
} else {
- theme = NULL;
+ theme = nullptr;
action = UIS_CLEAR;
}
/* Use modern "Explorer" theme. */
- SetWindowTheme(hWnd, theme, NULL);
+ SetWindowTheme(hWnd, theme, nullptr);
/* Hide focus rectangles. */
SendMessage(hWnd, WM_UPDATEUISTATE, MAKEWPARAM(action, UISF_HIDEFOCUS), 0);
@@ -64,7 +65,7 @@ LRESULT CALLBACK ListView::WndProc(const HWND hWnd, const UINT uMsg,
extern DlvDragger g_dragDlv;
switch (uMsg) {
case WM_NOTIFY:
- switch (((NMHDR*)lParam)->code) {
+ switch (reinterpret_cast<NMHDR*>(lParam)->code) {
case HDN_ENDTRACK:
UpdateLayout();
return TRUE;
@@ -83,7 +84,7 @@ LRESULT CALLBACK ListView::WndProc(const HWND hWnd, const UINT uMsg,
LRESULT CALLBACK WndProc(const HWND hWnd, const UINT uMsg, const WPARAM wParam,
const LPARAM lParam)
{
- ListView* const lv = (ListView*)GetProp(hWnd, L"this");
+ ListView* const lv = reinterpret_cast<ListView*>(GetProp(hWnd, L"this"));
if (uMsg == WM_DESTROY)
RemoveProp(hWnd, L"this");
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;
}
diff --git a/c/pl.h b/c/pl.h
index b0cdbbd..2992e86 100644
--- a/c/pl.h
+++ b/c/pl.h
@@ -102,7 +102,7 @@ int Pl(const char* const mod, const char* const pred, T... xs)
const term_t t = PL_new_term_refs(sizeof...(T));
if (!PlPutN(t, xs...)) return 0;
- Query q(NULL, PL_predicate(pred, sizeof...(T), mod), t);
+ Query q(nullptr, PL_predicate(pred, sizeof...(T), mod), t);
if constexpr (Except) {
if (!q.NextSolution()) return 0;
diff --git a/c/wcharptr.cpp b/c/wcharptr.cpp
index 240fff5..25ddae1 100644
--- a/c/wcharptr.cpp
+++ b/c/wcharptr.cpp
@@ -46,7 +46,7 @@ WcharPtr::~WcharPtr() noexcept
WcharPtr WcharPtr::FromNarrow(const char* const src, const int cp)
{
int cbMultiByte = strlen(src)+1;
- int cchWideChar = MultiByteToWideChar(cp, 0, src, cbMultiByte, NULL, 0);
+ int cchWideChar = MultiByteToWideChar(cp, 0, src, cbMultiByte, nullptr, 0);
wchar_t* dst = new wchar_t[cchWideChar];
if (!MultiByteToWideChar(cp, 0, src, cbMultiByte, dst, cchWideChar)) {
delete dst;
diff --git a/c/win.cpp b/c/win.cpp
index a120f96..19cfaab 100644
--- a/c/win.cpp
+++ b/c/win.cpp
@@ -22,11 +22,11 @@ const char* Win32Error::what() const noexcept
if (!m_szMsg)
FormatMessageA(
FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS,
- NULL,
+ nullptr,
code,
MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US),
(char*)&m_szMsg,
- 0, NULL);
+ 0, nullptr);
return m_szMsg;
}
@@ -35,11 +35,11 @@ const wchar_t* Win32Error::What() const noexcept
if (!m_wszMsg)
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS,
- NULL,
+ nullptr,
code,
MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US),
(wchar_t*)&m_wszMsg,
- 0, NULL);
+ 0, nullptr);
return m_wszMsg;
}
@@ -75,14 +75,14 @@ int EBMessageBox(const wchar_t* const wszText, const wchar_t* const wszCaption,
if (!g_hWnd || nCode < 0 || nCode != HCBT_ACTIVATE)
return CallNextHookEx(0, nCode, wParam, lParam);
- HWND hWnd = (HWND)wParam;
+ HWND hWnd = reinterpret_cast<HWND>(wParam);
long lStyle = GetWindowLong(hWnd, GWL_STYLE);
if (!(lStyle & WS_POPUP)) return 0;
RECT rcMain, rcMsg;
GetWindowRect(g_hWnd, &rcMain);
GetWindowRect(hWnd, &rcMsg);
- SetWindowPos(hWnd, NULL,
+ SetWindowPos(hWnd, nullptr,
rcMain.left+(rcMain.right-rcMain.left)/2-(rcMsg.right-rcMsg.left)/2,
rcMain.top+(rcMain.bottom-rcMain.top)/2-(rcMsg.bottom-rcMsg.top)/2,
-1, -1,
@@ -91,7 +91,7 @@ int EBMessageBox(const wchar_t* const wszText, const wchar_t* const wszCaption,
return 0;
};
- HHOOK hHook = Require(SetWindowsHookEx(WH_CBT, proc, (HINSTANCE)NULL, GetCurrentThreadId()));
+ HHOOK hHook = Require(SetWindowsHookEx(WH_CBT, proc, nullptr, GetCurrentThreadId()));
int r = MessageBox(g_hWnd, wszText, wszCaption, uType);
Require(UnhookWindowsHookEx(hHook));
return r;
@@ -102,7 +102,7 @@ int GetRelativeCursorPos(HWND hWnd, POINT* pt)
RECT rc;
if (!GetClientRect(hWnd, &rc)) return 0;
SetLastError(ERROR_SUCCESS);
- if (!MapWindowPoints(hWnd, NULL, (POINT*)&rc, 2)) return 0;
+ if (!MapWindowPoints(hWnd, nullptr, (POINT*)&rc, 2)) return 0;
POINT ptMouse;
if (!GetCursorPos(&ptMouse)) return 0;
diff --git a/c/win.h b/c/win.h
index baafbf0..d36cbdf 100644
--- a/c/win.h
+++ b/c/win.h
@@ -19,8 +19,8 @@ struct Win32Error : public std::exception
const wchar_t* What() const noexcept;
DWORD code;
private:
- char* m_szMsg = NULL;
- wchar_t* m_wszMsg = NULL;
+ char* m_szMsg = nullptr;
+ wchar_t* m_wszMsg = nullptr;
};
/* Wrapper for loading and freeing dynamically linked libraries. */
@@ -49,7 +49,7 @@ T* Library::GetProcAddress(const char* const szProc) noexcept
template <int I>
auto Metric = GetSystemMetrics(I);
-/* Check result of Windows API call, throwing error on NULL. */
+/* Check result of Windows API call, throwing error on null. */
template <typename T>
inline T Require(const T x)
{
@@ -57,13 +57,13 @@ inline T Require(const T x)
return x;
}
-/* Check result of Windows API call, showing a warning on NULL. */
+/* Check result of Windows API call, showing a warning on null. */
template <typename T>
inline T Prefer(const T x)
{
if (!x) {
EBMessageBox(Win32Error().What(), L"System Error", MB_ICONWARNING);
- return (T)NULL;
+ return (T)0;
}
return x;
}
@@ -79,7 +79,7 @@ inline int Dpi(const int i)
inline BOOL GetRelativeRect(const HWND hWnd, RECT* const rr)
{
if (!GetClientRect(hWnd, rr)) return 0;
- return MapWindowPoints(hWnd, GetParent(hWnd), (POINT*)rr, 2);
+ return MapWindowPoints(hWnd, GetParent(hWnd), reinterpret_cast<POINT*>(rr), 2);
}
inline BOOL SetWindowRect(const HWND hWnd,