RichEdit printing!

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Sep 2009
Posts: 5
Reputation: sixstorm1 is an unknown quantity at this point 
Solved Threads: 0
sixstorm1 sixstorm1 is offline Offline
Newbie Poster

RichEdit printing!

 
0
  #1
Sep 7th, 2009
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:

  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!
Reply With Quote Quick reply to this message  
Reply

Tags
api, c++, print, richedit, win32

Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC