From 9d133477d51dd0271d63520071cdf7a11e71c605 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Mon, 4 Apr 2022 21:46:19 +0200 Subject: Use file-local instead of function-local static variables. This pollutes the global scope, but it removes the unnecessary check that is otherwise done every time the function is called. --- c/main.c | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) (limited to 'c/main.c') diff --git a/c/main.c b/c/main.c index 2c69d70..b40bb83 100644 --- a/c/main.c +++ b/c/main.c @@ -12,6 +12,8 @@ HMENU HPopupMenu; HWND HFocus; HWND HWnd; int IDPI = -1; +static int BThemes; +static int CxVScroll; static LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); static INT_PTR CALLBACK AboutDlgProc(HWND, UINT, WPARAM, LPARAM); static int Attach(void); @@ -23,14 +25,20 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, INT nCmdShow) { char *argv[2]; + HMODULE hModule; HWND hWnd; LPTSTR tszErr; MSG msg; INITCOMMONCONTROLSEX icc; WNDCLASSEX wc; - /* Initialize Prolog. */ + /* Set constant globals. */ + hModule = LoadLibrary(TEXT("uxtheme.dll")); + BThemes = hModule && GetProcAddress(hModule,"SetWindowTheme"); + if (hModule) FreeLibrary(hModule); + CxVScroll = GetSystemMetrics(SM_CXVSCROLL); + /* Initialize Prolog. */ argv[0] = "EpisodeBrowser"; argv[1] = NULL; tszErr = TEXT("Could not initialize Prolog."); @@ -39,7 +47,6 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, if (!Attach()) goto f; /* Initialize common controls, load menu and register window class. */ - icc.dwSize = sizeof(icc); icc.dwICC = ICC_WIN95_CLASSES; tszErr = TEXT("Could not initialize common controls."); @@ -62,7 +69,6 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, if (!RegisterClassEx(&wc)) goto f; /* Create window. */ - hWnd = CreateWindowEx( 0, TEXT("Episode Browser"), @@ -305,17 +311,14 @@ UpdateLayout() int cxColumn, cyDlv; RECT rc; extern HWND HDlv, HElv; - static int cxVScroll = 0; GetClientRect(HWnd, &rc); - if (!cxVScroll) - cxVScroll = GetSystemMetrics(SM_CXVSCROLL); #define SETCOLW(lv) \ ListView_SetColumnWidth(lv, 0, LVSCW_AUTOSIZE); \ cxColumn = ListView_GetColumnWidth(lv, 0)+4; \ ListView_SetColumnWidth(lv, 0, cxColumn); \ - ListView_SetColumnWidth(lv, 1, rc.right-cxColumn-cxVScroll-4); + ListView_SetColumnWidth(lv, 1, rc.right-cxColumn-CxVScroll-4); /* Resize data list view. */ SendMessage(HDlv, WM_SETREDRAW, FALSE, 0); @@ -341,16 +344,8 @@ UpdateTheme() LPTSTR tszTheme; WORD wAction; extern HWND HElv, HDlv; - static int bThemes = -1; - - if (bThemes == -1) { - HMODULE hModule; - hModule = LoadLibrary(TEXT("uxtheme.dll")); - bThemes = hModule && GetProcAddress(hModule,"SetWindowTheme"); - if (hModule) FreeLibrary(hModule); - } - if (!bThemes) return; + if (!BThemes) return; if (IsThemeActive()) { dwStyle = LVS_EX_DOUBLEBUFFER; tszTheme = TEXT("Explorer"); -- cgit v1.2.3