Scrolling A Console Window Using The Scroll Wheel

 

To implement scrolling, you will need to:

Enable mouse events by executing SetConsoleMode(hStdin, ENABLE_MOUSE_INPUT).

 

Read input event using ReadConsoleInput.

 

Process MOUSE_EVENT events and for each TRANSLATE_WHEEL event, get the dwButtonState parameter from the MOUSE_EVENT_RECORD and use the high order word to determine how far to scroll the window. I found that I had to divide the value by 5 and negate it to get the number of text lines to scroll.
 

Get the current window position using GetConsoleScreenBufferInfo and getting the x and y position from the srWindow parameter.  Add the value calculated in the previous step to the y parameter and use SetConsoleWindowInfo to change the setting.