Copying Graphical Data via Enhanced Meta File
Posted
by Oliver Eichler
on August 6th, 1998
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:00amOriginally 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...
ReplyThanks in advance!!!
how to copy selected region in graph
Posted by Legacy on 08/15/2002 12:00amOriginally 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
ReplyIs there some changes in OfficeXP for handling enhance metafile ?
Posted by Legacy on 01/23/2002 12:00amOriginally 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.
ReplyHow 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:00amOriginally 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.
Replynot working inside an ATL control !
Posted by Legacy on 01/07/2002 12:00amOriginally posted by: shyamal
I tried the same inside an ATL ActiveX control.. Doesnt seem to be working :(
ReplyProblems with SetTextAlign
Posted by Legacy on 12/15/1999 12:00amOriginally 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 );
ReplyWorks well!
Posted by Legacy on 09/01/1999 12:00amOriginally 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
ReplyWorks well!
Posted by Legacy on 09/01/1999 12:00amOriginally 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