How to redirect mouse wheel message to other windows?

I am developing a Word addin for MS Word on Windows, and this addin has as an "extended taskbar" showing and docking with on the left side of the Word document window (this is a treeview (outline) showing a list of Word documents for quick editing of several documents in a project) .

My question is that the Word document window responds to the message of the mouse wheel only when focusing , but I want to scroll the document with the mouse wheel when the mouse cursor freezes on it even in the Word document window there is no input focus.

Any clues in this particular case ? Thanks!

+7
source share
5 answers

Not quite sure if this will work, but I would try the following:

Implement global low-level mouse hook using function

+7
source

Perhaps you can use the SetCapture(hWnd) function of the Windows API. This will cause all mouse events to go to your hWnd instead of what hWnd can usually expect to receive. If you record when the mouse enters the window of the Word document, and ReleaseCapture() when the mouse leaves or Word begins to focus, it should work fine.

Disclaimer: I have used mouse capture in C # before, but I have never done this in C ++. I don’t know if he behaves the same way.

+2
source

Try the following, this may help you.

1) Contact the message WM_MOUSEHOVER .

2) In the handler, use SendMessage with WM_VSCROLL as the message parameter.

0
source

Using Spy ++, I saw that the window that receives the messages has the _Wwg class (at least 2003) and responds to WM_MOUSEWHEEL . Therefore, you must send this window a WM_MOUSEWHELL message when you want to scroll it.

0
source

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; } 
0
source

All Articles