MFC CChartCtrl 滚轮缩放
原文来自:MFC그래프 라이브러리, ChartCtrl 마우스 휠 기능 추가
BOOL CChartCtrl::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt) { ScreenToClient(&pt); double MinVal = 0; double MaxVal = 0; double rate = 0.1; if (m_bZoomEnabled) { if (zDelta > 0) { rate = rate * 1; } else { rate = rate * -1; } double ZoomCenter = 0; if (m_pAxes[BottomAxis]) { m_pAxes[BottomAxis]->GetMinMax(MinVal, MaxVal); ZoomCenter = m_pAxes[BottomAxis]->ScreenToValue(pt.x); MinVal = MinVal + (ZoomCenter - MinVal) * rate; MaxVal = MaxVal - (MaxVal - ZoomCenter) * rate; m_pAxes[BottomAxis]->SetZoomMinMax(MinVal, MaxVal); } if (m_pAxes[LeftAxis]) { m_pAxes[LeftAxis]->GetMinMax(MinVal, MaxVal); ZoomCenter = m_pAxes[LeftAxis]->ScreenToValue(pt.y); MinVal = MinVal + (ZoomCenter - MinVal) * rate; MaxVal = MaxVal - (MaxVal - ZoomCenter) * rate; m_pAxes[LeftAxis]->SetZoomMinMax(MinVal, MaxVal); } if (m_pAxes[TopAxis]) { m_pAxes[TopAxis]->GetMinMax(MinVal, MaxVal); ZoomCenter = m_pAxes[TopAxis]->ScreenToValue(pt.x); MinVal = MinVal + (ZoomCenter - MinVal) * rate; MaxVal = MaxVal - (MaxVal - ZoomCenter) * rate; m_pAxes[TopAxis]->SetZoomMinMax(MinVal, MaxVal); } if (m_pAxes[RightAxis]) { m_pAxes[RightAxis]->GetMinMax(MinVal, MaxVal); ZoomCenter = m_pAxes[RightAxis]->ScreenToValue(pt.y); MinVal = MinVal + (ZoomCenter - MinVal) * rate; MaxVal = MaxVal - (MaxVal - ZoomCenter) * rate; m_pAxes[RightAxis]->SetZoomMinMax(MinVal, MaxVal); } RefreshCtrl(); if (m_PlottingRect.PtInRect(pt)) { TCursorMap::iterator iter = m_mapCursors.begin(); for (iter; iter != m_mapCursors.end(); iter++) iter->second->OnMouseButtonUp(pt); Invalidate(); } } return CWnd::OnMouseWheel(nFlags, zDelta, pt); }