Re: Closing Enh Metafile device contex

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



This post has confirmation from Microsoft that you should not be calling
DeleteDC on a metafile DC. So when you're done, call CloseEnhMetaFile and
DeleteEnhMetaFile. If CloseEnhMetaFile fails, there's nothing else you can
do.

http://groups.google.com/group/microsoft.public.win32.programmer.gdi/browse_thread/thread/cc416b159911486c/2b19177e8b3c2e7e

Paul

"Paul Baker [MVP, Windows - SDK]" <paulrichardbaker@xxxxxxxxxxxxxxxx> wrote
in message news:%23mNF7l8fIHA.5180@xxxxxxxxxxxxxxxxxxxxxxx
I am going to refer you to the documentation, but it is not as clear as it
should be:

Metafile Functions:
http://msdn2.microsoft.com/en-us/library/ms534278.aspx

CreateEnhMetaFile returns an HDC and DeleteEnhMetaFile wants an
ENHMETAFILE, so you can't do that.

You want to call CloseEnhMetaFile to convert your HDC to an ENHMETAFILE.

I don't know what you're supposed to do if CreateEnhMetaFile succeeds and
CloseEnhMetaFile fails! Call DeleteDC perhaps?

Paul

"Gary Larimer" <GaryLarimer@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:A05A1F75-D111-4DE7-89EE-8168116899B7@xxxxxxxxxxxxxxxx
How can an enhanced metafile context handle, hDC, be closed without
invoking
CloseEnhMetaFile(hDC) first?

The metafile context handle, hDC, was created as:
hDC = CreateEnhMetaFile(NULL, NULL, NULL, NULL)

Is it OK to do this,
iret = DeleteEnhMetaFile(hDC)

The reason I ask has to do with error handling. If hDC is created an an
error occurs in subsequent code, before CloseEnhMetaFile(hDC) is reached,
I
would like to just close hDC and return.

Thanks for any comments\information.
--
Gary Larimer




.



Relevant Pages

  • Re: Closing Enh Metafile device contex
    ... There is a good chance that CloseEnhMetaFile calls DeleteDC itself if it ... DeleteDC on a metafile DC. ... If CloseEnhMetaFile fails, there's nothing else you ... CreateEnhMetaFile returns an HDC and DeleteEnhMetaFile wants an ...
    (microsoft.public.win32.programmer.gdi)
  • Re: Problem with Open Bitmap File
    ... > HDC hdcMem; ... > HGDIOBJ hOldSel; ... > HBITMAP hBitmap; ... > DeleteDC; ...
    (microsoft.public.pocketpc.developer)
  • HDC questions
    ... It will take care of restoring the DC state and calling DeleteDC or ReleaseDC in the destructor. ... Can I use the HDC returned by BeginPaint after I call EndPaint? ...
    (microsoft.public.win32.programmer.gdi)
  • Re: Problem with Open Bitmap File
    ... > HDC hdcMem; ... > HGDIOBJ hOldSel; ... > HBITMAP hBitmap; ... > DeleteDC; ...
    (microsoft.public.windowsce.embedded.vc)
  • Re: Closing Enh Metafile device contex
    ... I have been using the CloseEnhMetaFile() ... followed by DeleteEnhMetaFile() in error code, but it looked a bit awkward. ... You want to call CloseEnhMetaFile to convert your HDC to an ENHMETAFILE. ...
    (microsoft.public.win32.programmer.gdi)