Hi, I am trying to print content from a Win32 richedit control, but it doesn't work. The text wraps to the half width of the page, and after printing, the text in the richedit is also messed up (word wrap to the half width of the box).

I use this unmodified code taken directly from MSDN:

Code:
bool PrintRTF(HWND Handle, HDC PrinterDC) {	
	DOCINFO di = { sizeof(di) };
	if (!StartDoc(PrinterDC, &di)) {
		return false;
	}
	int cxPhysOffset = GetDeviceCaps(PrinterDC, PHYSICALOFFSETX);
	int cyPhysOffset = GetDeviceCaps(PrinterDC, PHYSICALOFFSETY);
	int cxPhys = GetDeviceCaps(PrinterDC, PHYSICALWIDTH);
	int cyPhys = GetDeviceCaps(PrinterDC, PHYSICALHEIGHT);
	SendMessage(Handle, EM_SETTARGETDEVICE, (WPARAM)PrinterDC, cxPhys / 2);
	FORMATRANGE fr;
	fr.hdc = PrinterDC;
	fr.hdcTarget = PrinterDC;
	fr.rc.left = cxPhysOffset;
	fr.rc.right = cxPhysOffset + cxPhys;
	fr.rc.top = cyPhysOffset;
	fr.rc.bottom = cyPhysOffset + cyPhys;
	SendMessage(Handle, EM_SETSEL, 0, (LPARAM)-1);
	SendMessage(Handle, EM_EXGETSEL, 0, (LPARAM)&fr.chrg);
	bool fSuccess = true;
	while (fr.chrg.cpMin < fr.chrg.cpMax && fSuccess) {
		fSuccess = StartPage(PrinterDC) > 0;
		if (!fSuccess) break;
		int cpMin = SendMessage(Handle, EM_FORMATRANGE, true, (LPARAM)&fr);
		if (cpMin <= fr.chrg.cpMin) {
			fSuccess = false;
			break;
		}
		fr.chrg.cpMin = cpMin;
		fSuccess = EndPage(PrinterDC) > 0;
	}
	SendMessage(Handle, EM_FORMATRANGE, false, 0);
	if (fSuccess) {
		EndDoc(PrinterDC);
	 } 
	else {
		AbortDoc(PrinterDC);
	}
	DeleteDC(PrinterDC);
	return fSuccess;
}
Any thoughts?

Thanks in advance!