aboutsummaryrefslogtreecommitdiff
path: root/c/main.cpp
blob: 203757897999bce36d9f0c8df3200671fac82cc1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
#include <exception>
#include <sstream>
#include <windows.h>
#include <commctrl.h>
#include <uxtheme.h>
#include <SWI-Prolog.h>

#include "resource.h"
#include "common.h"
#include "datalistview.h"
#include "episodelistview.h"
#include "main.h"
#include "pl.h"

/* Application state. */
atom_t g_aThread;
int g_bThread;

/* Looked-up constants. */
int g_bThemes;
int g_iDPI = 96;

/* Fonts. */
HFONT g_hfNormal;
HFONT g_hfBold;

/* Menus. */
HMENU g_hPopupMenu;

/* Windows. */
HWND g_hWndFocus;
HWND g_hWnd;
HWND g_hWndStatus;

/* Child window objects. */
DataListView* g_pDlv;
EpisodeListView* g_pElv;

/* View settings. */
int g_bViewWatched = 1;
int g_bViewTVOriginal = 1;
char g_szLimitScreenwriter[64];

static LRESULT CALLBACK CBTProc(int, WPARAM, LPARAM);
static LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
void WndProcMainMenu(const HWND, unsigned short);
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
{
	std::basic_ostringstream<T> ss;
	ss << AWTEXT(T, "Episode Browser was terminated due to ");
	ss << sz1;
	if (sz2)
		ss << ": " << sz2;
	else
		ss << ".";
	AWFUN(T, MessageBox)(g_hWnd, ss.str().c_str(), AWTEXT(T, "Fatal Error"), MB_ICONERROR);
}

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());
		else
			TerminateMsg<char>("a Prolog exception", NULL);
	} catch (const Win32Error& e) {
		TerminateMsg<TCHAR>(TEXT("a Windows error"), e.what<TCHAR>());
	} catch (const std::exception& e) {
		TerminateMsg<char>("an exception", e.what());
	} catch (...) {
		TerminateMsg<char>("an exception", NULL);
	}
	_Exit(1);
}

