From 02ffd45d5cb15b7d025b9a72a21ec1fd32de8c6f Mon Sep 17 00:00:00 2001 From: Jonas Kümmerlin Date: Tue, 14 Apr 2020 17:48:45 +0200 Subject: replace GetVersion() calls with helper functions --- alf/alfbutton.cpp | 12 +++++------- alf/alfcombobox.cpp | 6 +++--- alf/alfcompat.cpp | 8 ++++---- alf/alfcompat.h | 10 ++++++++++ alf/alfedit.cpp | 2 +- alf/alflabel.cpp | 4 ++-- 6 files changed, 25 insertions(+), 17 deletions(-) diff --git a/alf/alfbutton.cpp b/alf/alfbutton.cpp index ce87f15..0bb0627 100644 --- a/alf/alfbutton.cpp +++ b/alf/alfbutton.cpp @@ -92,7 +92,6 @@ static void ALF__Button_Render95(HWND hwnd, ALFButtonPriv *priv, LPDRAWITEMSTRUCT dis) { RECT r = dis->rcItem; - DWORD v = GetVersion(); int textlen = GetWindowTextLength(hwnd); TCHAR *textbuf = ALF_New(TCHAR, textlen + 1); @@ -142,7 +141,7 @@ ALF__Button_Render95(HWND hwnd, ALFButtonPriv *priv, LPDRAWITEMSTRUCT dis) style |= DT_HIDEPREFIX; if (dis->itemState & ODS_DISABLED) { - if (v >= 0x80000000) { + if (ALF_Compat_IsWin9x()) { // Win9x just uses gray text. DSS_DISABLED is broken there, too, // so we can't get the NT look even if we wanted to COLORREF oldTextColor = SetTextColor(dis->hDC, GetSysColor(COLOR_GRAYTEXT)); @@ -322,7 +321,6 @@ ALF__ButtonSubclassProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT ReleaseDC(hwnd, hdc); } else if (uMsg == 0x2000 + WM_DRAWITEM) { LPDRAWITEMSTRUCT dis = (DRAWITEMSTRUCT *)lParam; - DWORD v = GetVersion(); if (!ALF_Compat_BufferedPaintRenderAnimation(hwnd, dis->hDC)) { if (priv->hTheme) { @@ -420,12 +418,12 @@ ALF__ButtonSubclassProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT } else { ALF__Button_RenderUxtheme(hwnd, priv, stateid, dis->itemState, dis->hDC, &dis->rcItem); } - } else if (LOBYTE(LOWORD(v)) < 4) { - // Draw pre-95 style button - ALF__Button_Render3x(hwnd, priv, dis); - } else { + } else if (ALF_Compat_IsMinWindowsVersion(4, 0)) { // Draw 95 style button ALF__Button_Render95(hwnd, priv, dis); + } else { + // Draw pre-95 style button + ALF__Button_Render3x(hwnd, priv, dis); } } diff --git a/alf/alfcombobox.cpp b/alf/alfcombobox.cpp index bf64cb9..c9da2ed 100644 --- a/alf/alfcombobox.cpp +++ b/alf/alfcombobox.cpp @@ -36,7 +36,7 @@ ALF__ComboItemHeight(HWND hwnd) SelectFont(hDc, oldfont); } - if (LOBYTE(LOWORD(GetVersion())) < 4) { + if (!ALF_Compat_IsMinWindowsVersion(4, 0)) { // baseline alignment for NT3.x/Win32s // ideally, this would only be applied for the ODS_COMOBOXEDIT state, // but that state is not sent pre-Win95. @@ -187,7 +187,7 @@ ALF__ComboWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) LONG y = lpdis->rcItem.top; LONG x = lpdis->rcItem.left; - if (LOBYTE(LOWORD(GetVersion())) < 4) { + if (!ALF_Compat_IsMinWindowsVersion(4, 0)) { // baseline alignment for NT3.x/Win32s // ideally, this would only be applied for the ODS_COMOBOXEDIT state, // but that state is not sent pre-Win95. @@ -242,7 +242,7 @@ ALF__ComboWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) SendMessage(hwndChild, CB_SETEDITSEL, 0, (LPARAM)sel); DWORD heightOffset = 0; - if (LOBYTE(LOWORD(GetVersion())) >= 4) { + if (ALF_Compat_IsMinWindowsVersion(4, 0)) { heightOffset = - 2*ALF_Compat_GetSystemMetricsForDpi( SM_CYEDGE, ALF_CentipointsToPixels(GetParent(hwnd), 7200)) - 2; diff --git a/alf/alfcompat.cpp b/alf/alfcompat.cpp index 8672bb8..5fa3be7 100644 --- a/alf/alfcompat.cpp +++ b/alf/alfcompat.cpp @@ -32,7 +32,7 @@ static int WINAPI ALF_Compat_fallbackGetSystemMetricsForDpi(int nIndex, UINT dpi) { (void)dpi; - if (LOBYTE(LOWORD(GetVersion())) < 4) { + if (!ALF_Compat_IsMinWindowsVersion(4, 0)) { // old NT does not support several properties, so we fake them switch (nIndex) { case SM_CXEDGE: @@ -84,7 +84,7 @@ ALF_Compat_fallbackSystemParametersInfoForDpi(UINT uiAction, UINT uiParam, PVOID // we need to provide a fallback even on ANSI systems #ifdef UNICODE SIZE_T s = sizeof(*ncmw); - if (LOBYTE(LOWORD(GetVersion())) < 6) { + if (!ALF_Compat_IsMinWindowsVersion(6, 0)) { // pre-vista OS doesn't contain last member s -= sizeof(ncmw->iPaddedBorderWidth); ncmw->iPaddedBorderWidth = 0; @@ -97,7 +97,7 @@ ALF_Compat_fallbackSystemParametersInfoForDpi(UINT uiAction, UINT uiParam, PVOID ZeroMemory(&ncma, sizeof(ncma)); SIZE_T s = sizeof(ncma); - if (LOBYTE(LOWORD(GetVersion())) < 6) { + if (!ALF_Compat_IsMinWindowsVersion(6, 0)) { // pre-vista OS doesn't contain last member s -= sizeof(ncma.iPaddedBorderWidth); ncma.iPaddedBorderWidth = 0; @@ -429,7 +429,7 @@ static HMODULE _alf_dll_comctl32 = NULL; void ALF_LoadCompatFunctions(void) { - if (GetVersion() < 0x80000000) // don't attempt to load uxtheme.dll on non-NT platforms (ugly error on Win32s) + if (ALF_Compat_IsWinNT()) // don't attempt to load uxtheme.dll on non-NT platforms (ugly error on Win32s) _alf_dll_uxtheme = LoadLibraryA("uxtheme.dll"); _alf_dll_user32 = LoadLibraryA("user32.dll"); diff --git a/alf/alfcompat.h b/alf/alfcompat.h index 3996309..0c542b0 100644 --- a/alf/alfcompat.h +++ b/alf/alfcompat.h @@ -24,6 +24,16 @@ static inline BOOL ALF_Compat_IsMinWindowsVersion(DWORD major, DWORD minor) return vMajor > major || (vMajor == major && vMinor >= minor); } +static inline BOOL ALF_Compat_IsWin9x(void) +{ + return GetVersion() >= 0x80000000; +} + +static inline BOOL ALF_Compat_IsWinNT(void) +{ + return GetVersion() < 0x80000000; +} + typedef LRESULT (CALLBACK *ALF_COMPAT_SUBCLASSPROC)(HWND,UINT,WPARAM,LPARAM,UINT_PTR,DWORD_PTR); typedef struct { diff --git a/alf/alfedit.cpp b/alf/alfedit.cpp index be06b01..95150ba 100644 --- a/alf/alfedit.cpp +++ b/alf/alfedit.cpp @@ -55,7 +55,7 @@ ALF_AddEdit(HWND win, WORD id, UINT x, UINT y, const TCHAR *text) DWORD exstyle; DWORD style; - if (LOBYTE(LOWORD(GetVersion())) >= 4) { + if (ALF_Compat_IsMinWindowsVersion(4, 0)) { exstyle = WS_EX_CLIENTEDGE; style = 0; } else { diff --git a/alf/alflabel.cpp b/alf/alflabel.cpp index c38ab08..5292a13 100644 --- a/alf/alflabel.cpp +++ b/alf/alflabel.cpp @@ -16,7 +16,7 @@ ALF__LabelTopPadding(HWND hwnd) // see also: alfedit.cpp return ALF_Compat_GetSystemMetricsForDpi( SM_CYEDGE, ALF_CentipointsToPixels(GetParent(hwnd), 7200)) - + ((LOBYTE(LOWORD(GetVersion())) < 4) ? 2 : 1) /* internal padding in edit control */; + + (!ALF_Compat_IsMinWindowsVersion(4, 0) ? 2 : 1) /* internal padding in edit control */; } static int @@ -136,7 +136,7 @@ ALF__LabelWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) SetTextColor(hdc, GetSysColor(COLOR_BTNSHADOW)); DrawText(hdc, text, -1, &rc, format); - } else if (GetVersion() >= 0x80000000) { + } else if (ALF_Compat_IsWin9x()) { // Win9x just uses gray text. DSS_DISABLED is broken there, too, // so we can't get the NT look even if we wanted to SetTextColor(hdc, GetSysColor(COLOR_GRAYTEXT)); -- cgit v1.2.3