I have C ++ code compressed from the comment below at https://msdn.microsoft.com/en-us/library/windows/desktop/ms645617(v=vs.85).aspx
And I have used it (and the options on it) successfully.
The user who wrote it claims to be inspired by the recommendation of ms in the Windows Vista Best Practices Guide to forward the mouse wheel event to any window hovering with the mouse cursor. The advantage of his / her implementation is that it is completely non-intrusive, you just drop it, and it sets hooks, referring to your main thread. This allows you to redirect the event to windows belonging to other processes, but perhaps it really can be good.
namespace { LRESULT CALLBACK mouseInputHook(int nCode, WPARAM wParam, LPARAM lParam) { //"if nCode is less than zero, the hook procedure must pass the message to the CallNextHookEx function //without further processing and should return the value returned by CallNextHookEx" if (nCode >= 0) { MSG& msgInfo = *reinterpret_cast<MSG*>(lParam); if (msgInfo.message == WM_MOUSEWHEEL || msgInfo.message == WM_MOUSEHWHEEL) { POINT pt = {}; pt.x = ((int)(short)LOWORD(msgInfo.lParam)); //yes, there also msgInfo.pt, but let not take chances pt.y = ((int)(short)HIWORD(msgInfo.lParam)); // //visible child window directly under cursor; attention: not necessarily from our process! //http://blogs.msdn.com/b/oldnewthing/archive/2010/12/30/10110077.aspx if (HWND hWin = ::WindowFromPoint(pt)) if (msgInfo.hwnd != hWin && ::GetCapture() == nullptr) { DWORD winProcessId = 0; ::GetWindowThreadProcessId(//no-fail! hWin, //_In_ HWND hWnd, &winProcessId); //_Out_opt_ LPDWORD lpdwProcessId if (winProcessId == ::GetCurrentProcessId()) //no-fail! msgInfo.hwnd = hWin; //it would be a bug to set handle from another process here } } } return ::CallNextHookEx(nullptr, nCode, wParam, lParam); } struct Dummy { Dummy() { hHook = ::SetWindowsHookEx(WH_GETMESSAGE, //__in int idHook, mouseInputHook, //__in HOOKPROC lpfn, nullptr, //__in HINSTANCE hMod, ::GetCurrentThreadId()); //__in DWORD dwThreadId assert(hHook); } ~Dummy() { if (hHook) ::UnhookWindowsHookEx(hHook); } private: HHOOK hHook; } dummy; }
Alexandre Pereira Nunes
source share