From ffc7c036f1287cad6386861db67281c8fee276bd Mon Sep 17 00:00:00 2001 From: Artur Wieczorek Date: Thu, 24 Jun 2021 19:22:56 +0200 Subject: [PATCH] Fix acquiring HDC from wxGCDC with non-GDI+ graphics context HDC can be acquired/released only when wxGCDC is associated with GDI+ graphics context. Closes #19207. --- interface/wx/renderer.h | 3 +++ src/msw/graphics.cpp | 17 ++++------------- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/interface/wx/renderer.h b/interface/wx/renderer.h index 3604754630..195a2df8bb 100644 --- a/interface/wx/renderer.h +++ b/interface/wx/renderer.h @@ -306,6 +306,9 @@ public: it changes them, so it is safe to assume that the same pen, brush and colours that were active before the call to this function are still in effect after it. + @note Under wxMSW drawing on wxGCDC is possible only if it's associated with + GDI+ wxGraphicsContext. + @library{wxcore} @category{gdi} */ diff --git a/src/msw/graphics.cpp b/src/msw/graphics.cpp index de04226eea..d9ee3f4811 100644 --- a/src/msw/graphics.cpp +++ b/src/msw/graphics.cpp @@ -3013,13 +3013,9 @@ WXHDC wxGCDC::AcquireHDC() if ( !gc ) return NULL; -#if wxUSE_CAIRO // we can't get the HDC if it is not a GDI+ context - wxGraphicsRenderer* r1 = gc->GetRenderer(); - wxGraphicsRenderer* r2 = wxGraphicsRenderer::GetCairoRenderer(); - if (r1 == r2) - return NULL; -#endif + wxCHECK_MSG(gc->GetRenderer() == wxGraphicsRenderer::GetGDIPlusRenderer(), NULL, + "can't get HDC because this is not GDI+ context"); Graphics * const g = static_cast(gc->GetNativeContext()); return g ? g->GetHDC() : NULL; @@ -3033,13 +3029,8 @@ void wxGCDC::ReleaseHDC(WXHDC hdc) wxGraphicsContext * const gc = GetGraphicsContext(); wxCHECK_RET( gc, "can't release HDC because there is no wxGraphicsContext" ); -#if wxUSE_CAIRO - // we can't get the HDC if it is not a GDI+ context - wxGraphicsRenderer* r1 = gc->GetRenderer(); - wxGraphicsRenderer* r2 = wxGraphicsRenderer::GetCairoRenderer(); - if (r1 == r2) - return; -#endif + wxCHECK_RET(gc->GetRenderer() == wxGraphicsRenderer::GetGDIPlusRenderer(), + "can't release HDC because this is not GDI+ context"); Graphics * const g = static_cast(gc->GetNativeContext()); wxCHECK_RET( g, "can't release HDC because there is no Graphics" );