aboutsummaryrefslogtreecommitdiff
path: root/c/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'c/main.c')
-rw-r--r--c/main.c31
1 files changed, 18 insertions, 13 deletions
diff --git a/c/main.c b/c/main.c
index 95026a1..c3e1be1 100644
--- a/c/main.c
+++ b/c/main.c
@@ -20,6 +20,7 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
{
char *rgArgs[2];
HWND hWnd;
+ LPTSTR tszErr;
MSG msg;
INITCOMMONCONTROLSEX icc;
WNDCLASSEX wc;
@@ -28,25 +29,25 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
rgArgs[0] = "episode_browser";
rgArgs[1] = NULL;
- if (!PL_initialise(1, rgArgs))
- PL_halt(1);
- Attach();
+ tszErr = TEXT("Could not initialize Prolog.");
+ if (!PL_initialise(1, rgArgs)) goto f;
+ tszErr = TEXT("Could not attach databases.");
+ if (!Attach()) goto f;
/* Initialize window. */
icc.dwSize = sizeof(icc);
icc.dwICC = ICC_WIN95_CLASSES;
- InitCommonControlsEx(&icc);
+ tszErr = TEXT("Could not initialize common controls.");
+ if (!InitCommonControlsEx(&icc)) goto f;
HPopupMenu = LoadMenu(NULL,
MAKEINTRESOURCE(IDR_POPUPMENU));
HPopupMenu = GetSubMenu(HPopupMenu, 0);
+ memset(&wc, 0, sizeof(WNDCLASSEX));
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);
@@ -54,7 +55,8 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
wc.lpszMenuName = MAKEINTRESOURCE(IDR_MENU);
wc.lpszClassName = TEXT("Episode Browser");
wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
- RegisterClassEx(&wc);
+ tszErr = TEXT("Could not register window class.");
+ if (!RegisterClassEx(&wc)) goto f;
hWnd = CreateWindowEx(
0,
@@ -64,7 +66,8 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
CW_USEDEFAULT, CW_USEDEFAULT, 510, 400,
NULL, NULL, hInstance, NULL
);
- if (!hWnd) return 0;
+ tszErr = TEXT("Could not create main window.");
+ if (!hWnd) goto f;
SetupFonts();
ShowWindow(hWnd, nCmdShow);
@@ -74,7 +77,11 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
DispatchMessage(&msg);
}
+ PL_halt(0);
return 0;
+f: MessageBox(NULL, tszErr, TEXT("Error"), MB_ICONERROR);
+ PL_halt(1);
+ return 1;
}
LRESULT CALLBACK
@@ -227,7 +234,6 @@ SetupFonts()
hModule = LoadLibrary(TEXT("User32.dll"));
if (hModule && GetProcAddress(hModule, "SystemParametersInfoW")) {
NONCLIENTMETRICS m;
-
m.cbSize = sizeof(NONCLIENTMETRICS);
SystemParametersInfo(SPI_GETNONCLIENTMETRICS,
sizeof(NONCLIENTMETRICS), &m, 0);
@@ -252,10 +258,9 @@ UpdateLayout()
RECT rc;
static int cxVScroll = 0;
- if (cxVScroll == 0)
- cxVScroll = GetSystemMetrics(SM_CXVSCROLL);
-
GetClientRect(HWnd, &rc);
+ if (!cxVScroll)
+ cxVScroll = GetSystemMetrics(SM_CXVSCROLL);
/* Resize data list view. */