From 0c030f8d5750c5f6248c86b74a7011d8285a0146 Mon Sep 17 00:00:00 2001 From: narzoul Date: Mon, 28 Mar 2016 17:14:47 +0200 Subject: [PATCH] Eliminated flickering in popup menus DC redirection for popup menus is suppressed unless requested from WM_PAINT. --- DDrawCompat/CompatGdiDc.cpp | 17 +++++++++++------ DDrawCompat/CompatGdiDc.h | 2 +- DDrawCompat/CompatGdiPaintHandlers.cpp | 3 ++- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/DDrawCompat/CompatGdiDc.cpp b/DDrawCompat/CompatGdiDc.cpp index c3217eb..6011286 100644 --- a/DDrawCompat/CompatGdiDc.cpp +++ b/DDrawCompat/CompatGdiDc.cpp @@ -5,6 +5,7 @@ #include "CompatGdiDc.h" #include "CompatGdiDcCache.h" #include "DDrawLog.h" +#include "Hook.h" namespace { @@ -126,11 +127,8 @@ namespace } } - void setClippingRegion(HDC compatDc, HDC origDc, const POINT& origin) + void setClippingRegion(HDC compatDc, HDC origDc, HWND hwnd, bool isMenuWindow, const POINT& origin) { - const HWND hwnd = WindowFromDC(origDc); - const bool isMenuWindow = hwnd && 0x8000 == GetClassLongPtr(hwnd, GCW_ATOM); - if (isMenuWindow) { RECT windowRect = {}; @@ -165,7 +163,7 @@ namespace namespace CompatGdiDc { - HDC getDc(HDC origDc) + HDC getDc(HDC origDc, bool isMenuPaintDc) { if (!origDc || OBJ_DC != GetObjectType(origDc) || DT_RASDISPLAY != GetDeviceCaps(origDc, TECHNOLOGY)) { @@ -181,6 +179,13 @@ namespace CompatGdiDc return it->second.dc; } + const HWND hwnd = CALL_ORIG_FUNC(WindowFromDC)(origDc); + const bool isMenuWindow = hwnd && 0x8000 == GetClassLongPtr(hwnd, GCW_ATOM); + if (isMenuWindow && !isMenuPaintDc) + { + return nullptr; + } + CompatDc compatDc(CompatGdiDcCache::getDc()); if (!compatDc.dc) { @@ -191,7 +196,7 @@ namespace CompatGdiDc GetDCOrgEx(origDc, &origin); copyDcAttributes(compatDc, origDc, origin); - setClippingRegion(compatDc.dc, origDc, origin); + setClippingRegion(compatDc.dc, origDc, hwnd, isMenuWindow, origin); compatDc.refCount = 1; compatDc.origDc = origDc; diff --git a/DDrawCompat/CompatGdiDc.h b/DDrawCompat/CompatGdiDc.h index c2cd2d3..d94c428 100644 --- a/DDrawCompat/CompatGdiDc.h +++ b/DDrawCompat/CompatGdiDc.h @@ -6,7 +6,7 @@ namespace CompatGdiDc { - HDC getDc(HDC origDc); + HDC getDc(HDC origDc, bool isMenuPaintDc = false); HDC getOrigDc(HDC dc); void releaseDc(HDC origDc); } diff --git a/DDrawCompat/CompatGdiPaintHandlers.cpp b/DDrawCompat/CompatGdiPaintHandlers.cpp index 87afd39..f747f2b 100644 --- a/DDrawCompat/CompatGdiPaintHandlers.cpp +++ b/DDrawCompat/CompatGdiPaintHandlers.cpp @@ -197,7 +197,8 @@ namespace } HDC dc = GetWindowDC(hwnd); - HDC compatDc = CompatGdiDc::getDc(dc); + const bool isMenuPaintDc = true; + HDC compatDc = CompatGdiDc::getDc(dc, isMenuPaintDc); if (compatDc) { origWndProc(hwnd, WM_PRINT, reinterpret_cast(compatDc),