diff --git a/DDrawCompat/Gdi/Cursor.cpp b/DDrawCompat/Gdi/Cursor.cpp index a4996c4..8f0779a 100644 --- a/DDrawCompat/Gdi/Cursor.cpp +++ b/DDrawCompat/Gdi/Cursor.cpp @@ -191,7 +191,7 @@ namespace Gdi g_prevCursorInfo = {}; POINT pos = {}; - GetCursorPos(&pos); + CALL_ORIG_FUNC(GetCursorPos)(&pos); SetCursorPos(pos.x, pos.y); } diff --git a/DDrawCompat/Gdi/WinProc.cpp b/DDrawCompat/Gdi/WinProc.cpp index c982d76..9a010ed 100644 --- a/DDrawCompat/Gdi/WinProc.cpp +++ b/DDrawCompat/Gdi/WinProc.cpp @@ -2,6 +2,7 @@ #include #include +#include #include #include @@ -54,6 +55,7 @@ namespace Compat::SrwLock g_windowProcSrwLock; std::map g_windowProc; + thread_local POINT* g_cursorPos = nullptr; thread_local unsigned g_inCreateDialog = 0; thread_local unsigned g_inMessageBox = 0; thread_local unsigned g_inWindowProc = 0; @@ -88,6 +90,7 @@ namespace { LOG_FUNC("ddcWindowProc", Compat::WindowMessageStruct(hwnd, uMsg, wParam, lParam)); ScopedIncrement inc(g_inWindowProc); + POINT cursorPos = {}; switch (uMsg) { @@ -111,6 +114,15 @@ namespace onInitDialog(hwnd); break; + case WM_MOUSEMOVE: + if (1 == g_inWindowProc) + { + cursorPos = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) }; + ClientToScreen(hwnd, &cursorPos); + g_cursorPos = &cursorPos; + } + break; + case WM_SYNCPAINT: if (Gdi::Window::isTopLevelWindow(hwnd)) { @@ -190,6 +202,13 @@ namespace onInitMenuPopup(reinterpret_cast(wParam)); break; + case WM_MOUSEMOVE: + if (1 == g_inWindowProc) + { + g_cursorPos = nullptr; + } + break; + case WM_NCDESTROY: onDestroyWindow(hwnd); break; @@ -247,6 +266,16 @@ namespace return LOG_RESULT(CALL_ORIG_FUNC(SetWindowLongA)(hWnd, nIndex, dwNewLong)); } + BOOL WINAPI getCursorPos(LPPOINT lpPoint) + { + if (lpPoint && g_cursorPos) + { + *lpPoint = *g_cursorPos; + return TRUE; + } + return CALL_ORIG_FUNC(GetCursorPos)(lpPoint); + } + BOOL WINAPI getMessage(LPMSG lpMsg, HWND hWnd, UINT wMsgFilterMin, UINT wMsgFilterMax, decltype(&GetMessageA) origGetMessage) { @@ -719,6 +748,7 @@ namespace Gdi HOOK_FUNCTION(user32, DialogBoxParamW, createDialog); HOOK_FUNCTION(user32, DialogBoxIndirectParamA, createDialog); HOOK_FUNCTION(user32, DialogBoxIndirectParamW, createDialog); + HOOK_FUNCTION(user32, GetCursorPos, getCursorPos); HOOK_FUNCTION(user32, GetMessageA, getMessageA); HOOK_FUNCTION(user32, GetMessageW, getMessageW); HOOK_FUNCTION(user32, GetWindowLongA, getWindowLongA); diff --git a/DDrawCompat/Input/Input.cpp b/DDrawCompat/Input/Input.cpp index 471e86f..6ba4c45 100644 --- a/DDrawCompat/Input/Input.cpp +++ b/DDrawCompat/Input/Input.cpp @@ -103,7 +103,7 @@ namespace { POINT cp = g_cursorPos; POINT origCp = {}; - GetCursorPos(&origCp); + CALL_ORIG_FUNC(GetCursorPos)(&origCp); cp.x += (llHook.pt.x - origCp.x); cp.y += (llHook.pt.y - origCp.y);