Place a enhanced metafile on the clipboard (uses OLE)

(1) If you don't have OLE in your project already then add this
#include < afxole.h >

and do the following during initialization
OleInitialize(NULL);

(2) The following places a metafile copy of a view on the clipboard. It can be easily modified to work with any CWnd that draws to a CDC.

void CMyView::OnEditCopyWmf() 
{ 
	tagSTGMEDIUM * data;
	CClientDC dcRef( this );
	data = new tagSTGMEDIUM;
	CMetaFileDC * dcMeta;
	dcMeta = new CMetaFileDC();
	COleDataSource* pData = new COleDataSource;
	CRect lmbr;
	GetClientRect(lmbr);
	//replace "ImageName" with a description of this image
	dcMeta->CreateEnhanced(&dcRef, NULL, NULL,"ImageName\0Copy\0\0" );
	dcMeta->SetMapMode(MM_TEXT);
	//actually draw to the device context
	OnDraw(dcMeta);
	//done drawing
	data->tymed = TYMED_ENHMF;
	data->hEnhMetaFile = dcMeta->CloseEnhanced();
	pData->CacheData( CF_ENHMETAFILE, data );
	pData->SetClipboard();
	delete dcMeta;
	delete data;
}

IT Offers

Comments

  • Technological requirements wagerer of induction of the Joomla! comfort managing system.

    Posted by carpitzak on 04/16/2013 11:14am

    A compute number of 141 items of clothing were purchased in April 2012 in 29 countries [url=http://www.hollistercovfrance.fr]hollister[/url] and regions worldwide from authorised retailers. The chemicals convince about included outrageous levels of toxic phthalates [url=http://www.abercrombiesfrancevparise.fr]abercrombie france[/url] in four of the garments, and cancer-causing amines from the be contemptuous of of non-specified azo dyes in two garments. NPEs [nonylphenol ethoxylates] were establish in 89 garments (unpaid junior to two thirds of those tested), showing [url=http://www.airjordanfrpaschera.fr]jordan[/url] minuscule imbalance from the results of the untimely determining push into the being of these substances in sports clothing that was conducted in 2011. In into the compact, the vicinity of many other typical types of potentially ticklish industrial chemicals was discovered across [url=http://www.abercrombieufrancersoldes.fr]abercrombie france[/url] a covey of the products tested. Disclose of outset on, when women wanted to emulate that look, [url=http://www.airjordanspasuchera.fr]jordan[/url] they couldn’t valid mince into a stunner salon and press for the hairdresser to interrupt down slack their tresses into that ungracious, just-below-the-ears style. Uncountable hairdressers [url=http://www.hollisterfrancevmagusin.fr]hollister[/url] unreserved doused refused to carry out the numbing and tenderly moot put in proper for And some didn’t separate how to do it since they’d but continuously utilized their shears on wish suggestion [url=http://www.abercrombiexandfitchuke.co.uk]abercrombie uk[/url]. In lieu of of being deterred, the flapper waved mad those rejections and headed to the barbershop on account of the do. The barbers complied [url=http://www.monclerfranceumagasinsfr.com]doudoune moncler[/url]. You ascendancy reminisce ended a seldom months ago we shared a enticing meet with disaster styled [url=http://www.airjordanzchaussuren.com]air jordan[/url] hurl with this lilting couple. Well, today we are sharing their breathtaking betrothal photos – and then their engaging combining coming up next! You also dominion [url=http://www.michaelukorsua.com]michael kors[/url] accept this couple since they in malapropos of in truth met on the tv express Consequential Fellow-clansman! Although they didn’t begin to year until after the display, it’s joking to recall that from time to lifetime rendezvous on a tv make known can entrust [url=http://www.hollisterucoboutiques.fr]hollister france[/url] in requital for all to speak with, right?The initial half of their spacious bombardment takes emplacement at Salvation Mountain and then it’s unreasonable to the wilderness an eye to some slumberous photos with the most glorious light. And I’m fully loving Dani’s assemblage choices too! Matchless impulse seeing that [url=http://patrimoine.agglo-troyes.fr/BAM/louboutinpascher.html]louboutin pas cher[/url] those of you planning your engagement photos now.

    Reply
  • La 2e lieu Revient a juin chaussure de Stuart Weitzman au talon aiguille en metal, Suivi subservient Jimmy Choo sandales juin. Jordan

    Posted by Vetriatszy on 03/15/2013 01:42pm

    ABERCROMBIE LANGE t private information is owned by more youthful, thigh users which are not uneasy to hair the money on their sequence and would like to get accepted. this amazing, woman enjoyment in huge individuality homeowners and gives yearnings concerning becoming incredible. realistically, clothing is good believe to help highlight someone different who the simplest way pretty awesome attractive force unique Going Here abilities. using the reasonably lawsuits, young ladies has become peak place emphasis a tad too. This is disposing of crash in this way within his or her a youngster so, who would delight in having have great new home appliances combined with trendy look and feel eachtime over and above for just a social meeting. Partage diffrents fashion diffrent faire briller l'astigmatisme dans l'instant, la femelle se 'vrrle rrtre maintenant extrmement lgant et luxueux. Dans la poursuite prs dom vie and also supplmentaire et. the monde des marques bien connues Abercrombie as well as Fitch reprsente not model de way, Une way de la compete relle. Au cours du sicle Abercrombie pas cher pass, 19e durante raison, united nations homme jee, Appel steve Abercrombie, A ouverlonger l. a,chicago chris are friends,james. Gwyneth Paltrow existants Vous l. a,chicago manire never ze fondre et en compltfillt l'ensemble des cramique lisr cheveux friss Royaume-Uni Aber

    Reply
  • How to send the text in a dialog box to clipboard

    Posted by Legacy on 10/24/2002 12:00am

    Originally posted by: Vidya Rajkumar

    I have some 4 edit boxes in a dialog.

    For eg.

    Name Vidya
    Age 23
    Sex Female
    occupation S/W Engineer


    Assume that these are the controls in a single dialog box.

    What i want is,on just pressing a button in toolbar,the data has to be sent to the clipboard ..Note that the nothing is selected or focussed.

    The data in the clipboard should be in the below format
    Name Vidya
    Age 23
    Sex Female
    occupation S/W Engineer


    How is it?

    Reply
  • oops

    Posted by Legacy on 10/21/2002 12:00am

    Originally posted by: W. J. Heitler

    Sorry, I've just noticed that the SetAtribDC modification was incorported in the earlier comment.
    It's not immediately obvious how to withdraw a comment, but if someone tells me how I'll pull this one and the previous.

    Reply
  • reading attributes like text height etc

    Posted by Legacy on 10/21/2002 12:00am

    Originally posted by: W. J. Heitler

    Thank you for your code, which is very useful. When I first tried it I had crash problems, because in my standard screen drawing routine I was reading attributes in order to draw text. The following modification seems to have sorted it.
    
    

    dcMeta->SetAttribDC(dcRef.m_hAttribDC);
    OnDraw(dcMeta);
    //done drawing
    dcMeta->ReleaseAttribDC(); // not sure if needed

    I hope this comment may be helpful.

    Reply
  • Adapted solution with correct rectangle dimensions and some simplification

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

    Originally posted by: Wim

    void CMyView::OnEditCopy()
    
    {
    // Create an OLE data source on the heap
    COleDataSource *pData = new COleDataSource;
    tagSTGMEDIUM data;
    CClientDC dcRef( this );
    CMetaFileDC dcMeta;
    RECT rect;
    int iWidthMM, iHeightMM, iWidthPels, iHeightPels;

    // Determine the picture frame dimensions.
    // iWidthMM is the display width in millimeters.
    // iHeightMM is the display height in millimeters.
    // iWidthPels is the display width in pixels.
    // iHeightPels is the display height in pixels
    iWidthMM = dcRef.GetDeviceCaps(HORZSIZE);
    iHeightMM = dcRef.GetDeviceCaps(VERTSIZE);
    iWidthPels = dcRef.GetDeviceCaps(HORZRES);
    iHeightPels = dcRef.GetDeviceCaps(VERTRES);

    // Retrieve the coordinates of the client
    // rectangle, in pixels.
    GetClientRect( &rect );

    // Convert client coordinates to .01-mm units.
    // Use iWidthMM, iWidthPels, iHeightMM, and
    // iHeightPels to determine the number of
    // .01-millimeter units per pixel in the x-
    // and y-directions.
    rect.left = (rect.left * iWidthMM * 100)/iWidthPels;
    rect.top = (rect.top * iHeightMM * 100)/iHeightPels;
    rect.right = (rect.right * iWidthMM * 100)/iWidthPels;
    rect.bottom = (rect.bottom * iHeightMM * 100)/iHeightPels;

    // Replace "ImageName" with a description of this image
    dcMeta.CreateEnhanced( &dcRef, NULL, &rect,"ImageName\0Copy\0\0" );
    dcMeta.SetMapMode( MM_TEXT );
    dcMeta.SetAttribDC( dcRef );

    // Actually draw to the device context
    OnDraw( &dcMeta );
    // Done drawing

    data.tymed = TYMED_ENHMF;
    data.hEnhMetaFile = dcMeta.CloseEnhanced();

    pData->CacheData( CF_ENHMETAFILE, &data );
    pData->SetClipboard();
    }

    Reply
  • Images do not render as expected when pasted to MS Word or MS PowerPoint

    Posted by Legacy on 12/09/2001 12:00am

    Originally posted by: John W. Blakely

         Thank you for the code sample.  I used it in a very simple test application.  Within that application, I draw a box and then write "Hello, World."  However, when I cut that image and paste it into an MS Powerpoint or an MS Word document, the results are not as drawn.  In both cases, the box is visible, but test is not.  Within MS Powerpoint, I can ungroup the image and recover the tst.  The rectangle is drawn as a series of lines and I used MM_TEXT mode to draw the image.
    
    

    Some questions:
    1. Is there an agreed map mdoe that is used to cut and past objects?
    2. Is it better to use TextOut or DrawText functions?
    3. What can I do to correctly cut and paste images?

    The nest few lines contain the code I added:
    dcMeta->SetMapMode(MM_TEXT);
    //actually draw to the device context
    dcMeta->MoveTo(0, 0);
    dcMeta->LineTo(0, 20000);
    dcMeta->LineTo(20000, 20000);
    dcMeta->LineTo(20000, 0);
    dcMeta->LineTo(0, 0);
    dcMeta->TextOut(10000, 10000, "Hello, World.");
    //done drawing

    Reply
  • How do I edit enhance metafile from clipboard ?

    Posted by Legacy on 08/21/2001 12:00am

    Originally posted by: Sapto Priyono

    I have a enhance metafile which is copied from the shape of Power Point object, but after I play with PlayEnhMetaFile, this enhmetafile has uncorrect displaying (fontsize is not correct, appear bullet in the first character). Why and how do I edit this enhmetafile ?. I have edited it's enhmetaheader, but no influence for the displaying.

    Reply
  • How one can render metafile image from dialog control?

    Posted by Legacy on 04/09/2001 12:00am

    Originally posted by: Michael

    How one can render metafile image from dialog control?
    
    Like List Conrol, for instance.

    Reply
  • duplicating Alt+PrtScrn

    Posted by Legacy on 02/09/2000 12:00am

    Originally posted by: P. McLaughlin

    I cut this code, added it as shown below.  Builds & runs fine...but what I'm looking to do is essentially duplicate the Alt+PrtScrn functionality within my code.  It seems to me that the View's OnDraw(pDC) function needs to do this, but how?  Any ideas?
    
    

    Thanks,
    Patrick

    Reply
  • Loading, Please Wait ...

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

Go Deeper

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds