Finally, I get here to report this error and hope some one can fix it in later versions.
Here is piece code handling WM_MOUSEWHEEL in vtkMFCWindow.cxx:
BOOL vtkMFCWindow::OnMouseWheel(UINT nFlags, short zDelta, CPoint point)
{
if(zDelta > 0)
static_cast<vtkWin32RenderWindowInteractor*>(this->GetInteractor())->
OnMouseWheelForward(this->GetSafeHwnd(), nFlags, point.x, point.y);
else
static_cast<vtkWin32RenderWindowInteractor*>(this->GetInteractor())->
OnMouseWheelBackward(this->GetSafeHwnd(), nFlags, point.x, point.y);
return TRUE;
}
which assume the parameter passed in “point” is in window client area, but it does not,
according to MSDN https://docs.microsoft.com/en-us/windows/win32/inputdev/wm-mousewheel
, the “point” passed as LPARAM for WM_MOUSEWHEEL is in screen space. I trace the calling chain underneath, the “point” will never be translated into client space, which will cause error when I override the handler of OnMouseWheelForwad and OnMouseWheelBackward in derived class of vtkInteractorStyle.
To fix this error, just review the following code segment:
BOOL vtkMFCWindow::OnMouseWheel(UINT nFlags, short zDelta, CPoint point)
{
/// Point is in screen space, translate to the client space.
/// This is a bug not fixed by VTK developers.
ScreenToClient(&point);
if(zDelta > 0)
static_cast<vtkWin32RenderWindowInteractor*>(this->GetInteractor())->
OnMouseWheelForward(this->GetSafeHwnd(), nFlags, point.x, point.y);
else
static_cast<vtkWin32RenderWindowInteractor*>(this->GetInteractor())->
OnMouseWheelBackward(this->GetSafeHwnd(), nFlags, point.x, point.y);
return TRUE;
}