diff --git a/include/wx/msw/private/darkmode.h b/include/wx/msw/private/darkmode.h index 1d742ac924..2ef0d1b3fd 100644 --- a/include/wx/msw/private/darkmode.h +++ b/include/wx/msw/private/darkmode.h @@ -44,7 +44,7 @@ HBRUSH GetBackgroundBrush(); // This can only be called from WM_PAINT handler for a native control and // assumes that this control handles WPARAM argument of WM_PAINT as HDC to // paint on. -bool PaintIfNecessary(wxWindow* w); +bool PaintIfNecessary(HWND hwnd, WXWNDPROC defWndProc); // If dark mode is active and if the message is one of those used for menu // drawing, process it and return true, otherwise just return false without diff --git a/src/msw/darkmode.cpp b/src/msw/darkmode.cpp index 51b13a7e83..dc0b6c5538 100644 --- a/src/msw/darkmode.cpp +++ b/src/msw/darkmode.cpp @@ -347,13 +347,14 @@ HBRUSH GetBackgroundBrush() return brush ? GetHbrushOf(*brush) : 0; } -bool PaintIfNecessary(wxWindow* w) +bool PaintIfNecessary(HWND hwnd, WXWNDPROC defWndProc) { #if wxUSE_IMAGE if ( !wxMSWImpl::ShouldUseDarkMode() ) return false; - const wxSize size = w->GetClientSize(); + const RECT rc = wxGetClientRect(hwnd); + const wxSize size{rc.right - rc.left, rc.bottom - rc.top}; // Don't bother doing anything with the empty windows. if ( size == wxSize() ) @@ -363,7 +364,12 @@ bool PaintIfNecessary(wxWindow* w) wxBitmap bmp(size); { wxMemoryDC mdc(bmp); - w->MSWDefWindowProc(WM_PAINT, (WPARAM)GetHdcOf(mdc), 0); + + WPARAM wparam = (WPARAM)GetHdcOf(mdc); + if ( defWndProc ) + ::CallWindowProc(defWndProc, hwnd, WM_PAINT, wparam, 0); + else + ::DefWindowProc(hwnd, WM_PAINT, wparam, 0); } wxImage image = bmp.ConvertToImage(); @@ -386,13 +392,14 @@ bool PaintIfNecessary(wxWindow* w) } PAINTSTRUCT ps; - wxDCTemp dc(::BeginPaint(GetHwndOf(w), &ps), size); + wxDCTemp dc(::BeginPaint(hwnd, &ps), size); dc.DrawBitmap(wxBitmap(image), 0, 0); - ::EndPaint(GetHwndOf(w), &ps); + ::EndPaint(hwnd, &ps); return true; #else // !wxUSE_IMAGE - wxUnusedVar(w); + wxUnusedVar(hwnd); + wxUnusedVar(defWndProc); return false; #endif @@ -636,7 +643,7 @@ HBRUSH GetBackgroundBrush() return 0; } -bool PaintIfNecessary(wxWindow* WXUNUSED(w)) +bool PaintIfNecessary(HWND WXUNUSED(hwnd), WXWNDPROC WXUNUSED(defWndProc)) { return false; } diff --git a/src/msw/window.cpp b/src/msw/window.cpp index 59d9fc696d..1ef6f514c5 100644 --- a/src/msw/window.cpp +++ b/src/msw/window.cpp @@ -3135,7 +3135,7 @@ wxWindowMSW::MSWHandleMessage(WXLRESULT *result, else // no DC given { if ( MSWShouldUseAutoDarkMode() && - wxMSWDarkMode::PaintIfNecessary(this) ) + wxMSWDarkMode::PaintIfNecessary(GetHwnd(), m_oldWndProc) ) processed = true; else processed = HandlePaint();