精通
英语
和
开源
,
擅长
开发
与
培训
,
胸怀四海
第一信赖
锐英源精品开源心得,转载请注明:“锐英源www.wisestudy.cn,孙老师作品,电话13803810136。”需要全文内容也请联系孙老师。
#define MAXZOOMIN 4 // Maximum zoom-in factor最大放大因子 #define PICKMARGIN 10 // Screen pixels apart for region zoom用于缩放区域的屏幕像素成组个数 ///////////////////////////////////////////////////////////////////////////// // CZoomView IMPLEMENT_DYNCREATE(CZoomView, CScrollView) /*--------------------------------------------------------------------------- FUNCTION: CZoomView PURPOSE : Constructor for the CZoomView class 构造函数 ---------------------------------------------------------------------------*/ CZoomView::CZoomView() : CScrollView() { // Init zoom mode to nothing模式设置为空 m_zoomMode = MODE_ZOOMOFF; m_bCaptured = FALSE; m_zoomScale = 1.0;> m_ptDragRect.SetRectEmpty(); // Load the zoom cursor加载图标 m_hZoomCursor = ::LoadCursor(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDC_ZOOMCURSOR)); // Default to centering on full fit默认屏幕居中 m_bCenter = TRUE; } // CZoomView /*--------------------------------------------------------------------------- FUNCTION: ~CZoomView PURPOSE : Destructor for the CZoomView class 析构函数 ---------------------------------------------------------------------------*/ CZoomView::~CZoomView() { // Clean up the cursors if they were loaded properly释放图标 if (m_hZoomCursor) DestroyCursor(m_hZoomCursor); } // ~CZoomView ///////////////////////////////////////////////////////////////////////////// // CZoomView overridden default CScrollView members ///////////////////////////////////////////////////////////////////////////// /*--------------------------------------------------------------------------- FUNCTION: SetZoomSizes PURPOSE : Set up the CZoomView class with the logical page size, and 以逻辑页面大小和滚动页/行单位来设置 scrolling page/line units. This replaces CScrollView::SetScrollSizes.替换CScrollView::SetScrollSizes ---------------------------------------------------------------------------*/ void CZoomView::SetZoomSizes ( SIZE sizeTotal, const SIZE& sizePage, // in logical units逻辑单位 const SIZE& sizeLine) // in logical units { // Set up the defaults设置为默认 ASSERT(sizeTotal.cx >= 0 && sizeTotal.cy >= 0); m_nMapMode = MM_ANISOTROPIC; // Need for arbitrary scaling需要服务于自由缩放 m_totalLog = sizeTotal;//文档里的m_sizeDoc决定的大小 // Setup default Viewport extent to be conversion of Window extent // into device units.设置默认的视口大小,使窗口大小以设备单位能够和视口大小转换 //BLOCK for DC DC代码块 CWindowDC dc(NULL); dc.SetMapMode(m_nMapMode); // total size总大小 m_totalDev = m_totalLog; dc.LPtoDP((LPPOINT)&m_totalDev); } // Release DC here // Save the origional Viewport Extent保存视口大小原来值 m_origTotalDev = m_totalDev; // Save the origional scrollbar info - for CalcBars保存滚动信息原来值 -用于CalcBars m_origPageDev = sizePage;//滚动用的页面大小 m_origLineDev = sizeLine;//滚动用的一行的大小 // Fugure out scroll bar info计算滚动条信息 CalcBars(); // Notify the class that the zoom scale was set通知类缩放比例设置好了 NotifyZoom(); } // SetZoomSizes /*--------------------------------------------------------------------------- FUNCTION: OnPrepareDC PURPOSE : Override of CScrollView for MM_ANISOTROPIC zoom mode MM_ANISOTROPIC模式设置 ---------------------------------------------------------------------------*/ void CZoomView::OnPrepareDC ( CDC* pDC, CPrintInfo* pInfo) { #ifdef _DEBUG if (m_nMapMode != MM_ANISOTROPIC) { TRACE0("Error: must call SetZoomSizes() before painting zoom view\n"); ASSERT(FALSE); return; } #endif //_DEBUG ASSERT_VALID(pDC); ASSERT(m_totalLog.cx >= 0 && m_totalLog.cy >= 0); ASSERT(m_totalDev.cx >= 0 && m_totalDev.cx >= 0); // Set the Mapping mode, and the window and viewport extents设置模式,窗口和视口大小 pDC->SetMapMode(m_nMapMode); pDC->SetWindowExt(m_totalLog); // in logical coordinates逻辑坐标单位 CPoint ptVpOrg; if (!pDC->IsPrinting()) {//如果不是打印 //初始化时m_totalLog==m_totalDev,通过修改视口大小来实现缩放 pDC->SetViewportExt(m_totalDev); // in device coordinates设备坐标单位 // by default shift viewport origin in negative direction of scroll默认把原点设置到滚动方向的反方向 ASSERT(pDC->GetWindowOrg() == CPoint(0,0)); ptVpOrg = -GetDeviceScrollPosition(); // Center full fit居中自适应 if (m_bCenter) { CRect rect; GetClientRect(&rect); // if client area is larger than total device size,如果客户区比设备总大小大, // override scroll positions to place origin such that覆盖滚动位置来设置原点位置,让输出居中到窗口 // output is centered in the window if (m_totalDev.cx < rect.Width()) ptVpOrg.x = (rect.Width() - m_totalDev.cx) / 2; if (m_totalDev.cy < rect.Height()) ptVpOrg.y = (rect.Height() - m_totalDev.cy) / 2; } } else { // Special case for printing打印情况的处理 CSize printSize; printSize.cx = pDC->GetDeviceCaps(HORZRES); printSize.cy = pDC->GetDeviceCaps(VERTRES); // Maintain the origional ratio, setup origin shift维护原来比例,设置原点进行移动 PersistRatio(m_totalLog, printSize, ptVpOrg); // Zoom completely out缩小 pDC->SetViewportExt(printSize); } // Set the new origin设置新的原点 pDC->SetViewportOrg(ptVpOrg); // For default Printing behavior CView::OnPrepareDC(pDC, pInfo); } // OnPrepareDC