int WINAPI WinMain(const HINSTANCE hInstance, const HINSTANCE, char* const, const int nCmdShow)
{
	/* Exit gracefully on uncaught exception. */
	std::set_terminate(OnTerminate);

	/* Initialize Prolog. */
	char* argv[] = { (char*)"EpisodeBrowser", NULL };
	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_hPopupMenu = require(LoadMenu((HINSTANCE)NULL, MAKEINTRESOURCE(IDR_POPUPMENU)));
	g_hPopupMenu = require(GetSubMenu(g_hPopupMenu, 0));

	WNDCLASSEX wc;
	memset(&wc, 0, sizeof(WNDCLASSEX));
	wc.cbSize	 = sizeof(WNDCLASSEX);
	wc.lpfnWndProc	 = WndProc;
	wc.hInstance	 = hInstance;
	wc.hIcon	 = LoadIcon(NULL, IDI_APPLICATION);
	wc.hCursor	 = LoadCursor(NULL, IDC_ARROW);
	wc.hbrBackground = (HBRUSH)COLOR_WINDOW;
	wc.lpszMenuName	 = MAKEINTRESOURCE(IDR_MENU);
	wc.lpszClassName = TEXT("Episode Browser");
	wc.hIconSm	 = LoadIcon(NULL, 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 HWND hWnd = require(CreateWindowEx(
	    0,
	    TEXT("Episode Browser"),
	    TEXT("Episode Browser"),
	    WS_OVERLAPPEDWINDOW|WS_CLIPCHILDREN,
	    CW_USEDEFAULT, CW_USEDEFAULT, 0, 0,
	    (HWND)NULL, (HMENU)NULL, hInstance, (void*)NULL));
	require(UnhookWindowsHookEx(hHook));

	g_hWndStatus = require(CreateWindowEx(
	    0,
	    STATUSCLASSNAME,
	    (const TCHAR*)NULL,
	    WS_CHILD|WS_VISIBLE|SBARS_SIZEGRIP,
	    0, 0, 0, 0,
	    hWnd, (HMENU)IDR_STATUS, hInstance, (void*)NULL));

	ShowWindow(hWnd, nCmdShow);

	/* Populate episode list view. */
	Pl("track_episodes","update_tracked_episodes");
	g_pElv->Update();
	g_pElv->RestoreFocus();

	MSG msg;
	while (GetMessage(&msg, NULL, 0, 0) > 0) {
		if (IsDialogMessage(hWnd, &msg)) continue;
		TranslateMessage(&msg);
		DispatchMessage(&msg);
	}

	PL_halt(0);
	return 0;
}

static LRESULT CALLBACK CBTProc(const int nCode, const WPARAM wParam, const LPARAM lParam)
{
	if (nCode < 0 || nCode != HCBT_CREATEWND || g_hWnd)
		return CallNextHookEx(0, nCode, wParam, lParam);

	/* This code is run ONCE, at the creation of the top-level
	 * window -- before WndProc! This is important, as it
	 * initializes global variables that are used by WndProc. */

	g_hWnd = (HWND)wParam;

	/* Look up constants. */
	if (auto opLib = maybe_make<Library>(TEXT("User32.dll"));
	    auto GetDpiForWindow = opLib->GetProcAddress<UINT(HWND)>("GetDpiForWindow"))
		g_iDPI = GetDpiForWindow(g_hWnd);

	if (auto opLib = maybe_make<Library>(TEXT("uxtheme.dll"));
	    opLib->GetProcAddress<void>("SetWindowTheme"))
		g_bThemes = 1;

	if (auto opLib = maybe_make<Library>(TEXT("User32.dll"));
	    opLib->GetProcAddress<void>("SystemParametersInfo" WA)) {
		NONCLIENTMETRICS m;
		m.cbSize = 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)));

	LOGFONT lf;
	require(GetObject(g_hfNormal, sizeof(LOGFONT), &lf));
	lf.lfWeight = FW_BOLD;
	g_hfBold = require(CreateFontIndirect(&lf));

	/* Create child windows. */
	g_pDlv = new DataListView(g_hWnd);
	g_pElv = new EpisodeListView(g_hWnd);

	/* Get saved view settings. */
	char* sz;
	Pl("cfg","get_view_watched",&g_bViewWatched);
	Pl("cfg","get_view_tv_original",&g_bViewTVOriginal);
	if (Pl("cfg","get_limit_screenwriter",&sz))
		strcpy_s(g_szLimitScreenwriter, sizeof(g_szLimitScreenwriter), sz);
	return 0;
}

LRESULT CALLBACK WndProc(const HWND hWnd, const UINT uMsg, const WPARAM wParam, LPARAM lParam)
{
	switch (uMsg) {
	case WM_CREATE:
		UpdateTheme();
		SetWindowPos(hWnd, NULL, -1, -1, Dpi(510), Dpi(412), SWP_NOZORDER|SWP_NOMOVE|SWP_NOACTIVATE);
		SetFocus(g_pElv->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_szLimitScreenwriter[0]? MF_UNCHECKED: MF_CHECKED);
		break;
	case WM_CLOSE:
		DestroyWindow(hWnd);
		break;
	case WM_DESTROY:
		g_pElv->SaveFocus();
		PostQuitMessage(0);
		break;
	case WM_SIZE:
		SendMessage(g_hWndStatus, WM_SIZE, wParam, lParam);
		UpdateLayout(LOWORD(lParam), HIWORD(lParam));
		break;
	case WM_GETMINMAXINFO:
	    {
		MINMAXINFO* const pMMI = (MINMAXINFO*)lParam;
		pMMI->ptMinTrackSize.x = Dpi(220);
		pMMI->ptMinTrackSize.y = Dpi(220);
		break;
	    }
	case WM_THEMECHANGED:
		UpdateTheme();
		UpdateLayout();
		break;
	case 0x02E0: /* WM_DPICHANGED */
	    {
		const RECT* const lpr = (RECT*)lParam;
		g_iDPI = HIWORD(wParam);
		prefer(SetWindowPos(hWnd, (HWND)NULL,
		    lpr->left, lpr->top,
		    lpr->right-lpr->left,
		    lpr->bottom-lpr->top,
		    SWP_NOZORDER|SWP_NOACTIVATE));
		UpdateLayout(lpr->right-lpr->left, lpr->bottom-lpr->top);
		break;
	    }
	case WM_ACTIVATE:
		switch (wParam) {
		case WA_INACTIVE:
			g_hWndFocus = GetFocus();
			break;
		case WA_ACTIVE:
		case WA_CLICKACTIVE:
			SetFocus(g_hWndFocus);
			Pl("track_episodes","update_tracked_episodes");
			g_pElv->Redraw();
		}
		break;
	case WM_NOTIFY:
		switch (((NMHDR*)lParam)->idFrom) {
		case IDC_EPISODELISTVIEW:
			return g_pElv->HandleNotify(lParam);
		}
		break;
	case WM_TIMER:
		switch (wParam) {
		case IDR_TIMER:
		    {
			static int i = 0;

			/* Animate ellipsis in status bar while doing
			 * work in other thread. */
			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("")));
			} else {
				i = 0;
				g_bThread = 0;
				prefer(KillTimer(hWnd, IDR_TIMER));
				g_pElv->Update();
			}
			break;
		    }
		}
		break;
	case WM_COMMAND:
		switch (ID_GROUP((LOWORD(wParam)))) {
		case IDG_MENU:
			WndProcMainMenu(hWnd, LOWORD(wParam));
			break;
		case IDG_CTX:
			WndProcContextMenu(hWnd, LOWORD(wParam));
			break;
		}
		break;
	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.");
		case IDM_VIEW_WATCHED:
			TIP(g_bViewWatched?
			    TEXT("Click to hide watched episodes."):
			    TEXT("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."));
			break;
		case IDM_VIEW_OTHERS:
			TIP(g_szLimitScreenwriter?
			    TEXT("Click to hide episodes by other screenwriters."):
			    TEXT("Click to show episodes by other screenwriters."));
			break;
		default:
			TIP(TEXT(""));
			break;
