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

  • When it comes to desktops – physical or virtual – it's all about the applications. Cloud-hosted virtual desktops are growing fast because you get local data center-class security and 24x7 access with the complete personalization and flexibility of your own desktop. Organizations make five common mistakes when it comes to planning and implementing their application management strategy. This eBook tells you what they are and how to avoid them, and offers real-life case studies on customers who didn't …

  • The impact of a data loss event can be significant. Real-time data is essential to remaining competitive. Many companies can no longer afford to rely on a truck arriving each day to take backup tapes offsite. For most companies, a cloud backup and recovery solution will eliminate, or significantly reduce, IT resources related to the mundane task of backup and allow your resources to be redeployed to more strategic projects. The cloud - can now be comfortable for you – with 100% recovery from anywhere all …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds