thanks

解决方案 »

  1.   

    下面的代码片断产生一个图片大小为(800, 600)象素, 包括一个蓝色边框, 红色填充, 尺寸为(100, 100, 700, 500)象素单位矩形的Enhanced meta file:         CFileDialog dlg(FALSE, "wmf", "test.wmf"); if (dlg.DoModal())
    {
    CString strFileName = dlg.GetPathName();
    CDC *pDC = GetDC(); CRect rcBox(0, 0, 800, 600);
    rcBox.left = rcBox.left * pDC->GetDeviceCaps(HORZSIZE) * 100 / pDC->GetDeviceCaps(HORZRES);
    rcBox.top = rcBox.top * pDC->GetDeviceCaps(VERTSIZE) * 100 / pDC->GetDeviceCaps(VERTRES);
    rcBox.right = rcBox.right * pDC->GetDeviceCaps(HORZSIZE) * 100 / pDC->GetDeviceCaps(HORZRES);
    rcBox.bottom = rcBox.bottom * pDC->GetDeviceCaps(VERTSIZE) * 100 / pDC->GetDeviceCaps(VERTRES); CDC *pMetaDC = CDC::FromHandle(CreateEnhMetaFile(pDC->m_hDC, strFileName, &rcBox, NULL));
    if (pMetaDC)
    {
    int nOldMap = pMetaDC->SetMapMode(MM_LOENGLISH);
    CRect rc(100, 100, 700, 500);
    pMetaDC->DPtoLP(&rc);

    CPen pen(PS_SOLID, 2, RGB(0, 0, 255));
    CBrush brush(RGB(255, 0, 0)); CPen *pOldPen = (CPen *)pMetaDC->SelectObject(&pen);
    CBrush *pOldBrush = (CBrush *)pMetaDC->SelectObject(&brush); pMetaDC->Rectangle(&rc); pMetaDC->SelectObject(pOldPen);
    pMetaDC->SelectObject(pOldBrush);
    pMetaDC->SetMapMode(nOldMap); HENHMETAFILE hMetaFile = CloseEnhMetaFile(pMetaDC->Detach());
    if (hMetaFile)
    {
    DeleteEnhMetaFile(hMetaFile);
    }
    }
    else
    {
    AfxMessageBox("Failed to create meta file .");
    } ReleaseDC(pDC);
    }