From 8e456eafcbd9374d89eafd28a91184d6ea859ecb Mon Sep 17 00:00:00 2001 From: narzoul Date: Sat, 19 Mar 2016 16:16:13 +0100 Subject: [PATCH] Implemented WindowFromDC for compat DCs --- DDrawCompat/CompatGdiDc.cpp | 7 +++++++ DDrawCompat/CompatGdiDc.h | 1 + DDrawCompat/CompatGdiDcFunctions.cpp | 6 ++++++ 3 files changed, 14 insertions(+) diff --git a/DDrawCompat/CompatGdiDc.cpp b/DDrawCompat/CompatGdiDc.cpp index 20f6411..135232c 100644 --- a/DDrawCompat/CompatGdiDc.cpp +++ b/DDrawCompat/CompatGdiDc.cpp @@ -172,6 +172,13 @@ namespace CompatGdiDc return compatDc.dc; } + HDC getOrigDc(HDC dc) + { + const auto it = std::find_if(g_origDcToCompatDc.begin(), g_origDcToCompatDc.end(), + [dc](const CompatDcMap::value_type& compatDc) { return compatDc.second.dc == dc; }); + return it != g_origDcToCompatDc.end() ? it->first : dc; + } + void releaseDc(HDC origDc) { CompatGdi::GdiScopedThreadLock gdiLock; diff --git a/DDrawCompat/CompatGdiDc.h b/DDrawCompat/CompatGdiDc.h index 9def77d..c2cd2d3 100644 --- a/DDrawCompat/CompatGdiDc.h +++ b/DDrawCompat/CompatGdiDc.h @@ -7,5 +7,6 @@ namespace CompatGdiDc { HDC getDc(HDC origDc); + HDC getOrigDc(HDC dc); void releaseDc(HDC origDc); } diff --git a/DDrawCompat/CompatGdiDcFunctions.cpp b/DDrawCompat/CompatGdiDcFunctions.cpp index c03e037..1bdad1c 100644 --- a/DDrawCompat/CompatGdiDcFunctions.cpp +++ b/DDrawCompat/CompatGdiDcFunctions.cpp @@ -101,6 +101,11 @@ namespace { return &compatGdiDcFunc; } + + HWND WINAPI windowFromDc(HDC dc) + { + return CALL_ORIG_GDI(WindowFromDC)(CompatGdiDc::getOrigDc(dc)); + } } #define HOOK_GDI_DC_FUNCTION(module, func) \ @@ -147,6 +152,7 @@ namespace CompatGdiDcFunctions // Device context functions HOOK_GDI_DC_FUNCTION(gdi32, CreateCompatibleDC); HOOK_GDI_DC_FUNCTION(gdi32, DrawEscape); + HOOK_GDI_FUNCTION(user32, WindowFromDC, windowFromDc); // Filled shape functions HOOK_GDI_DC_FUNCTION(gdi32, Chord);