Note: The most up-to-date version of the code is in post #1. WheelHookAllControls.zip includes MSFlexGrid example
It was brought to my attention that controls that already responded to the MouseWheel (combobox, textbox, etc.), would prevent MouseWheel events passing to form, so even if you were over a grid, it would be the combobox that scrolled, and you would have to remove focus from the control before it would work
I have fixed this so that you can Hook the controls, and if a WM_MOUSEWHEEL event occurs and the mouse is not over the control, it triggers the MouseWheel sub on the form.
The code for scrolling the grid if it's the activecontrol will work fine regardless of other controls responding to scroll events.
EDIT: This was recovered from the original post. The original two attachments are the links WheelHook-NestedControls and WheelHook-AllControls:
These example projects demonstrate enabling the MouseWheel for any control (multiple controls / multiple forms).
Examples
• Enabling MouseWheel Support with any control - attached to post #1 14/03/06: Slight correction to code 20/04/06: Minor modification to code (more info: post #9) 12/01/07:Nested Controls example created allowing the mousewheel to work with controls nested to any depth - incorporates fixes from other posts (1, 2) - attached to post #1
The hooking code was modified from here. Original thread, with suggestions from other members.
Note:
These codes use subclassing which can cause your IDE to crash if your code is incorrectly ended (e.g. via the stop button).
See here for adding in code to detect if your program is running in the IDEWheelHook-NestedControls.zipWheelHook-AllControls.zip
Last edited by Shaggy Hiker; Apr 21st, 2023 at 10:07 AM.