From 699bef1316f9b44572489537a1c869e9dbbd0268 Mon Sep 17 00:00:00 2001 From: Ritchie Swann Date: Sun, 11 Aug 2024 10:33:10 +0100 Subject: [PATCH] Better solution for DwmDefWindowProc on mingw64 On mingw, create our own thunk for DwmDefWindowProc. It should exist in libdwmapi.a (and exists in MSVC), but doesn't. --- libraries/ZWidget/CMakeLists.txt | 3 +++ .../ZWidget/src/window/win32/win32window.cpp | 25 ++++++++++++++++--- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/libraries/ZWidget/CMakeLists.txt b/libraries/ZWidget/CMakeLists.txt index dd836cd6de..68c048e22e 100644 --- a/libraries/ZWidget/CMakeLists.txt +++ b/libraries/ZWidget/CMakeLists.txt @@ -120,6 +120,9 @@ include_directories(include include/zwidget src) if(WIN32) set(ZWIDGET_SOURCES ${ZWIDGET_SOURCES} ${ZWIDGET_WIN32_SOURCES}) add_definitions(-DUNICODE -D_UNICODE) + if(MINGW) + add_definitions(-DMINGW) + endif() elseif(APPLE) set(ZWIDGET_SOURCES ${ZWIDGET_SOURCES} ${ZWIDGET_COCOA_SOURCES}) set(ZWIDGET_LIBS ${CMAKE_DL_LIBS} -ldl) diff --git a/libraries/ZWidget/src/window/win32/win32window.cpp b/libraries/ZWidget/src/window/win32/win32window.cpp index 54350513d6..958c3fef60 100644 --- a/libraries/ZWidget/src/window/win32/win32window.cpp +++ b/libraries/ZWidget/src/window/win32/win32window.cpp @@ -29,6 +29,26 @@ #define RIDEV_INPUTSINK (0x100) #endif +#ifdef MINGW +// MinGW's library doesn't contain a thunk for DwmDefWindowProc, so we need to create our own + +BOOL DwmDefWindowProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, LRESULT *plResult ) +{ + typedef LRESULT(* dwmdwp)(HWND, UINT, WPARAM, LPARAM ); + BOOL result(false); + HMODULE module = LoadLibrary( _T( "dwmapi.dll" ) ); + if( module ) { + dwmdwp proc = reinterpret_cast( GetProcAddress( module, "DwmDefWindowProc" ) ); + if( proc ) { + *plResult = proc( hWnd, msg, wParam, lParam ); + } + FreeLibrary(module); + } + return result; +} + +#endif + static std::string from_utf16(const std::wstring& str) { if (str.empty()) return {}; @@ -389,9 +409,8 @@ LRESULT Win32Window::OnWindowMessage(UINT msg, WPARAM wparam, LPARAM lparam) { LPARAM result = 0; - // DwmDefWindowProc is not a publicly defined symbol on Windows 11 - /*if (DwmDefWindowProc(WindowHandle, msg, wparam, lparam, &result)) - return result;*/ + if (DwmDefWindowProc(WindowHandle, msg, wparam, lparam, &result)) + return result; if (msg == WM_INPUT) {