However, i'm trying to print text written by the user, so i don't have any idea how much pages it will take. Obviously, i won't be able to use the StartPage-EndPage structure. So how can i make this work for variable amount of text?

07-11-2011

TAZIN

I found that the Windows printing stuff can get rather complicated specially when you deal with things like: headers, trailers, margins, handling of tabs, etc.. I suggest checking out Petzold's, "Programming Windows" book for an example on printing for some basics. In order to print on multiple pages you need to calculate the number of characters that will fit on a line and the number of lines of text (for a given font) that will fit on a page. All these variables are then handled/incremented via loop(s). I hope this helps.

07-11-2011

novacain

The problem is that font size differs greatly on a printer DC and screen DC.

The 2 ways to do this are with world transformations and basic math.

Basic math uses DrawText() with DT_CALCRECT to find the required area, divide into pages and print.
The size of the printer DC can be found with GetDeviceCaps() using HORZRES and VERTRES and the printer DC
You can also use something like GetTextExtPoint32() to find the height of one line with a given font on the Printer DC. You then calc the number of pages based on the number of lines you have.
This is harder as you have to know how many lines you have and the width of a string varies depending on the actual combination of letters the string contains.

Another way is convert your print preview DC into the printer DC using scaling functions like SetViewportExtEx(), SetViewportOrgEx(), SetWindowOrgEx(), SetWindowExtEx() and SetWorldTransform().