From 196aeb5a981e184c9eb48a8215639252812f2608 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Fri, 25 Feb 2022 15:58:00 +0100 Subject: Small improvements. --- c/main.c | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) (limited to 'c/main.c') 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. */ -- cgit v1.2.3