BUG: Win95 CreateEnhMetaFile Returns hDC with Characteristics

ID: Q151918


The information in this article applies to:
  • Microsoft Win32 Application Programming Interface (API), used with:
    • Microsoft Windows 95
    • Microsoft Windows NT 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 query words: 4.00

Keywords : kbNTOS400 kbSDKWin32 kbWinOS95
Version : winnt:4.0
Platform : winnt
Issue type : kbbug


Last Reviewed: June 24, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.