Path: 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 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 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=