第十一课

如何让CDC上输出的文字、图形具有保持功能,集合类CPtrArray 的使用,CPaintDCCClientDC的区别与应用,OnPaintOnDrawCView中的关系及实现内幕,滚动窗口的实现,坐标空间,映射方式,设备坐标与逻辑坐标的转换。元文件设备描述表的使用,如何利用兼容DC实现图形的保存和再现。

  1. 设置窗口的滚动条 
  2. void CGraphicView::OnInitialUpdate() 窗口完全创立第一个调用的函数 
  3.     CScrollView::OnInitialUpdate(); 
  4.      
  5.     // TODO: Add your specialized code here and/or call the base class 
  6.     SetScrollSizes(MM_TEXT,CSize(800,600)); 
  7.  
  8. 创建元文件 
  9. CMetaFileDC m_dcMetaFile; 
  10. CGraphicView::CGraphicView() 
  11.     // TODO: add construction code here 
  12.     m_nDrawType=0; 
  13.     m_ptOrigin=0; 
  14.     m_dcMetaFile.Create(); 
  15.  
  16.     hmetaFile=m_dcMetaFile.Close(); 
  17.     pDC->PlayMetaFile(hmetaFile); 
  18.     m_dcMetaFile.Create(); 
  19.     m_dcMetaFile.PlayMetaFile(hmetaFile); 
  20.     DeleteMetaFile(hmetaFile); 
  21.  
  22. 保存元文件 
  23. void CGraphicView::OnFileSave()  
  24.     // TODO: Add your command handler code here 
  25.     HMETAFILE hmetaFile; 
  26.     hmetaFile=m_dcMetaFile.Close(); 
  27.     CopyMetaFile(hmetaFile,"meta.wmf"); 
  28.     m_dcMetaFile.Create(); 
  29.     DeleteMetaFile(hmetaFile); 
  30. 打开元文件 
  31. void CGraphicView::OnFileOpen()  
  32.     // TODO: Add your command handler code here 
  33.     HMETAFILE hmetaFile; 
  34.     hmetaFile=GetMetaFile("meta.wmf"); 
  35.     m_dcMetaFile.PlayMetaFile(hmetaFile); 
  36.     DeleteMetaFile(hmetaFile); 
  37.     Invalidate(); 
  38. 创建兼容位图 
  39.     if(!m_dcCompatible.m_hDC) 
  40.     { 
  41.         m_dcCompatible.CreateCompatibleDC(&dc); 
  42.         CRect rect; 
  43.         GetClientRect(&rect); 
  44.         CBitmap bitmap; 
  45.         bitmap.CreateCompatibleBitmap(&dc,rect.Width(),rect.Height()); 
  46.         m_dcCompatible.SelectObject(&bitmap); 
  47.         m_dcCompatible.BitBlt(0,0,rect.Width(),rect.Height(),&dc,0,0,SRCCOPY); 
  48.         m_dcCompatible.SelectObject(pBrush); 
  49.     }