第十一课
如何让CDC上输出的文字、图形具有保持功能,集合类CPtrArray 的使用,CPaintDC与CClientDC的区别与应用,OnPaint与OnDraw在CView中的关系及实现内幕,滚动窗口的实现,坐标空间,映射方式,设备坐标与逻辑坐标的转换。元文件设备描述表的使用,如何利用兼容DC实现图形的保存和再现。
- 设置窗口的滚动条
- void CGraphicView::OnInitialUpdate() 窗口完全创立第一个调用的函数
- {
- CScrollView::OnInitialUpdate();
- // TODO: Add your specialized code here and/or call the base class
- SetScrollSizes(MM_TEXT,CSize(800,600));
- }
- 创建元文件
- CMetaFileDC m_dcMetaFile;
- CGraphicView::CGraphicView()
- {
- // TODO: add construction code here
- m_nDrawType=0;
- m_ptOrigin=0;
- m_dcMetaFile.Create();
- }
- hmetaFile=m_dcMetaFile.Close();
- pDC->PlayMetaFile(hmetaFile);
- m_dcMetaFile.Create();
- m_dcMetaFile.PlayMetaFile(hmetaFile);
- DeleteMetaFile(hmetaFile);
- 保存元文件
- void CGraphicView::OnFileSave()
- {
- // TODO: Add your command handler code here
- HMETAFILE hmetaFile;
- hmetaFile=m_dcMetaFile.Close();
- CopyMetaFile(hmetaFile,"meta.wmf");
- m_dcMetaFile.Create();
- DeleteMetaFile(hmetaFile);
- }
- 打开元文件
- void CGraphicView::OnFileOpen()
- {
- // TODO: Add your command handler code here
- HMETAFILE hmetaFile;
- hmetaFile=GetMetaFile("meta.wmf");
- m_dcMetaFile.PlayMetaFile(hmetaFile);
- DeleteMetaFile(hmetaFile);
- Invalidate();
- }
- 创建兼容位图
- if(!m_dcCompatible.m_hDC)
- {
- m_dcCompatible.CreateCompatibleDC(&dc);
- CRect rect;
- GetClientRect(&rect);
- CBitmap bitmap;
- bitmap.CreateCompatibleBitmap(&dc,rect.Width(),rect.Height());
- m_dcCompatible.SelectObject(&bitmap);
- m_dcCompatible.BitBlt(0,0,rect.Width(),rect.Height(),&dc,0,0,SRCCOPY);
- m_dcCompatible.SelectObject(pBrush);
- }