943,742 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 2162
  • C++ RSS
Sep 7th, 2009
0

RichEdit printing!

Expand Post »
Hi everyone, 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:

C++ Syntax (Toggle Plain Text)
  1. bool PrintRTF(HWND Handle, HDC PrinterDC) {
  2. DOCINFO di = { sizeof(di) };
  3. if (!StartDoc(PrinterDC, &di)) {
  4. return false;
  5. }
  6. int cxPhysOffset = GetDeviceCaps(PrinterDC, PHYSICALOFFSETX);
  7. int cyPhysOffset = GetDeviceCaps(PrinterDC, PHYSICALOFFSETY);
  8. int cxPhys = GetDeviceCaps(PrinterDC, PHYSICALWIDTH);
  9. int cyPhys = GetDeviceCaps(PrinterDC, PHYSICALHEIGHT);
  10. SendMessage(Handle, EM_SETTARGETDEVICE, (WPARAM)PrinterDC, cxPhys / 2);
  11. FORMATRANGE fr;
  12. fr.hdc = PrinterDC;
  13. fr.hdcTarget = PrinterDC;
  14. fr.rc.left = cxPhysOffset;
  15. fr.rc.right = cxPhysOffset + cxPhys;
  16. fr.rc.top = cyPhysOffset;
  17. fr.rc.bottom = cyPhysOffset + cyPhys;
  18. SendMessage(Handle, EM_SETSEL, 0, (LPARAM)-1);
  19. SendMessage(Handle, EM_EXGETSEL, 0, (LPARAM)&fr.chrg);
  20. bool fSuccess = true;
  21. while (fr.chrg.cpMin < fr.chrg.cpMax && fSuccess) {
  22. fSuccess = StartPage(PrinterDC) > 0;
  23. if (!fSuccess) break;
  24. int cpMin = SendMessage(Handle, EM_FORMATRANGE, true, (LPARAM)&fr);
  25. if (cpMin <= fr.chrg.cpMin) {
  26. fSuccess = false;
  27. break;
  28. }
  29. fr.chrg.cpMin = cpMin;
  30. fSuccess = EndPage(PrinterDC) > 0;
  31. }
  32. SendMessage(Handle, EM_FORMATRANGE, false, 0);
  33. if (fSuccess) {
  34. EndDoc(PrinterDC);
  35. }
  36. else {
  37. AbortDoc(PrinterDC);
  38. }
  39. DeleteDC(PrinterDC);
  40. return fSuccess;
  41. }

Any thoughts?

Thanks in advance!
Similar Threads
Reputation Points: 23
Solved Threads: 0
Newbie Poster
sixstorm1 is offline Offline
5 posts
since Sep 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Add compression to my program
Next Thread in C++ Forum Timeline: Homework help: undefined reference error





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC