VS2005 painter程序关键点

在视图类中使用CClientDC绘图

CClientDC pDC = new CClientDC(this);

pDC->MoveTo(...)
pDC->LineTo(...)
pDC->SelectStockObject(...)
pDC->Rectangle(....)

改变鼠标外观

BOOL CPainterView::PreCreateWindow(CREATESTRUCT &cs)
{
    cs.lpszClass = AfxRegisterWndClass(...);
}

删除原来的图形

nOldMode = pDC->GetROP2();

pDC->SetROP2(R2_NOT);

通过使用像素反色重新绘制原来图形(删除)

绘制新图形

pDC->SetROP2(nOldMode);

CMetaFileDC与CMetaFile

CMetaFileDC用于将绘图内容保存到内存,以便之后的重绘操作。

重绘操作

/*获取MetaFile句柄,重绘*/
HMETAFILE MetaFileHandle = pDoc->pMetaFileDC->Close();
pDC->PlayMetaFile(MetaFileHandle);

/*获取当前MetaFileDC*/
CMetaFileDC *ReplacementMetaFile = new CMetaFileDC();
ReplacementMetaFile->Create();
ReplacementMetaFile->PlayMetaFile(MetaFileHandle);

/*保存当前MetaFileDC*/
DeleteMetaFile(MetaFileHandle);
delete pDC->pMetaFileDC;
pDC->pMetaFileDC = ReplacementMetaFile;

 

保存到文件

CopyMetaFile(MetaFileHandle,_T("painter.wmf"));

 

从文件获取

HMETAFILE MetaFileHandle  = GetMetaFile(_T("painter.wmf"));

CMetaFileDC *ReplacementMetaFile = new CMetaFileDC();
ReplacementMetaFile->Create();
ReplacementMetaFile->PlayMetaFile(MetaFileHandle);
DeleteMetaFile(MetaFileHandle);

delete pDC->pMetaFileDC;
pDC->pMetaFileDC = ReplacementMetaFile;

Invalidate();


 

 

你可能感兴趣的:(VS2005 painter程序关键点)