Copying Graphical Data via Enhanced Meta File

The code below is copying graphical data via enhanced meta file to any application. Even to WinWord 7.0 which makes it different to Randy Mores code. It is placed into an appropriate function of a class derived from CView.
	CMetaFileDC * m_pMetaDC = new CMetaFileDC();
	//draw meta file

	//do what ever you want to do: bitmaps, lines, text...

	//close meta file dc and prepare for clipboard;
	HENHMETAFILE hMF = m_pMetaDC->CloseEnhanced();

	//copy to clipboard
	delete m_pMetaDC;

Altogether it is a pretty straight forward solution as suggested by the help documents provided with VC++ making it a good alternative to Randys code. And it's working with Word 7.0. Tested printing, too. :)

Have fun

Last updated: 11 April 1998


  • Meta-File is not created!

    Posted by Legacy on 04/07/2003 12:00am

    Originally posted by: Matthias Beck

    I tried what you wrote, but it doesn�t work.
    The application doesn�t create any .emf file.
    What can I do? Shall I copy the Meta File like this?

    CopyEnhMetaFile(hMF, "CopiedMeta-File.emf" );

    or play the Meta-File???

    pDC->PlayMetaFile (hMF, rechteck);

    don�t know what to do...

    Thanks in advance!!!

  • how to copy selected region in graph

    Posted by Legacy on 08/15/2002 12:00am

    Originally posted by: jing zhang

    Hi there,

    I have a problem about copying selected region in graph. I have a
    scrollview to show my graph, which has zoom in/out function. When I
    zoom in, the whole graph is redrawn in total scroll size, but only
    region of interested will be shown in view client area. Now, I only
    want to copy the zoom-in part in client area, not the total scroll
    size, how can I do? I use CMetaFileDC for copying, and also try to use
    SetViewportExt and SetViewportOrg to set the position, but they don't
    work. Any sample code will be very appreciated.

    Thank you very much!


  • Is there some changes in OfficeXP for handling enhance metafile ?

    Posted by Legacy on 01/23/2002 12:00am

    Originally posted by: Sapto Priyono

    I have copied the object of OfficeXP (shapes in Power Point) and with COleDataObject, I get their enhance metafile. I enumerate this enhance metafile to be many enhance metarecords. In Office'97 and Office 2000, the position and demension of this enhance metafile (rclBounds, szlDevice,xDest,cxDest,yDest,cyDest etc in enhance metarecords) are correct, but not correct in OfficeXP. I use the OS of Windows 2000 Profesional. Is there some changes in OfficeXP for handling enhance metafile ? Thank's.

  • How can I save a bitmap file to disk (bmp, gif or jpg) from an Enhanced Metafile in Clipboard?

    Posted by Legacy on 01/17/2002 12:00am

    Originally posted by: Sergi Balaguer

    I'm trying to retrieve data from Clipboard that is in Enhanced Metafile format. I have already achieved this. But I want to save a Bitmap file (BMP, GIF, or JPG) from this EMF data in Clipboard to disk. How can I do this?


  • not working inside an ATL control !

    Posted by Legacy on 01/07/2002 12:00am

    Originally posted by: shyamal

    I tried the same inside an ATL ActiveX control.. Doesnt seem to be working :(

  • Problems with SetTextAlign

    Posted by Legacy on 12/15/1999 12:00am

    Originally posted by: Cathy Grimes

    When calling CDC:SetTextAlign to align text, the old alignment should be returned. However, when calling this function when the device context is a metafile, a random number is returned. If the old text alignment is used to reset the text alignment, this can have the effect of showing misaligned text on the clipboard or pasted image. I recommend that you do not used the old text alignment but explicitly set the alignment that you require.

    Do not rely on this code

    UINT old_align = m_pDC->SetTextAlign( TA_CENTER | TA_TOP );

    m_pDC->SetTextAlign( old_align );

    This is safer

    UINT old_align = m_pDC->SetTextAlign( TA_CENTER | TA_TOP );

    m_pDC->SetTextAlign( TA_LEFT | TA_TOP );

  • Works well!

    Posted by Legacy on 09/01/1999 12:00am

    Originally posted by: Pascal Bertolino

    Thank you for this code, it's straightforward and it works well. Now, we are waiting for a paste snippet... :-)


  • Works well!

    Posted by Legacy on 09/01/1999 12:00am

    Originally posted by: Pascal Bertolino

    Thank you for this code, it's straightforward and it works well. Now, we are waiting for a paste snippet... :-)


Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Companies undertaking an IT project need to find the right balance between cost and functionality. It's important to start by determining whether to build a solution from scratch, buy an out-of-the-box solution, or a combination of both. In reality, most projects will require some system tailoring to meet business requirements. Decision-makers must understand how much software development is enough and craft a detailed implementation plan to ensure the project's success. This white paper examines the different …

  • This report outlines the future look of Forrester's solution for security and risk (S&R) executives working on building an identity and access management strategy for the extended enterprise. We designed this report to help you understand and navigate the major business and IT trends affecting identity and access management (IAM) during the next five years. IAM in 2012 has become a tool not just for security but also for business agility. Competitive challenges push businesses into the cloud and encourage …

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date