Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to redirect mouse wheel message to other windows?

I'm developing a Word addin for MS Word on Windows, and this addin has as 'advanced task pane' showing and docking on the left side of the Word document window (it's treeview(outline) showing a list of Word documents for fast editing multiple documents in a project).

My question is, the Word document window responds to mouse wheel message only when it's focused, but I want to be able to scroll the document with mouse wheel whenever the mouse cursor is hovering on it even the Word document window doesn't have a input focus.

Any hints in this particular case? Thank you!

like image 914
Edwin Yip Avatar asked May 05 '11 11:05

Edwin Yip


2 Answers

Not quite sure it will work, but I'd try the following:

Implement a global low-level mouse hook using the SetWindowsHookEx function. In the hook procedure, which should be called on mouse wheel scroll events, check if the window under mouse cursor is the Word document window. If so, set a shared flag indicating the needed scroll action. Don't send WM_VSCROLL directly from the hook procedure! This procedure has to be really fast and simple.

Now, in your add-in's message loop check the flag and if it is set, send WM_VSCROLL to the Word document window.

like image 93
Alex Jenter Avatar answered Nov 14 '22 20:11

Alex Jenter


Perhaps you could make use of the SetCapture(hWnd) Windows API function. This will cause all mouse events to go to your hWnd instead of whatever hWnd might normally expect to receive them. If you capture when the mouse enters the Word document window, and ReleaseCapture() when the mouse leaves or Word gains focus, it should work alright.

Disclaimer: I've used mouse capturing in C# before, but I've never done it in C++. I don't know if it behaves exactly the same way.

like image 35
Sean Edwards Avatar answered Nov 14 '22 20:11

Sean Edwards