From ae25d8012939de481633fa3572e7cd598d8a5a5f Mon Sep 17 00:00:00 2001 From: Jonas Kümmerlin Date: Wed, 1 May 2019 16:27:25 +0200 Subject: redo compat function architecture way less code at the expense of explicit initialization --- alf/alfcompat.h | 85 +++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 58 insertions(+), 27 deletions(-) (limited to 'alf/alfcompat.h') diff --git a/alf/alfcompat.h b/alf/alfcompat.h index 0d5a7d4..6926de5 100644 --- a/alf/alfcompat.h +++ b/alf/alfcompat.h @@ -8,39 +8,51 @@ #define WM_DPICHANGED 0x02E0 #endif +#ifdef __cplusplus extern "C" IMAGE_DOS_HEADER __ImageBase; +#else +extern IMAGE_DOS_HEADER __ImageBase; +#endif #define ALF_HINSTANCE ((HINSTANCE)&__ImageBase) typedef LRESULT (CALLBACK *ALF_COMPAT_SUBCLASSPROC)(HWND,UINT,WPARAM,LPARAM,UINT_PTR,DWORD_PTR); typedef struct { - UINT cbSize; - int iBorderWidth; - int iScrollWidth; - int iScrollHeight; - int iCaptionWidth; - int iCaptionHeight; - LOGFONT lfCaptionFont; - int iSmCaptionWidth; - int iSmCaptionHeight; - LOGFONT lfSmCaptionFont; - int iMenuWidth; - int iMenuHeight; - LOGFONT lfMenuFont; - LOGFONT lfStatusFont; - LOGFONT lfMessageFont; - int iPaddedBorderWidth; // new in Vista -} ALF_NONCLIENTMETRICS_VISTA; - -static inline SIZE_T -ALF_SizeOf_NONCLIENTMETRICS(void) -{ - if (LOBYTE(LOWORD(GetVersion())) >= 6) { - return sizeof(ALF_NONCLIENTMETRICS_VISTA); - } else { - return sizeof(ALF_NONCLIENTMETRICS_VISTA) - sizeof(int); - } -} + UINT cbSize; + int iBorderWidth; + int iScrollWidth; + int iScrollHeight; + int iCaptionWidth; + int iCaptionHeight; + LOGFONTW lfCaptionFont; + int iSmCaptionWidth; + int iSmCaptionHeight; + LOGFONTW lfSmCaptionFont; + int iMenuWidth; + int iMenuHeight; + LOGFONTW lfMenuFont; + LOGFONTW lfStatusFont; + LOGFONTW lfMessageFont; + int iPaddedBorderWidth; // new in Vista +} ALF_NONCLIENTMETRICSW_VISTA; +typedef struct { + UINT cbSize; + int iBorderWidth; + int iScrollWidth; + int iScrollHeight; + int iCaptionWidth; + int iCaptionHeight; + LOGFONTA lfCaptionFont; + int iSmCaptionWidth; + int iSmCaptionHeight; + LOGFONTA lfSmCaptionFont; + int iMenuWidth; + int iMenuHeight; + LOGFONTA lfMenuFont; + LOGFONTA lfStatusFont; + LOGFONTA lfMessageFont; + int iPaddedBorderWidth; // new in Vista +} ALF_NONCLIENTMETRICSA_VISTA; long ALF_GetAveCharWidth(HDC hdc); @@ -75,6 +87,25 @@ typedef struct { #define TMT_TRANSITIONDURATION 6000 #endif +void ALF_LoadCompatFunctions(void); +void ALF_UnloadCompatFunctions(void); + +inline static void +ALF_Compat_LogFontWtoA(const LOGFONTW *w, LOGFONTA *a) +{ + CopyMemory(a, w, sizeof(LOGFONTA) - LF_FACESIZE); + WideCharToMultiByte(CP_ACP, 0, w->lfFaceName, -1, a->lfFaceName, LF_FACESIZE, NULL, NULL); + a->lfFaceName[LF_FACESIZE - 1] = '\0'; +} + +inline static void +ALF_Compat_LogFontAtoW(const LOGFONTA *a, LOGFONTW *w) +{ + CopyMemory(w, a, sizeof(LOGFONTA) - LF_FACESIZE); + MultiByteToWideChar(CP_ACP, 0, a->lfFaceName, -1, w->lfFaceName, LF_FACESIZE); + w->lfFaceName[LF_FACESIZE - 1] = 0; +} + extern BOOL (WINAPI *ALF_Compat_IsAppThemed)(void); extern UINT (WINAPI *ALF_Compat_GetDpiForWindow)(HWND); extern BOOL (WINAPI *ALF_Compat_AdjustWindowRectExForDpi)(LPRECT,DWORD,BOOL,DWORD,UINT); -- cgit v1.2.3