Printkernel.h 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #ifndef __PRINT_KERNEL_20150902__
  2. #define __PRINT_KERNEL_20150902__
  3. #pragma once
  4. //////////////////////////////////////////////////////////////////////////
  5. // caculate the logic x and y, change into physics x and y.(int printer DC)
  6. #define CALCF(x) (-MulDiv(x, GetDeviceCaps(m_DC.m_hDC, LOGPIXELSY), 72))
  7. #define CALCY(y) (MulDiv(y, GetDeviceCaps(m_DC.m_hDC, LOGPIXELSY), 72))
  8. #define CALCX(x) (MulDiv(x, GetDeviceCaps(m_DC.m_hDC, LOGPIXELSX), 72))
  9. // each added font can have 4 attributes
  10. #define FACE_NORMAL 0
  11. #define FACE_NORMALBOLD 1
  12. #define FACE_BIG 2
  13. #define FACE_BIGBOLD 3
  14. // for Print text, you should let it by left or right, and up or bottom
  15. // these formats can be combined with the | operator
  16. #define FORMAT_NORMAL 0 //default should be by left and top
  17. #define FORMAT_HCENTER 1 // 水平居中;
  18. #define FORMAT_VCENTER 2 // 垂直居中;
  19. #define FORMAT_RIGHT 4 // 右对齐;
  20. #define FORMAT_LEFT 8 // 左对齐;
  21. #define FORMAT_UP 16 // 上对齐;
  22. #define FORMAT_BOTTOM 32 // 下对齐;
  23. // Error-codes
  24. #define PRERR_OK 0
  25. #define PRERR_NOIMAGES 1
  26. #define PRERR_LOADBITMAPFAILED 2
  27. #define PRERR_NOGETOBJECT 3
  28. #define PRERR_NOCOMPATIBLEDC 4
  29. #define PRERR_NOSELECTOBJECT 5
  30. #define PRERR_STRETCHBLTFAILED 6
  31. #define PRERR_STARTPAGEFAILED 7
  32. #define PRERR_CANTCREATEPRINTERDC 8
  33. #define PRERR_NOBITBLT 9
  34. class CPrinter
  35. {
  36. public:
  37. CPrinter(void);
  38. ~CPrinter(void);
  39. public:
  40. int InitToPrint(TCHAR *PrinterName, int Copies = 1);
  41. int StartPrint();
  42. int StartPage();
  43. void MoveTo(int xCur, int yCur);
  44. int GetStrSize(TCHAR *str, CSize& size);
  45. int GetWidth();
  46. void NewPage();
  47. void SetDistance (int punkte);
  48. int SetMargins(int Top, int Bottom, int Left, int Right);
  49. int SetFontFace(int iFont, int iFace);
  50. int AddFont(LOGFONT *lf);
  51. int AddFont(CFont &newfont);
  52. int DrawVLine(int x_up, int y_up, int x_bottom, int y_bottom, CPen &newpen);
  53. int DrawVLine(int x_up, int y_up, int x_bottom, int y_bottom);
  54. int DrawHLine(int x_left, int y_left, int x_right, int y_right, CPen & newpen);
  55. int DrawHLine(int x_left, int y_left, int x_right, int y_right);
  56. int DrawText(TCHAR *str, CRect& m_rt, int iFont = 0, int iFace = 0, int format = FORMAT_NORMAL);
  57. int DrawText(TCHAR *str, int iFont = 0, int iFace = 0, int format = FORMAT_NORMAL);
  58. int DrawBarCode(TCHAR *str, CRect& rcBar);
  59. void EndPage();
  60. int EndPrint();
  61. public:
  62. HDC GetHDC() { return m_DC.m_hDC; };
  63. int DrawTextEx(IN LPCTSTR lpStr, IN CRect& rtStr, IN LOGFONT& lf, IN const int& nAlign);
  64. private:
  65. CDC m_DC; // 要打印的内容(所有内容都画在该DC上);
  66. HDC m_hPrinter; // 默认打印机的时候使用;
  67. CDC m_PrinterDC; // 指定打印机的时候使用;
  68. CFont* m_font[10][4]; // 存放字体的的变量;
  69. int m_nFonts; // 现有的字体数;
  70. int m_iFont; // 使用的字体索引;
  71. int m_iFace[10]; // 使用的风格索引;
  72. int m_nCopies; // 打印的份数;
  73. CSize m_WorkSize; // 纸张的物理的宽度,以打印机的像素数为准;
  74. CRect m_Margins; // 期望的页边距区域;
  75. int m_yCur; // 当前的鼠标的位置Y;
  76. int m_xCur; // 当前的鼠标的位置X;
  77. int m_Abstand; // 行间距;
  78. int m_iPage; // 当前的页数;
  79. int m_LastErrNo; // 最后一个错误值;
  80. CPrintDialog *m_pPrintDlg; // 使用打印机设置对话框;
  81. };
  82. #endif // __PRINT_KERNEL_20150902__