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();
	m_pMetaDC->CreateEnhanced(GetDC(),NULL,NULL,"whatever");
	//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
	OpenClipboard();
	EmptyClipboard();
	::SetClipboardData(CF_ENHMETAFILE,hMF);
	CloseClipboard();
	//DeleteMetaFile(hMF);
	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


Comments

  • 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!!!

    Reply
  • 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!

    jing

    Reply
  • 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.

    Reply
  • 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?

    Thanks.

    Reply
  • 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 :(

    Reply
  • 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 );


    Reply
  • 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... :-)

    Pascal

    Reply
  • 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... :-)

    Pascal

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

Top White Papers and Webcasts

  • Live Event Date: October 29, 2014 @ 11:00 a.m. ET / 8:00 a.m. PT Are you interested in building a cognitive application using the power of IBM Watson? Need a platform that provides speed and ease for rapidly deploying this application? Join Chris Madison, Watson Solution Architect, as he walks through the process of building a Watson powered application on IBM Bluemix. Chris will talk about the new Watson Services just released on IBM bluemix, but more importantly he will do a step by step cognitive …

  • Live Event Date: October 23, 2014 @ 12:00 p.m. ET / 9:00 a.m. PT Despite the current "virtualize everything" mentality, there are advantages to utilizing physical hardware for certain tasks. This is especially true for backups. In many cases, it is clearly in an organization's best interest to make use of physical, purpose-built backup appliances rather than relying on virtual backup software (VBA - Virtual Backup Appliances). Join us for this eSeminar to learn why physical appliances are preferable to …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds