《截图及保存显示相关》由会员分享,可在线阅读,更多相关《截图及保存显示相关(12页珍藏版)》请在金锄头文库上搜索。
1、截图及保存显示相关void CZoomPartView:OnDraw(CDC* pDC)CZoomPartDoc* pDoc = GetDocument();ASSERT_VALID(pDoc);/ TODO: add draw code for native data here/声明判D断?是?否?load位?图?的?静2态?标志?static bool load;/按原-来大小?显?示?位?图?if (!load) BITMAP bm;load = !load;m_pBitmap-LoadBitmap(IDB_BITMAP1);m_pdcMem-CreateCompatibleDC(pDC
2、);m_pdcMem-SelectObject(m_pBitmap);m_pBitmap-GetObject(sizeof(bm),m_sizeSource.cx = bm.bmWidth;m_sizeSource.cy = bm.bmHeight;m_sizeDest = m_sizeSource;pDC-StretchBlt(0,0,m_sizeSource.cx,m_sizeSource.cy,m_pdcMem,0,0,m_sizeSource.cx,m_sizeSource.cy,mana);else pDC-StretchBlt(0,0,m_sizeSource.cx,m_sizeS
3、ource.cy,m_pdcMem,0,0,m_sizeSource.cx,m_sizeSource.cy,mana);void CZoomPartView:OnMouseMove(UINT nFlags, CPoint point) /计?算?要a放?大的?局?部?矩?形?的?源图?像?位?置?和目?标 位?置?CString cord; int dd;CRect srect,drect,mrect; srect.left = point.x - s; srect.top = point.y - s; srect.right = point.x + s; srect.bottom = poi
4、nt.y + s;drect.left = point.x - d; drect.top = point.y - d; drect.right = point.x + d; drect.bottom = point.y + d;mrect.left = oldx - d; mrect.top = oldy - d; mrect.right = oldx + d; mrect.bottom = oldy + d; dd = 2*d; CDC * pDC = GetDC(); OnPrepareDC(pDC); /放?大图?像?if (recover) pDC-BitBlt(mrect.left,
5、mrect.top,dd,dd, m_pdcMem,mrect.left,mrect.top,mana); pDC-StretchBlt(drect.left,drect.top, drect.Width(),drect.Height(),m_pdcMem,srect.left, srect.top,srect.Width(),srect.Height(),SRCCOPY); oldx = point.x; oldy = point.y; ReleaseDC(pDC);recover = true;CView:OnMouseMove(nFlags, point); void CZoomPart
6、View:OnLButtonDown(UINT nFlags, CPoint point) /如?果?鼠标位?置?不?在位?图?上?,?则还1原-位?图? 大小?显?示?CRect rc(0,0,m_sizeSource.cx,m_sizeSource.cy); if(!rc.PtInRect(point) Invalidate(); else if (d 5)/如?果?放?大倍?数y大于5,?就继 续?减?小?放?大倍?数y,?然?后进?行D放?大显?示? CDC * pDC = GetDC(); pDC-StretchBlt(oldx - d,oldy - d,2*d, 2*d,m_pdc
7、Mem,oldx - d,oldy - d,2*d,2*d,mana);d -= 10; ReleaseDC(pDC); CZoomPartView:OnMouseMove(nFlags, point); CView:OnLButtonDown(nFlags, point); void CZoomPartView:OnRButtonDown(UINT nFlags, CPoint point) /如?果?鼠标位?置?不?在位?图?上?,?则还1原-位?图? 大小?显?示?CRect rc(0,0,m_sizeSource.cx,m_sizeSource.cy); if(!rc.PtInRect
8、(point) Invalidate(); else if (d 8 ) lpDIBBits = (LPVOID)(LPDWORD)(bmInfo.bmiColors + bmInfo.bmiHeader.biClrUsed) + (bmInfo.bmiHeader.biCompression = BI_BITFIELDS) ? 3 : 0); else lpDIBBits = (LPVOID)(bmInfo.bmiColors + nColors);/ Select and realize the palette if one supplied and if device supports
9、it if( pPal pDC-RealizePalette(); :SetDIBitsToDevice(pDC-m_hDC, / hDC xDest, / DestX yDest, / DestY bmInfo.bmiHeader.biWidth, / nDestWidthbmInfo.bmiHeader.biHeight, / nDestHeight 0, / SrcX 0, / SrcY 0, / nStartScan bmInfo.bmiHeader.biHeight, / nNumScans lpDIBBits, / lpBits (LPBITMAPINFO)hDIB, / lpBi
10、tsInfo DIB_RGB_COLORS); / wUsage FunctionFunction 2:2: DrawBitmapDrawBitmapThe DrawBitmap() function can be used with both a DDB and a DIB section. This function does take into account that the destination device context might have a map mode other than MM_TEXT. This might not work always or the eff
11、ect may not be what you want. / DrawBitmap- Draws a bitmap (DDB :GetObject( hBitmap, sizeof( bm ), CPoint size( bm.bmWidth, bm.bmHeight ); pDC-DPtoLP(CPoint org(0,0); pDC-DPtoLP(/ Create a memory DC compatible with the destination DC CDC memDC; memDC.CreateCompatibleDC( pDC ); memDC.SetMapMode( pDC-
12、GetMapMode() );/memDC.SelectObject( HBITMAP hBmOld = (HBITMAP):SelectObject( memDC.m_hDC, hBitmap );/ Select and realize the palette if( hPal pDC-RealizePalette(); pDC-BitBlt(xDest, yDest, size.x, size.y, :SelectObject( memDC.m_hDC, hBmOld ); FunctionFunction 3:3: DrawDIBSectionDrawDIBSectionAlthoug
13、h we can use the DrawBitmap() function to draw a DIB section as well, this functions takes the color information of the bitmap into consideration and will create and use an appropriate palette when needed. Note that since this function may create a palette in each call, it might be better, for perfo
14、rmance reasons, to create an appropriate palette from the DIB section and use the DrawBitmap() function instead. The DrawDIBSection() is handy if DIB sections color information is modified before displaying it. / DrawDIBSection- Draws a DIB section onto a device / hDC- Handle to a device context / h
15、Bitmap- Handle of the DIB Section / xDest- x-coordinate of the upper-left corner of the destination rect / yDest- y-coordinate of the upper-left corner of the destination rect void DrawDIBSection( HDC hDC, HBITMAP hBitmap, int xDest, int yDest ) HPALETTE hPal;HDC hDCMem = :CreateCompatibleDC( hDC );/ Create a logical palette for the bitmap DIBSECTION ds; BITMAPINFOHEADER if( :GetObject(hBitmap, sizeof(ds), / Not a DIB SectionHGDIOBJ hBmpOld = :SelectObject(hDCMem, hBitmap);int nColors = bmInfo.biClrUsed ? bmInfo.biClrUsed : 1 256. if( n