#ifndef __PRINT_KERNEL_20150902__ #define __PRINT_KERNEL_20150902__ #pragma once ////////////////////////////////////////////////////////////////////////// // caculate the logic x and y, change into physics x and y.(int printer DC) #define CALCF(x) (-MulDiv(x, GetDeviceCaps(m_DC.m_hDC, LOGPIXELSY), 72)) #define CALCY(y) (MulDiv(y, GetDeviceCaps(m_DC.m_hDC, LOGPIXELSY), 72)) #define CALCX(x) (MulDiv(x, GetDeviceCaps(m_DC.m_hDC, LOGPIXELSX), 72)) // each added font can have 4 attributes #define FACE_NORMAL 0 #define FACE_NORMALBOLD 1 #define FACE_BIG 2 #define FACE_BIGBOLD 3 // for Print text, you should let it by left or right, and up or bottom // these formats can be combined with the | operator #define FORMAT_NORMAL 0 //default should be by left and top #define FORMAT_HCENTER 1 // 水平居中; #define FORMAT_VCENTER 2 // 垂直居中; #define FORMAT_RIGHT 4 // 右对齐; #define FORMAT_LEFT 8 // 左对齐; #define FORMAT_UP 16 // 上对齐; #define FORMAT_BOTTOM 32 // 下对齐; // Error-codes #define PRERR_OK 0 #define PRERR_NOIMAGES 1 #define PRERR_LOADBITMAPFAILED 2 #define PRERR_NOGETOBJECT 3 #define PRERR_NOCOMPATIBLEDC 4 #define PRERR_NOSELECTOBJECT 5 #define PRERR_STRETCHBLTFAILED 6 #define PRERR_STARTPAGEFAILED 7 #define PRERR_CANTCREATEPRINTERDC 8 #define PRERR_NOBITBLT 9 class CPrinter { public: CPrinter(void); ~CPrinter(void); public: int InitToPrint(TCHAR *PrinterName, int Copies = 1); int StartPrint(); int StartPage(); void MoveTo(int xCur, int yCur); int GetStrSize(TCHAR *str, CSize& size); int GetWidth(); void NewPage(); void SetDistance (int punkte); int SetMargins(int Top, int Bottom, int Left, int Right); int SetFontFace(int iFont, int iFace); int AddFont(LOGFONT *lf); int AddFont(CFont &newfont); int DrawVLine(int x_up, int y_up, int x_bottom, int y_bottom, CPen &newpen); int DrawVLine(int x_up, int y_up, int x_bottom, int y_bottom); int DrawHLine(int x_left, int y_left, int x_right, int y_right, CPen & newpen); int DrawHLine(int x_left, int y_left, int x_right, int y_right); int DrawText(TCHAR *str, CRect& m_rt, int iFont = 0, int iFace = 0, int format = FORMAT_NORMAL); int DrawText(TCHAR *str, int iFont = 0, int iFace = 0, int format = FORMAT_NORMAL); int DrawBarCode(TCHAR *str, CRect& rcBar); void EndPage(); int EndPrint(); public: HDC GetHDC() { return m_DC.m_hDC; }; int DrawTextEx(IN LPCTSTR lpStr, IN CRect& rtStr, IN LOGFONT& lf, IN const int& nAlign); private: CDC m_DC; // 要打印的内容(所有内容都画在该DC上); HDC m_hPrinter; // 默认打印机的时候使用; CDC m_PrinterDC; // 指定打印机的时候使用; CFont* m_font[10][4]; // 存放字体的的变量; int m_nFonts; // 现有的字体数; int m_iFont; // 使用的字体索引; int m_iFace[10]; // 使用的风格索引; int m_nCopies; // 打印的份数; CSize m_WorkSize; // 纸张的物理的宽度,以打印机的像素数为准; CRect m_Margins; // 期望的页边距区域; int m_yCur; // 当前的鼠标的位置Y; int m_xCur; // 当前的鼠标的位置X; int m_Abstand; // 行间距; int m_iPage; // 当前的页数; int m_LastErrNo; // 最后一个错误值; CPrintDialog *m_pPrintDlg; // 使用打印机设置对话框; }; #endif // __PRINT_KERNEL_20150902__