PrintRX.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. // PrintRX.h: interface for the CPrintRX class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #if !defined(AFX_PRINTRX_H__592C1902_0E73_4C23_A133_350A66362613__INCLUDED_)
  5. #define AFX_PRINTRX_H__592C1902_0E73_4C23_A133_350A66362613__INCLUDED_
  6. #if _MSC_VER > 1000
  7. #pragma once
  8. #endif // _MSC_VER > 1000
  9. //////////////////////////////////////////////////////////////////////////
  10. // caculate the logic x and y, change into physics x and y.(int printer DC)
  11. #define CALCF(x) (-MulDiv(x, GetDeviceCaps(m_DC.m_hDC, LOGPIXELSY), 72))
  12. #define CALCY(y) (MulDiv(y, GetDeviceCaps(m_DC.m_hDC, LOGPIXELSY), 72))
  13. #define CALCX(x) (MulDiv(x, GetDeviceCaps(m_DC.m_hDC, LOGPIXELSX), 72))
  14. // each added font can have 4 attributes
  15. #define FACE_NORMAL 0
  16. #define FACE_NORMALBOLD 1
  17. #define FACE_BIG 2
  18. #define FACE_BIGBOLD 3
  19. // for Print text, you should let it by left or right, and up or bottom
  20. // these formats can be combined with the | operator
  21. #define FORMAT_NORMAL 0 //default should be by left and top
  22. #define FORMAT_HCENTER 1
  23. #define FORMAT_VCENTER 2
  24. #define FORMAT_RIGHT 4
  25. #define FORMAT_LEFT 8
  26. #define FORMAT_UP 16
  27. #define FORMAT_BOTTOM 32
  28. // Error-codes
  29. #define PRERR_OK 0
  30. #define PRERR_NOIMAGES 1
  31. #define PRERR_LOADBITMAPFAILED 2
  32. #define PRERR_NOGETOBJECT 3
  33. #define PRERR_NOCOMPATIBLEDC 4
  34. #define PRERR_NOSELECTOBJECT 5
  35. #define PRERR_STRETCHBLTFAILED 6
  36. #define PRERR_STARTPAGEFAILED 7
  37. #define PRERR_CANTCREATEPRINTERDC 8
  38. #define PRERR_NOBITBLT 9
  39. ///////////////////////////////////////////////////////////////////////
  40. class CPrintRX
  41. {
  42. CDC m_memdc;
  43. CBitmap m_bmp;
  44. public:
  45. void GetWidHei(int &w, int &h);
  46. CDC * GetPDC();
  47. void CalcuRc(CRect &rc);
  48. void DrawRect2(CRect &rc, int mode);
  49. void MoveTo(int xCur, int yCur);
  50. int GetStrSize(char *str, CSize& size);
  51. int GetWidth();
  52. void NewPage();
  53. void EndPage();
  54. int StartPage();
  55. void SetDistance (int punkte);
  56. int SetMargins(int Top, int Bottom, int Left, int Right);
  57. int EndPrint();
  58. int StartPrint();
  59. int InitToPrint(char *PrinterName, int Copies);
  60. int SetFontFace(int iFont, BOOL bWeight, CString name);
  61. int AddFont(LOGFONT *lf);
  62. int AddFont(CFont &newfont);
  63. int DrawVLine(int x_up, int y_up, int x_bottom, int y_bottom, CPen &newpen);
  64. int DrawVLine(int x_up, int y_up, int x_bottom, int y_bottom);
  65. int DrawHLine(int x_left, int y_left, int x_right, int y_right, CPen & newpen);
  66. int DrawHLine(int x_left, int y_left, int x_right, int y_right);
  67. int DrawText(char *str, CRect& m_rt, int iFont = 0, int iFace = 0, int format = FORMAT_NORMAL);
  68. int DrawText(char *str, int iFont = 0, int iFace = 0, int format = FORMAT_NORMAL);
  69. void DrawRect(CRect& m_rt);
  70. void DrawImage(Image *pImg, CRect& m_rt);
  71. void SetColor(COLORREF col);
  72. CPrintRX();
  73. virtual ~CPrintRX();
  74. private:
  75. CDC m_DC; // device-context for printing
  76. HDC m_hPrinter; // used when given a printer name that chosed
  77. CDC m_PrinterDC; // used when no given a printer chosed, you should craeate it youeself
  78. CFont m_newfont;
  79. CFont* m_font[10][4]; // 10 different fonts with 4 different apperances for each
  80. int m_nFonts; // number of added fonts, max. 10 possible
  81. int m_iFont; // the index of fonts now
  82. int m_iFace[10]; // the index of faces in each font now
  83. int m_nCopies; // number of copies, which should printed
  84. CSize m_WorkSize; // max width/height, which the printer allowes on the paper
  85. CRect m_Margins; // desired margins
  86. int m_yCur; // cursor-position at page during the printing
  87. int m_xCur; // cursor-position at page during the printing
  88. int m_Abstand; // distance of lines in points
  89. int m_iPage; // actual page-number
  90. int m_LastErrNo; // contains in error-case the error-number. can get with GetErrorCode()
  91. CPrintDialog *m_pPrintDlg; // pointer to a various dialog-class, if desired
  92. };
  93. #endif // !defined(AFX_PRINTRX_H__592C1902_0E73_4C23_A133_350A66362613__INCLUDED_)