Article View: comp.windows.ms
Article #13893Re: copying metafile to clipboard
From: Marco Papa
Date: Mon, 08 Jan 1990 06:22
Date: Mon, 08 Jan 1990 06:22
72 lines
2517 bytes
2517 bytes
In article <22139@usc.edu| papa@pollux.usc.edu (Marco Papa) writes:
|I've been trying to copying metafiles to "disk files" with no problem,
|while I had no success with copying a metafile to the Clipboard. The
|clipboard recognizes that it received a Picture, but nothing is shown.
|The following is the sample code I use, mainly taken verbatim from
|Charles Petzold book "Programming Windows". When SaveClip is false,
|the etafile is correctly saved on a disk file. When SaveClip is
|true an "empty" picture shows up in the clipboard. Any ideas?
Gee, I should have waited a couple of hours, since I just got it running.
The Clipboard seems to want a "copy" of the metafile, generated with
CopyMetafile(.., NULL). The following is the edited code that works for
the clipboard, too.
|void SetBarMetafile(HWND hWnd)
|{
| HDC hMetaDC;
| HANDLE hMF;
| HANDLE hDiskMF;
| GLOBALHANDLE hGMem;
| LPMETAFILEPICT lpMFP;
*** HANDLE hClipMF;
|
| if (SaveClip) {
| hMetaDC = CreateMetaFile(NULL);
| } else {
| hMetaDC = CreateMetaFile(szMetaFileName);
| }
| SetWindowExt(hMetaDC, 1024, 780);
|
| <<< do the GDI graphics using hMetaDC >>>
|
| hMF = CloseMetaFile(hMetaDC);
| /* copy memory metafile to disk metafile or Clipboard */
| if (hMF) {
| if (SaveClip) {
*** hClipMF = CopyMetaFile(hMF, NULL);
| hGMem = GlobalAlloc(GHND,(DWORD)sizeof(METAFILEPICT));
| lpMFP = (LPMETAFILEPICT) GlobalLock(hGMem);
|
| lpMFP->mm = MM_ANISOTROPIC;
| lpMFP->xExt = 0;
| lpMFP->yExt = 0;
|
|** lpMFP->hMF = hMF; (old)
*** lpMFP->hMF = hClipMF; (new);
| GlobalUnlock(hGMem);
|
| OpenClipboard(hWnd);
| EmptyClipboard();
| SetClipboardData(CF_METAFILEPICT, hGMem);
| CloseClipboard();
| }
| DeleteMetaFile(hMF);
| } else
| MessageBox(hWnd, "Error creating Picture", szAppName,
| MB_OK | MB_ICONHAND);
| }
|}
Enjoy.
-- Marco Papa 'Doc'
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
"Xerox sues somebody for copying?" -- David Letterman
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Technical Details
Message-ID:
<22142@usc.edu>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!usc!pollux.usc.edu!papaReferences:
<22139@usc.edu|Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!usc!pollux.usc.edu!papa From: papa@pollux.usc.edu (Marco Papa) Newsgroups: comp.windows.ms Subject: Re: copying metafile to clipboard Message-ID: <22142@usc.edu> Date: 8 Jan 90 06:22:29 GMT References: <22139@usc.edu| Sender: news@usc.edu Organization: Felsina Software, Los Angeles, CA Lines: 72