MFC图像缩放时使滚动条最大值根据图像高宽进行变换。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
| void CChildView::ResetScrollBar(int cx, int cy) { CConfiguration* pCofig = CConfiguration::GetInstance(); double minScale = pCofig->GetMinScale(); double maxScale = pCofig->GetMaxScale(); double viewHeight = m_pDrawManager->GetAllTableSizeHeight(); double viewWidth = m_pDrawManager->GetAllTableSizeWidth(); double yScale = cy/viewHeight; double xScale = (cx-emDrawManagerPosX)/viewWidth; double scale = 1.0; if (abs(xScale) > abs(yScale)) { scale = xScale; } else { scale = yScale; } if (scale < minScale) { scale = minScale; } else if (scale > maxScale) { scale = maxScale; } m_pDrawManager->SetScaleFactor(scale); int tpos = 0; SCROLLINFO svc; GetScrollInfo(SB_VERT, &svc); tpos = svc.nPos; svc.fMask = SIF_ALL; svc.nMax = (int)(viewHeight*scale); svc.nMin = 0; svc.nPage = cy; svc.nPos = (int)(tpos*scale); SetScrollInfo(SB_VERT, &svc, TRUE); SCROLLINFO shc; GetScrollInfo(SB_HORZ, &shc); tpos = shc.nPos; shc.fMask = SIF_ALL; shc.nMax = (int)(viewWidth*scale); shc.nMin = 0; shc.nPage = cx; shc.nPos = (int)(tpos*scale); SetScrollInfo(SB_HORZ, &shc, TRUE); }
|