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
|
#include <windows.h>
#include <commctrl.h>
#include <stdio.h>
#include <string.h>
#include <SWI-Prolog.h>
#include "resource.h"
#include "defs.h"
HFONT g_GUIFont;
HFONT g_GUIFontBold;
static LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
static INT_PTR CALLBACK AboutDlgProc(HWND, UINT, WPARAM, LPARAM);
static int Attach(void);
static void SetupFonts();
int WINAPI
WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, INT nCmdShow)
{
char *rgArgs[2];
HWND hWnd;
MSG msg;
INITCOMMONCONTROLSEX icc;
//term_t t;
WNDCLASSEX wc;
/* Initialize Prolog. */
rgArgs[0] = "episode_browser";
rgArgs[1] = NULL;
if (!PL_initialise(1, rgArgs))
PL_halt(1);
//t = PL_new_term_refs(1);
//if (!PL_put_atom_chars(t+0, "false"))
// return 0;
//if (!PL_call_predicate(NULL, PL_Q_NORMAL,
// PL_predicate("set_prolog_gc_thread", 1, "user"),
// t))
// return 0;
Attach();
/* Create window. */
icc.dwSize = sizeof(icc);
icc.dwICC = ICC_WIN95_CLASSES;
InitCommonControlsEx(&icc);
SetupFonts();
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = 0;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wc.lpszMenuName = MAKEINTRESOURCE(IDR_MENU);
wc.lpszClassName = TEXT("Episode Browser");
wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
RegisterClassEx(&wc);
hWnd = CreateWindowEx(
0,
TEXT("Episode Browser"),
TEXT("Episode Browser"),
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, /* Position */
510, 300, /* Size */
NULL, /* Parent window */
NULL, /* Menu */
hInstance,
NULL
);
if (!hWnd)
return 0;
ShowWindow(hWnd, nCmdShow);
while (GetMessage(&msg, NULL, 0, 0) > 0) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
LRESULT CALLBACK
WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg) {
case WM_CLOSE:
DestroyWindow(hWnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
case WM_COMMAND:
switch (LOWORD(wParam)) {
case ID_FILE_EXIT:
PostMessage(hWnd, WM_CLOSE, 0, 0);
break;
case ID_FILE_REFRESH:
ElvUpdate();
break;
case ID_FILE_ABOUT:
DialogBox(
GetModuleHandle(NULL),
MAKEINTRESOURCE(IDD_ABOUT),
hWnd,
AboutDlgProc
);
break;
}
break;
case WM_CREATE:
ElvCreate(hWnd);
DlvCreate(hWnd);
break;
case WM_SIZE:
UpdateLayout(hWnd);
break;
case WM_NOTIFY:
switch (((NMHDR *)lParam)->idFrom) {
case IDC_EPISODELISTVIEW:
return ElvHandleNotify(lParam);
}
break;
default:
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
return 0;
}
INT_PTR CALLBACK
AboutDlgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg) {
case WM_INITDIALOG:
return TRUE;
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;
}
/***/
/* Attach persistent databases. */
int
Attach()
{
int r;
term_t t;
t = PL_new_term_refs(2);
r = PL_call_predicate(NULL, PL_Q_NORMAL,
PL_predicate("attach", 0, "track_episodes"),
t);
if (!r) return r;
r = PL_call_predicate(NULL, PL_Q_NORMAL,
PL_predicate("attach", 0, "episode_data"),
t);
if (!r) return r;
return 1;
}
void
SetupFonts()
{
HMODULE hModule;
LOGFONT lf;
hModule = LoadLibrary(TEXT("User32.dll"));
if (hModule && GetProcAddress(hModule, "SystemParametersInfoW")) {
NONCLIENTMETRICS m;
m.cbSize = sizeof(NONCLIENTMETRICS);
SystemParametersInfo(SPI_GETNONCLIENTMETRICS,
sizeof(NONCLIENTMETRICS), &m, 0);
g_GUIFont = CreateFontIndirect(&m.lfMessageFont);
} else {
g_GUIFont = GetStockObject(DEFAULT_GUI_FONT);
}
GetObject(g_GUIFont, sizeof(LOGFONT), &lf);
lf.lfWeight = FW_BOLD;
g_GUIFontBold = CreateFontIndirect(&lf);
}
/***/
void
UpdateLayout(HWND hWnd)
{
HWND hElv, hDlv;
int cxColumn, cyDlv;
RECT rc;
static int cxVScroll = 0;
extern int g_SelectedItem;
if (cxVScroll == 0)
cxVScroll = GetSystemMetrics(SM_CXVSCROLL);
GetClientRect(hWnd, &rc);
#define EDGE 4
/* Resize data list view. */
hDlv = GetDlgItem(hWnd, IDC_DATALISTVIEW);
cyDlv = rc.bottom-100;
MoveWindow(hDlv, 0, cyDlv,
rc.right, rc.bottom,
TRUE);
cxColumn = ListView_GetColumnWidth(hDlv, 0);
ListView_SetColumnWidth(hDlv, 1,
rc.right-cxColumn-cxVScroll-EDGE);
/* Resize episode list view. */
hElv = GetDlgItem(hWnd, IDC_EPISODELISTVIEW);
MoveWindow(hElv, 0, 0,
rc.right, cyDlv+1,
TRUE);
cxColumn = ListView_GetColumnWidth(hElv, 0);
ListView_SetColumnWidth(hElv, 1,
rc.right-cxColumn-cxVScroll-EDGE);
ListView_EnsureVisible(hElv, g_SelectedItem, TRUE);
}
|