#undef OF
#undef TIP
		}
		break;
	default:
		return DefWindowProc(hWnd, uMsg, wParam, lParam);
	}

	return 0;
}

/* Process main menu commands. */
void WndProcMainMenu(const HWND hWnd, unsigned short wCommand)
{
	switch (wCommand) {
	case IDM_FILE_EXIT:
		PostMessage(hWnd, WM_CLOSE, 0, 0);
		break;
	case IDM_FILE_REFRESH:
		g_pElv->Update();
		break;
	case IDM_FILE_FETCH_DATA:
		if (g_bThread) break;
		Pl("episode_data","thread_create","update_episode_data",&g_aThread);
		goto t;
	case IDM_FILE_FETCH_SCREENWRITERS:
		if (g_bThread) break;
		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("."));
		g_bThread = 1;
		break;
	case IDM_FILE_ABOUT:
		DialogBox(
		    GetModuleHandle(NULL),
		    MAKEINTRESOURCE(IDD_ABOUT),
		    hWnd,
		    AboutDlgProc
		);
		break;
	case IDM_VIEW_WATCHED:
		CheckMenuItem(GetMenu(hWnd), IDM_VIEW_WATCHED,
		    g_bViewWatched? MF_UNCHECKED: MF_CHECKED);
		g_bViewWatched = !g_bViewWatched;
		Pl("cfg","set_view_watched",g_bViewWatched);
		g_pElv->Update();
		g_pElv->EnsureFocusVisible();
		break;
	case IDM_VIEW_TV_ORIGINAL:
		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_pElv->Update();
		g_pElv->EnsureFocusVisible();
		break;
	case IDM_VIEW_OTHERS:	/* Show/hide other screenwriters. */
		if (g_szLimitScreenwriter[0]) {
			CheckMenuItem(GetMenu(hWnd), IDM_VIEW_OTHERS,
			    MF_CHECKED);
			g_szLimitScreenwriter[0] = 0;
		} else {
			const int iEpFocus = ListView_GetNextItem(g_pElv->hWnd, -1, LVNI_FOCUSED);
			if (iEpFocus == -1) break;

			LVITEM lvi;
			lvi.iItem = iEpFocus;
			lvi.mask = LVIF_PARAM;
			if (!ListView_GetItem(g_pElv->hWnd, &lvi)) break;

			char* sz;
			if (!Pl("episode_data","episode_datum",lvi.lParam,"Screenwriter",&sz))
				break;
			strcpy_s(g_szLimitScreenwriter,
			    sizeof(g_szLimitScreenwriter), sz);
			CheckMenuItem(GetMenu(hWnd), IDM_VIEW_OTHERS,
			    MF_UNCHECKED);
		}
		Pl("cfg","set_limit_screenwriter",g_szLimitScreenwriter);
		g_pElv->Update();
		g_pElv->EnsureFocusVisible();
		break;
	}
}

