mirror of
https://github.com/narzoul/DDrawCompat
synced 2024-12-30 08:55:36 +01:00
Moved WM_ERASEBKGND handling to DefWindowProc
Unfortunately, Edit and ListBox controls don't seem to handle WM_ERASEBKGND through DefWindowProc, so their window procedures need additional hooking.
This commit is contained in:
parent
7ece7eed97
commit
6850fc449c
@ -273,6 +273,14 @@ namespace CompatGdi
|
||||
}
|
||||
}
|
||||
|
||||
void hookWndProc(LPCSTR className, WNDPROC &oldWndProc, WNDPROC newWndProc)
|
||||
{
|
||||
HWND hwnd = CreateWindow(className, nullptr, 0, 0, 0, 0, 0, nullptr, nullptr, nullptr, 0);
|
||||
oldWndProc = reinterpret_cast<WNDPROC>(
|
||||
SetClassLongPtr(hwnd, GCLP_WNDPROC, reinterpret_cast<LONG>(newWndProc)));
|
||||
DestroyWindow(hwnd);
|
||||
}
|
||||
|
||||
void installHooks()
|
||||
{
|
||||
InitializeCriticalSection(&g_gdiCriticalSection);
|
||||
|
@ -47,6 +47,7 @@ namespace CompatGdi
|
||||
reinterpret_cast<void*&>(getOrigFuncPtr<OrigFuncPtr, origFunc>()), newFuncPtr);
|
||||
}
|
||||
|
||||
void hookWndProc(LPCSTR className, WNDPROC &oldWndProc, WNDPROC newWndProc);
|
||||
void installHooks();
|
||||
void invalidate(const RECT* rect);
|
||||
void updatePalette();
|
||||
|
@ -10,9 +10,15 @@ namespace
|
||||
{
|
||||
LRESULT WINAPI defWindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam,
|
||||
WNDPROC origDefWindowProc, const char* funcName);
|
||||
LRESULT WINAPI eraseBackgroundProc(
|
||||
HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam, WNDPROC origWndProc, const char* wndProcName);
|
||||
LRESULT onEraseBackground(HWND hwnd, HDC dc, WNDPROC origWndProc);
|
||||
LRESULT onNcPaint(HWND hwnd, WPARAM wParam, WNDPROC origWndProc);
|
||||
LRESULT onPrint(HWND hwnd, UINT msg, HDC dc, LONG flags, WNDPROC origWndProc);
|
||||
|
||||
WNDPROC g_origEditWndProc = nullptr;
|
||||
WNDPROC g_origListBoxWndProc = nullptr;
|
||||
|
||||
LRESULT WINAPI defDlgProcA(HWND hdlg, UINT msg, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
return defWindowProc(hdlg, msg, wParam, lParam, CALL_ORIG_GDI(DefDlgProcA), "defDlgProcA");
|
||||
@ -36,6 +42,10 @@ namespace
|
||||
|
||||
switch (msg)
|
||||
{
|
||||
case WM_ERASEBKGND:
|
||||
result = onEraseBackground(hwnd, reinterpret_cast<HDC>(wParam), origDefWindowProc);
|
||||
break;
|
||||
|
||||
case WM_NCPAINT:
|
||||
result = onNcPaint(hwnd, wParam, origDefWindowProc);
|
||||
break;
|
||||
@ -64,6 +74,58 @@ namespace
|
||||
return defWindowProc(hwnd, msg, wParam, lParam, CALL_ORIG_GDI(DefWindowProcW), "defWindowProcW");
|
||||
}
|
||||
|
||||
LRESULT WINAPI editWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
return eraseBackgroundProc(hwnd, msg, wParam, lParam, g_origEditWndProc, "editWndProc");
|
||||
}
|
||||
|
||||
LRESULT WINAPI eraseBackgroundProc(
|
||||
HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam, WNDPROC origWndProc, const char* wndProcName)
|
||||
{
|
||||
Compat::LogEnter(wndProcName, hwnd, msg, wParam, lParam);
|
||||
|
||||
LPARAM result = 0;
|
||||
if (WM_ERASEBKGND == msg)
|
||||
{
|
||||
result = onEraseBackground(hwnd, reinterpret_cast<HDC>(wParam), origWndProc);
|
||||
}
|
||||
else
|
||||
{
|
||||
result = origWndProc(hwnd, msg, wParam, lParam);
|
||||
}
|
||||
|
||||
Compat::LogLeave(wndProcName, hwnd, msg, wParam, lParam) << result;
|
||||
return result;
|
||||
}
|
||||
|
||||
LRESULT WINAPI listBoxWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
return eraseBackgroundProc(hwnd, msg, wParam, lParam, g_origListBoxWndProc, "listBoxWndProc");
|
||||
}
|
||||
|
||||
LRESULT onEraseBackground(HWND hwnd, HDC dc, WNDPROC origWndProc)
|
||||
{
|
||||
if (!hwnd || !CompatGdi::beginGdiRendering())
|
||||
{
|
||||
return origWndProc(hwnd, WM_ERASEBKGND, reinterpret_cast<WPARAM>(dc) , 0);
|
||||
}
|
||||
|
||||
LRESULT result = 0;
|
||||
HDC compatDc = CompatGdiDc::getDc(dc);
|
||||
if (compatDc)
|
||||
{
|
||||
result = origWndProc(hwnd, WM_ERASEBKGND, reinterpret_cast<WPARAM>(compatDc), 0);
|
||||
CompatGdiDc::releaseDc(dc);
|
||||
}
|
||||
else
|
||||
{
|
||||
result = origWndProc(hwnd, WM_ERASEBKGND, reinterpret_cast<WPARAM>(dc), 0);
|
||||
}
|
||||
|
||||
CompatGdi::endGdiRendering();
|
||||
return result;
|
||||
}
|
||||
|
||||
LRESULT onNcPaint(HWND hwnd, WPARAM wParam, WNDPROC origWndProc)
|
||||
{
|
||||
if (!hwnd || !CompatGdi::beginGdiRendering())
|
||||
@ -122,6 +184,9 @@ namespace CompatGdiPaintHandlers
|
||||
{
|
||||
void installHooks()
|
||||
{
|
||||
CompatGdi::hookWndProc("Edit", g_origEditWndProc, &editWndProc);
|
||||
CompatGdi::hookWndProc("ListBox", g_origListBoxWndProc, &listBoxWndProc);
|
||||
|
||||
DetourTransactionBegin();
|
||||
HOOK_GDI_FUNCTION(user32, DefWindowProcA, defWindowProcA);
|
||||
HOOK_GDI_FUNCTION(user32, DefWindowProcW, defWindowProcW);
|
||||
|
@ -18,7 +18,6 @@ namespace
|
||||
std::unordered_map<HWND, RECT> g_prevWindowRect;
|
||||
|
||||
void disableDwmAttributes(HWND hwnd);
|
||||
void eraseBackground(HWND hwnd, HDC dc);
|
||||
void onWindowPosChanged(HWND hwnd);
|
||||
void removeDropShadow(HWND hwnd);
|
||||
|
||||
@ -39,13 +38,6 @@ namespace
|
||||
CompatGdi::GdiScopedThreadLock lock;
|
||||
g_prevWindowRect.erase(ret->hwnd);
|
||||
}
|
||||
else if (WM_ERASEBKGND == ret->message)
|
||||
{
|
||||
if (0 != ret->lResult)
|
||||
{
|
||||
eraseBackground(ret->hwnd, reinterpret_cast<HDC>(ret->wParam));
|
||||
}
|
||||
}
|
||||
else if (WM_WINDOWPOSCHANGED == ret->message)
|
||||
{
|
||||
onWindowPosChanged(ret->hwnd);
|
||||
@ -85,20 +77,6 @@ namespace
|
||||
&disableTransitions, sizeof(disableTransitions));
|
||||
}
|
||||
|
||||
void eraseBackground(HWND hwnd, HDC dc)
|
||||
{
|
||||
if (CompatGdi::beginGdiRendering())
|
||||
{
|
||||
HDC compatDc = CompatGdiDc::getDc(dc);
|
||||
if (compatDc)
|
||||
{
|
||||
SendMessage(hwnd, WM_ERASEBKGND, reinterpret_cast<WPARAM>(compatDc), 0);
|
||||
CompatGdiDc::releaseDc(dc);
|
||||
}
|
||||
CompatGdi::endGdiRendering();
|
||||
}
|
||||
}
|
||||
|
||||
LRESULT CALLBACK mouseProc(int nCode, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
if (HC_ACTION == nCode)
|
||||
|
Loading…
x
Reference in New Issue
Block a user