BUG: Win95 CreateEnhMetaFile Returns hDC with Characteristics

Last reviewed: June 5, 1996
Article ID: Q151918
The information in this article applies to:
  • Microsoft Win32 Application Programming Interface (API) included with: Microsoft Windows 95, version 4.0

SYMPTOMS

In Windows 95, calling CreateEnhMetaFile and specifying a reference printer DC (hdcRef) as the first parameter results in an hDC with characteristics of the default printer, not of the hdcRef specified.

RESOLUTION

To work around this problem, obtain the current ENHMETAHEADER information by calling GetEnhMetafileBits. Modify the appropriate members of the structure to reflect the correct values, and then call SetEnhMetafileBits() to write the modified header information back.

STATUS

Microsoft has confirmed this to be a bug in the products listed at the beginning of this article. We are researching this bug and will post new information here in the Microsoft Knowledge Base as it becomes available.

MORE INFORMATION

This problem can be demonstrated when the resolution of the device specified as hdcRef to CreateEnhMetafile is different from the resolution of the default printer.

Steps to Reproduce Problem

  1. From the Control Panel, set the default printer to print at 300 dots- per-inch (dpi).

  2. Modify the DEVMODE structure using DocumentProperties to reset this resolution to 600 dpi for your application.

  3. Create a DC using CreateDC with the modified 600 dpi DEVMODE structure from step 2, specifying the same driver, device, and port name as the default printer.

  4. Create an enhanced metafile using CreateEnhMetaFile, passing this printer DC from step 3 as the reference DC.

  5. Call GetDeviceCaps on the hDC returned from step 4, and verify that the LOGPIXELSX and LOGPIXELSY values are set to 300 dpi, which is the resolution of the default printer device, and not of the modified printer DC created in step 3. Any attempt to draw a 2x2 rectangle onto this enhanced metafile results in a 4x4 rectangle due to the 300 dpi resolution, instead of the desired 600 dpi.

  6. To work around the problem, call GetEnhMetaFileBits to obtain an ENHMETAHEADER structure. The szlDevice member of this structure specifies the resolution of the device on which the picture was created. Modify this to reflect the 600 dpi change and write the modified information back using SetEnhMetaFileBits.


Additional reference words: 4.00
KBCategory: kbgraphic kbprg kbbuglist
KBSubcategory: GdiMeta



THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: June 5, 1996
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.