Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 433
  • Last Modified:

MFC MDI MetaFiles, EnhancedMetaFiles

Visual C++ 5.0, MDI application:

I tried to paint my window to a CMetaFileDC class, a regular one doesn't work, so I created an Enhanced MetaFile. The problem is that the texts are not saved. On the contrary the graphics are OK, but the text cannot be seen in the result file when I open it. The texts are written with the DrawText(...) function.

- How to fix the text problem: my code is:
mfdc.CreateEnhanced(NULL, "c:\\gir.emf", NULL, "GioGraph\0Graph\0\0" );//creating
pDoc->Data.DrawGraph(&mfdc, MaxSize, DG_METAFILE);//drawing
HENHMETAFILE hemf = mfdc.CloseEnhanced();//getting handle

- How to work with a regualar-not-enhanced MetaFile - my code is:
mfdc.Create("c:\\gir.wmf");//creating
pDoc->Data.DrawGraph(&mfdc, MaxSize, DG_METAFILE);//drawing
HMETAFILE hemf = mfdc.Close();//getting handle
0
giora
Asked:
giora
  • 2
1 Solution
 
piano_boxerCommented:
Can you post the code for pDoc->Data.DrawGraph() ?
0
 
piano_boxerCommented:
Try this code (It works for me in a very complex view drawing):


CDC* pDC = GetDC();
pDC->SetMapMode(MM_HIMETRIC);
CMetaFileDC dc;
if(dc.CreateEnhanced(pDC, "filename.emf", NULL, "Test\0File\0\0"))
{
    dc.SetMapMode(MM_HIMETRIC);
    dc.m_bPrinting = TRUE;
    dc.m_hAttribDC = pDC->m_hDC;
    OnDraw(&dc);  // Call normal drawing routine for the view
}

::DeleteEnhMetaFile(dc.CloseEnhanced());
ReleaseDC(pDC);

NOTE: You can change/remove the SetMapMode(MM_HIMETRIC) calls if you use a different mapping mode.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now