Here is a snippet of code that deals with the MouseWheel events correctly, taking into account the user setting SPI_GETWHEELSCROLLLINES. The default number of lines to scroll is three.
#define
HANDLE_WM_MOUSEWHEEL(hwnd,wParam,lParam,fn) ((fn)((hwnd),(int)(short)LOWORD(lParam),(int)(short)HIWORD(lParam),(int)(short)HIWORD(wParam),(UINT)(short)LOWORD(wParam)),0L)
#define WHEEL_DELTA 120
#define SPI_GETWHEELSCROLLLINES 104
static void OnMouseWheel(HWND hwnd, int xPos, int yPos, int zDelta, UINT fwKeys)
{
int pvParam;
SystemParametersInfo(SPI_GETWHEELSCROLLLINES, 0, &pvParam, 0);
int linesToScroll = (zDelta / WHEEL_DELTA ) * pvParam;
if (zDelta > 0)
{
do
FORWARD_WM_VSCROLL(hwnd, NULL, SB_LINEUP, 0, SendMessage);
while (--linesToScroll > 0);
}
else
{
do
FORWARD_WM_VSCROLL(hwnd, NULL, SB_LINEDOWN, 0, SendMessage);
while (++linesToScroll < 0);
}
}
LRESULT CALLBACK MdiChildWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
PAINTSTRUCT ps;
RECT rc;
switch(uMsg) {
case WM_MOUSEWHEEL:
HANDLE_WM_MOUSEWHEEL(hWnd,wParam,lParam,OnMouseWheel);
break;
You can change this scroll value permanently with this code.
#define SPI_SETWHEELSCROLLLINES 105
SystemParametersInfo(SPI_SETWHEELSCROLLLINES, 4, 0, SPIF_UPDATEINIFILE);