How to interpret CDC::DrawText returning negative value?

Viewed 80

I am debugging some code that uses the MFC CDC Class for printing documents, and which have issues with the preview-printing for determining the total number of pages.

When comparing return values from CDC::DrawText for certain elements, I notice that when drawing to memory the return value is positive but then when drawing to printer the return value is negative.

The CDC documentations says DrawText return "The height of the text if the function is successful."
What does a negative value mean?

1 Answers

This is caused by the fact that your two CDC's (memory and printer) have been placed in different mapping modes.

For example, when the CDC's underlying device context is in MM_TEXT mode, then positive y is down whereas, in (most) other modes, positive 'y' is up. A quick test on my own system (albeit using a screen-based CDC) has shown that CDC::DrawText() returns a positive value when the DC is in MM_TEXT mode but a negative value for (e.g.) MM_ISOTROPIC or MM_HIMETRIC.

Whether or not you have explicitly changed the mapping mode for either of your CDCs, I don't know! But, even if you haven't, the MFC framework has probably "done something" to the printer device context - either before you've retrieved it or (more likely) in the OnPreparePrinting function.

Related