#include "WndProcEater.h" static HWND hWndEaten = 0; static WNDPROC eatenWndProc = 0; struct ExtraWndProcInfo { ExtraWndProc proc; DWORD flags; }; static ExtraWndProcInfo* extraProcs = 0; static int numExtraProcs = 0; void ReleaseExtraProc(ExtraWndProc proc) { // Probably isn't needed, but just in case... // Creating and destroying the mutex adds some inefficiency, // but this function is only called on emulation start and on focus/unfocus. HANDLE hMutex = CreateMutexA(0, 0, "LilyPad"); if (hMutex) WaitForSingleObject(hMutex, 100); for (int i=0; i res) res = res2; } } if (res != NO_WND_PROC) { if (out == WM_DESTROY) { ReleaseEatenProc(); } if (res == CONTINUE_BLISSFULLY) out = CallWindowProc(eatenWndProc, hWnd, uMsg, wParam, lParam); else if (res == USE_DEFAULT_WND_PROC) out = DefWindowProc(hWnd, uMsg, wParam, lParam); } return out; } int EatWndProc(HWND hWnd, ExtraWndProc proc, DWORD flags) { // Probably isn't needed, but just in case... // Creating and destroying the mutex adds some inefficiency, // but this function is only called on emulation start and on focus/unfocus. HANDLE hMutex = CreateMutexA(0, 0, "LilyPad"); if (hMutex) WaitForSingleObject(hMutex, 100); if (hWnd != hWndEaten) { ReleaseEatenProc(); eatenWndProc = (WNDPROC) SetWindowLongPtr(hWnd, GWLP_WNDPROC, (LONG_PTR)OverrideWndProc); // ??? if (eatenWndProc) hWndEaten = hWnd; } if (hWndEaten == hWnd) { extraProcs = (ExtraWndProcInfo*) realloc(extraProcs, sizeof(ExtraWndProcInfo)*(numExtraProcs+1)); extraProcs[numExtraProcs].proc = proc; extraProcs[numExtraProcs].flags = flags; numExtraProcs++; } if (hMutex) { ReleaseMutex(hMutex); CloseHandle(hMutex); } return hWndEaten == hWnd; }