/* Process context menu commands. */
void WndProcContextMenu(const HWND, unsigned short wCommand)
{
	LVITEM lvi;
	int cNotFound = 0;

	/* Look through selected items, applying the
	 * selected command to each one. */

	lvi.mask = LVIF_PARAM;
	lvi.iItem = -1;
	while ((lvi.iItem = ListView_GetNextItem(g_pElv->hWnd, lvi.iItem, LVNI_SELECTED)) != -1
	    && ListView_GetItem(g_pElv->hWnd, &lvi)) {

		/* Process rate commands. */
		if (ID_SUBGROUP(wCommand) == IDG_CTX_RATE) {
			Pl("episode_data","rate_episode",lvi.lParam,ID_RATING(wCommand));
			g_pElv->UpdateItem(&lvi);
			continue;
		}

		/* Process other commands. */
		switch (wCommand) {
		case IDM_WATCH_LOCALLY:
			if (!Pl("local_episode","open_episode_locally",lvi.lParam))
				cNotFound++;
			break;
		case IDM_WATCH_ONLINE:
			Pl("local_episode","open_episode_online",lvi.lParam);
			break;
		case IDM_TOGGLE:
			Pl("track_episodes","toggle_episode",lvi.lParam);
			break;
		case IDM_FORGET:
			Pl("track_episodes","forget_episode",lvi.lParam);
			Pl("track_episodes","update_tracked_episodes");
			break;
		case IDM_LOOKUP:
			Pl("episode_data","retract_episode",lvi.lParam);
			g_pElv->UpdateItem(&lvi);
			g_pDlv->ShowEpisode(lvi.lParam);
			break;
		case IDM_WIKI:
			Pl("episode_data","open_episode_wiki",lvi.lParam);
			break;
		}
	}

	g_pElv->Redraw();
	if (cNotFound == 1) {
		EBMessageBox(TEXT("Episode could not be opened locally."),
		    TEXT("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);
	} else if (ID_SUBGROUP(wCommand) == IDG_CTX_RATE) {
		g_pElv->Sort();
		g_pElv->ShowFocus();
	}
}

/* Handle messages to Help > About dialog. */
INT_PTR CALLBACK AboutDlgProc(const HWND hWnd, const UINT uMsg, const WPARAM wParam, const LPARAM)
{
	switch (uMsg) {
	case WM_CLOSE:
		EndDialog(hWnd, IDOK);
		break;
	case WM_COMMAND:
		switch (LOWORD(wParam)) {
		case IDOK:
			EndDialog(hWnd, IDOK);
			break;
		}
		break;
	default:
		return FALSE;
	}

	return TRUE;
}

void UpdateLayout(int w, int h)
{
	if (!g_hWndStatus) return;

	RECT rc, rrStatus;
	if (w && h) rc = {0, 0, w, h};
	else require(GetClientRect(g_hWnd, &rc));
	require(GetRelativeRect(g_hWndStatus, &rrStatus));

	SendMessage(g_hWnd, WM_SETREDRAW, FALSE, 0);

	/* Resize list views. */
	const long pad = IsThemeActive()? Dpi(6): 0; /* Add padding in modern themes. */
	const long cyDlv = rrStatus.top-g_pDlv->Height()-pad;
	require(SetWindowRect(g_pDlv->hWnd, pad, cyDlv, rc.right-pad, rrStatus.top-pad));
	require(SetWindowRect(g_pElv->hWnd, pad, pad, rc.right-pad, cyDlv-pad));
	g_pDlv->ResizeColumns(rc.right-pad-pad);
	g_pElv->ResizeColumns(rc.right-pad-pad);

	/* 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_hWnd, WM_SETREDRAW, TRUE, 0);
	RedrawWindow(g_hWnd, NULL, NULL,
	    RDW_ERASE|RDW_FRAME|RDW_INVALIDATE|RDW_ALLCHILDREN);
}

/* Try to style application according to current Windows theme. */
void UpdateTheme()
{
	if (!g_bThemes) return;
	const BOOL bThemeActive = IsThemeActive();
	g_pDlv->UpdateTheme(bThemeActive);
	g_pElv->UpdateTheme(bThemeActive);
}