Visual C++6.0是開發Windows應用程序的強大工具,可是要經過它實現程序的打印功能,一直是初學者的一個難點,常常有朋友詢問如何在VC中實現打印功能,他們每每感到在MFC提供的框架內實現這個問題很複雜,不知道如何下手。本例針對這個問題,介紹一種簡單的方法實現文字串的打印功能,讀者朋友能夠在此基礎上稍微改動一下,就能夠實現文件、圖像的打印功能。
1、實現方法
在Windows操做系統下,顯示器、打印機和繪圖儀都被視爲輸出設備,正常狀況下,系統默認的輸出設備是顯示器。要使用打印機,首先須要建立一個指向打印機的設備環境句柄,而後經過該句柄調用相關的繪圖函數把所需的文字和圖形輸出至打印機上。當打印結束後,刪除這個設備環境句柄便可。
當Windows系統中安裝好打印機後,系統老是自動設置一個打印機爲系統的默認打印機,在Windows的啓動配置文件Win.ini中的[window]段中列出了帶有關鍵字device的默認打印機。下面是某一機器中Win.ini中的[Windows]字段的內容:
編程
[windows] load= run= NullPort=None device=HP LaserJet 4050(computer000),HPBFDB1,LPT1windows |
在上述關鍵字device後的字符串中,包含了系統中默認打印機的三個重要屬性,它們依次是打印機的設備名HP LaserJet 4050(computer000),驅動程序名是HPBFDB1,輸出端口爲LPT1。
爲了操縱系統默認的打印機,實現程序的打印功能,在程序中可調用API函數GetProfileString()從Win.ini文件中得到device這個設備字符串,該函數的原型爲:DWORD GetProfileString( LPCTSTR lpAppName, LPCTSTR lpKeyName, LPCTSTR lpDefault, LPTSTR lpReturnedString, DWORD nSize)。函數中lpAppName參數爲所要檢索的Win.ini文件中的字段名;lpKeyName爲字段中的關鍵字名;lpDefault爲默認的字符串;lpReturnedString爲檢索到的字符串,若是該函數沒有從lpKeyName關鍵字中檢索到相應的字符串,則kpRetrunedString返回默認字符串lpDefault;nSize爲返回字符串的長度。
獲取上述字符串後,再使用strtok()函數將該字符串進行分解,得到與打印機相關的三個屬性,做爲API函數CreateDC()建立打印機設備環境句柄的參數,CreateDC()函數若是調用成功,則爲默認打印機建立一個設備環境句柄,不然返回一個空值(NULL)。該函數的原形爲:HDC CreateDC(LPCTSTR lpszDriver,LPCTSTR lpszDevice,LPCTSTR lpszOutput,CONST DEVMODE *lpinitData)。該函數的前三個參數剛好對應打印機的三個屬性,最後一個參數爲初始化打印機驅動程序的數據,通常狀況下該參數設置爲NULL就能夠了。
在具體打印的過程當中,調用int StartDoc( HDC hdc, CONST DOCINFO *lpdi )函數來開始一個打印任務,其中參數lpdi爲一個指向DOCINFO結構的指針,該結構以下:
框架
typedef struct { int cbSize; //結構的尺寸大小; LPCTSTR lpszDocName; //文檔的名字; LPCTSTR lpszOutput; //輸出文檔名,通常狀況下爲NULL; LPCTSTR lpszDatatype;//用來記錄打印過程的數據類型,通常狀況下爲NULL; DWORD fwType; //用來支持打印工做的額外ide |
信息,通常狀況下爲NULL;
} DOCINFO, *LPDOCINFO;
開始一個打印任務後,再調用StartPage(hdcprint)函數讓打印機走紙,通知打印機有文檔將要打印;接下來的工做就是輸出數據了,這部分工做對於開發人員來講就象往計算機屏幕上輸出文字、圖像同樣容易,只不過是計算機根據當前的設備環境句柄自動將數據輸出到打印機罷了。數據打印完後,須要做一些善後處理工做,使用RestoreDC(hdcprint,-1)函數恢復打印機設備句柄、EndPage(hdcprint)函數讓打印機中止打印,最後調用EndDoc(hdcprint)函數結束上述的打印做業。
2、編程步驟
一、啓動Visual C++6.0,新建一個基於對話框的應用程序Test,在程序的對話框窗體中加入一個按鈕(Button),設置這個Button的屬性:ID=IDC_PRINT,CAPTION="打印";
二、使用Class Wizard類嚮導爲該按鈕添加一個鼠標單擊處理函數OnPrint()
三、修改TestDlg.cpp文件中的OnPrint()函數;
四、添加代碼,編譯運行程序。函數
==========================================================================================================================工具
在打印預覽對話框類中字體
- extern int nPaperSize_X ;
- extern int nPaperSize_Y ;
- extern int nOneLines;
- extern int nNextLines;
-
- typedef struct
- {
- int nMaxLine;
- int nCountPage;
- int nCurPage;
- BOOL IsPrint;
- HWND hWnd;
- HWND hListView;
- TCHAR szTag[256];
- int nTag;
- LPVOID lpVoid;
- CGridCtrlEx *pObj;
- }PRNINFO, *PPRNINFO;
- void CPreviewParentDlg::SetCallBackFun( PRINTPREVIEW pFun, PRNINFO &sPrnInfo )
- {
- memcpy(&m_PrnInfo, &sPrnInfo, sizeof(PRNINFO));
- m_pDrawInfoFun = pFun;
- m_nCount = m_PrnInfo.nMaxLine;
- m_nCountPage = 1;
- int m = m_nCount-m_OneCount;
- int n = m/m_NextCount;
- m_nCountPage += n;
- n = m%m_NextCount;
- if(n>0)
- m_nCountPage++;
- m_PrnInfo.nCountPage = m_nCountPage;
- sPrnInfo.nCountPage = m_nCountPage;
- }
- void CPreviewChildDlg::PrintDoc()
- {
- NotifyDlg Ndlg(_T("決定打印當前報表嗎?"), TRUE);
- if (Ndlg.DoModal() == IDCANCEL)
- return;
-
- PRINTDLG printInfo;
- ZeroMemory(&printInfo,sizeof(printInfo));
- printInfo.lStructSize = sizeof(printInfo);
- printInfo.hwndOwner = 0;
- printInfo.hDevMode = 0;
- printInfo.hDevNames = 0;
-
-
- printInfo.Flags = PD_RETURNDC | PD_RETURNDEFAULT | PD_ALLPAGES;
-
- PrintDlg(&printInfo);
- DWORD rst = CommDlgExtendedError();
- if(rst != 0)
- {
- printInfo.Flags = 0;
- PrintDlg(&printInfo);
- }
-
- HDC printDC=printInfo.hDC;
-
- CDC MemDc;
- MemDc.Attach(printDC);
-
- if(m_pDrawInfoFun!= NULL)
- {
- m_PrnInfo.IsPrint = TRUE;
- m_PrnInfo.nCurPage = m_CurPage;
- m_PrnInfo.nCountPage = m_CountPage;
- m_pDrawInfoFun(MemDc, m_PrnInfo);
- }
-
- MemDc.DeleteDC();}
- void CPreviewChildDlg::OnPaint()
- {
- CPaintDC dc(this);
-
-
-
- CClientDC dlgDC(this);
- SetWindowOrgEx(dlgDC.m_hDC, m_xPt, m_yPt, NULL);
- CDC MemDc;
- MemDc.CreateCompatibleDC(NULL);
- CBitmap cBitmap;
- int xP = dlgDC.GetDeviceCaps(LOGPIXELSX);
- int yP = dlgDC.GetDeviceCaps(LOGPIXELSY);
-
- DOUBLE xPix = (DOUBLE)xP*10/254;
- DOUBLE yPix = (DOUBLE)yP*10/254;
-
- cBitmap.CreateCompatibleBitmap(&dlgDC, nPaperSize_X*xPix, nPaperSize_Y*yPix);
- MemDc.SelectObject(&cBitmap);
- if(m_pDrawInfoFun!= NULL)
- {
- m_PrnInfo.IsPrint = FALSE;
- m_PrnInfo.nCurPage = m_CurPage;
- m_pDrawInfoFun(MemDc, m_PrnInfo);
- }
- dlgDC.BitBlt(xP/2, yP/2, nPaperSize_X*xPix+xP/2, nPaperSize_Y*yPix+yP/2, &MemDc, 0, 0, SRCCOPY);
-
- MemDc.DeleteDC();
- cBitmap.DeleteObject();
-
- }
=============調用打印功能類this
- void CAttendReportDlg::PrintData()
- {
- CGridCtrlEx *pGridCtrl = NULL;
- BOOL bDay = FALSE;
- if ( ((CButton*)GetDlgItem(IDC_RADIO_DAY))->GetCheck() )
- {
- pGridCtrl = m_pDayGridCtrl;
- bDay = TRUE;
- }
- else if ( ((CButton*)GetDlgItem(IDC_RADIO_MONTH))->GetCheck() )
- {
- pGridCtrl = m_pMonGridCtrl;
- }
-
- if( pGridCtrl->GetRowCount() <= 1 )
- return;
-
-
- CDC MemDc;
- HDC hdcPrint = NULL;
- CPrintDialog dlg(FALSE);
- if (m_bPrint)
- {
- PRINTDLG printInfo;
- ZeroMemory(&printInfo,sizeof(printInfo));
- printInfo.lStructSize = sizeof(printInfo);
- printInfo.hwndOwner = 0;
- printInfo.hDevMode = 0;
- printInfo.hDevNames = 0;
-
-
- printInfo.Flags = PD_RETURNDC | PD_RETURNDEFAULT | PD_ALLPAGES;
-
- PrintDlg(&printInfo);
- DWORD rst = CommDlgExtendedError();
- if(rst != 0)
- {
- printInfo.Flags = 0;
- PrintDlg(&printInfo);
- }
-
- hdcPrint=printInfo.hDC;
- }
- else
- {
- dlg.DoModal();
- hdcPrint = dlg.GetPrinterDC();
- }
-
- if(hdcPrint == NULL)
- {
- NotifyDlg Ndlg(_T("打印機初始化失敗!"));
- Ndlg.DoModal();
- return;
- }
-
- MemDc.Attach(hdcPrint);
- nPaperSize_X = MemDc.GetDeviceCaps(HORZSIZE);
- nPaperSize_Y = MemDc.GetDeviceCaps(VERTSIZE);
- int xP = GetDeviceCaps(MemDc.m_hDC, LOGPIXELSX);
- int yP = GetDeviceCaps(MemDc.m_hDC, LOGPIXELSY);
- int xPix = (DOUBLE)xP*10/254;
- int yPix = (DOUBLE)yP*10/254;
- DOUBLE fAdd = 5*yPix;
- nOneLines = (nPaperSize_Y * 0.85*yPix)/fAdd;
- nNextLines = (nPaperSize_Y * 0.85*yPix)/fAdd+1;
-
- PRNINFO PrnInfo = {0};
- PrnInfo.hListView = NULL;
- PrnInfo.hWnd = this->m_hWnd;
- PrnInfo.IsPrint = m_bPrint;
- PrnInfo.nCurPage = 1;
- PrnInfo.nMaxLine = pGridCtrl->GetRowCount()-1;
- PrnInfo.pObj = pGridCtrl;
-
- CPreviewParentDlg DlgPreView;
- CPreviewChildDlg DlgChildPreView;
- if (bDay)
- {
- DlgPreView.SetCallBackFun(PrintDayInfo, PrnInfo);
- DlgChildPreView.SetCallBackFun(PrintDayInfo, PrnInfo);
- }
- else
- {
- DlgPreView.SetCallBackFun(PrintMonInfo, PrnInfo);
- DlgChildPreView.SetCallBackFun(PrintMonInfo, PrnInfo);
- }
-
- if (!m_bPrint)
- {
- DlgPreView.DoModal();
- }
- else
- {
- DlgChildPreView.PrintDoc();
- }
- MemDc.DeleteDC();
- }
-
- void CAttendReportDlg::PrintDayInfo( CDC &memDC, PRNINFO PrnInfo )
- {
- if(memDC.m_hDC == NULL)
- return;
-
- int nCurPage = PrnInfo.nCurPage;
- BOOL IsPrint = PrnInfo.IsPrint;
- int nMaxPage = PrnInfo.nCountPage;
- HWND hWnd = PrnInfo.hWnd;
- CString csLFinality, csRFinality;
- CGridCtrlEx *pGridCtrl = PrnInfo.pObj;
- CTime time = CTime::GetCurrentTime();
- csLFinality = time.Format(_T("%Y-%m-%d %H:%M:%S"));
- csLFinality = _T("報表日期:") + csLFinality;
- csRFinality.Format(_T("第 %i 頁/共 %i 頁"), nCurPage, nMaxPage);
-
- TCHAR szTitle[] = _T("考 勤 日 報 表");
- CRect rc, rt1, rt2, rt3, rt4, rt5, rt6, rt7, rt8, rt9, rt10;
- CPen *hPenOld;
- CPen cPen;
- CFont TitleFont, DetailFont, *oldfont;
-
- TitleFont.CreateFont(-MulDiv(14,memDC.GetDeviceCaps(LOGPIXELSY),72),
- 0,0,0,FW_NORMAL,0,0,0,GB2312_CHARSET,
- OUT_STROKE_PRECIS,CLIP_STROKE_PRECIS,DRAFT_QUALITY,
- VARIABLE_PITCH|FF_SWISS,_T("黑體"));
-
- DetailFont.CreateFont(-MulDiv(10,memDC.GetDeviceCaps(LOGPIXELSY),92),
- 0,0,0,FW_NORMAL,0,0,0,GB2312_CHARSET,
- OUT_STROKE_PRECIS,CLIP_STROKE_PRECIS,DRAFT_QUALITY,
- VARIABLE_PITCH|FF_SWISS,_T("宋體"));
-
- cPen.CreatePen(PS_SOLID, 2, RGB(0, 0, 0));
-
- int xP = GetDeviceCaps(memDC.m_hDC, LOGPIXELSX);
- int yP = GetDeviceCaps(memDC.m_hDC, LOGPIXELSY);
-
- DOUBLE xPix = (DOUBLE)xP*10/254;
- DOUBLE yPix = (DOUBLE)yP*10/254;
- DOUBLE fAdd = 5*yPix;
- DOUBLE nTop = 30*yPix;
- int iStart = 0;
- DOUBLE nBottom = nTop+nOneLines*fAdd;
- if(nCurPage != 1)
- nTop = 30*yPix-fAdd;
- if(nCurPage == 2)
- iStart = nOneLines;
- if(nCurPage>2)
- iStart = nOneLines+(nCurPage - 2)*nNextLines;
-
- DOUBLE nLeft = 15*xPix;
- DOUBLE nRight = xPix*(nPaperSize_X-15);
- DOUBLE nItemWide = ((nPaperSize_X-30)/14)*xPix;
-
- DOUBLE nTextAdd = 1.5*xPix;
-
- if(IsPrint)
- {
-
- static DOCINFO di = {sizeof (DOCINFO), szTitle} ;
-
-
- if(memDC.StartDoc( &di ) < 0)
- {
- NotifyDlg dlg(_T("鏈接到打印機化敗!"));
- dlg.DoModal();
- }
- else
- {
- iStart = 0;
- nTop = 30*yPix;
- for(int iTotalPages = 1; iTotalPages<=nMaxPage; iTotalPages++)
- {
- int nCurPage = iTotalPages;
- csRFinality.Format(_T("第 %i 頁/共 %i 頁"), nCurPage, nMaxPage);
- time=CTime::GetCurrentTime();
- csLFinality = time.Format(_T("%Y-%m-%d %H:%M:%S"));
- csLFinality = _T("報表日期:") + csLFinality;
-
- if(nCurPage != 1)
- nTop = 30*yPix-fAdd;
- if(nCurPage == 2)
- iStart = nOneLines;
- if(nCurPage>2)
- iStart = nOneLines+(nCurPage - 2)*nNextLines;
-
- if(memDC.StartPage() < 0)
- {
- NotifyDlg dlg(_T("打印失敗!"));
- dlg.DoModal();
- memDC.AbortDoc();
- return;
- }
- else
- {
-
-
- oldfont = memDC.SelectObject(&TitleFont);
- int nItem = nNextLines;
- if(nCurPage == 1)
- {
- nItem = nOneLines;
- rc.SetRect(0, yPix*15, nPaperSize_X*xPix, yPix*25);
- memDC.DrawText(szTitle, &rc, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
- }
-
- memDC.SelectObject(&DetailFont);
- rc.SetRect(nLeft, nTop, nRight, nTop+fAdd);
-
- memDC.MoveTo(rc.left, rc.top);
- memDC.LineTo(rc.right, rc.top);
-
- rt1.SetRect(nLeft, nTop, rc.right -12.4*nItemWide , nTop+fAdd);
- rt2.SetRect(rt1.right, rt1.top, rt1.right + 1.5*nItemWide, rt1.bottom);
- rt3.SetRect(rt2.right, rt1.top, rt2.right + 1.5*nItemWide, rt1.bottom);
- rt4.SetRect(rt3.right, rt1.top, rt3.right + 2.2*nItemWide, rt1.bottom);
- rt5.SetRect(rt4.right, rt1.top, rt4.right + 1.6*nItemWide, rt1.bottom);
- rt6.SetRect(rt5.right, rt1.top, rt5.right + 1.6*nItemWide, rt1.bottom);
- rt7.SetRect(rt6.right, rt1.top, rt6.right + nItemWide, rt1.bottom);
- rt8.SetRect(rt7.right, rt1.top, rt7.right + nItemWide, rt1.bottom);
- rt9.SetRect(rt8.right, rt1.top, rt8.right + nItemWide, rt1.bottom);
- rt10.SetRect(rt9.right, rt1.top, rc.right, rt1.bottom);
- memDC.DrawText(_T("編 號"), &rt1, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
- memDC.DrawText(_T("姓 名"), &rt2, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
- memDC.DrawText(_T("考勤日期"), &rt3, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
- memDC.DrawText(_T("班 次"), &rt4, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
- memDC.DrawText(_T("時 段"), &rt5, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
- memDC.DrawText(_T("考勤時間"), &rt6, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
- memDC.DrawText(_T("遲到(分)"), &rt7, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
- memDC.DrawText(_T("早退(分)"), &rt8, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
- memDC.DrawText(_T("曠工(分)"), &rt9, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
- memDC.DrawText(_T("請假(分)"), &rt10, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
-
- memDC.MoveTo(rt1.right, rt1.top);
- memDC.LineTo(rt1.right, rt1.bottom);
- memDC.MoveTo(rt2.right, rt1.top);
- memDC.LineTo(rt2.right, rt1.bottom);
- memDC.MoveTo(rt3.right, rt1.top);
- memDC.LineTo(rt3.right, rt1.bottom);
- memDC.MoveTo(rt4.right, rt1.top);
- memDC.LineTo(rt4.right, rt1.bottom);
- memDC.MoveTo(rt5.right, rt1.top);
- memDC.LineTo(rt5.right, rt1.bottom);
- memDC.MoveTo(rt6.right, rt1.top);
- memDC.LineTo(rt6.right, rt1.bottom);
- memDC.MoveTo(rt7.right, rt1.top);
- memDC.LineTo(rt7.right, rt1.bottom);
- memDC.MoveTo(rt8.right, rt1.top);
- memDC.LineTo(rt8.right, rt1.bottom);
- memDC.MoveTo(rt9.right, rt1.top);
- memDC.LineTo(rt9.right, rt1.bottom);
- memDC.MoveTo(rc.left, rt1.bottom);
- memDC.LineTo(rc.right, rt1.bottom);
-
- CString strID, strName, strDate, strSID, strTime, strAttTime, strLate, strEarlier, strAbsent, strLeave;
- rc.SetRect(nLeft, nTop+fAdd, nRight, nTop+2*fAdd);
- rt1.SetRect(nLeft+nTextAdd, rc.top, rc.right-12.4*nItemWide, rc.bottom);
- rt2.SetRect(rt1.right+nTextAdd, rt1.top, rt1.right + 1.5*nItemWide, rt1.bottom);
- rt3.SetRect(rt2.right+nTextAdd, rt1.top, rt2.right + 1.5*nItemWide, rt1.bottom);
- rt4.SetRect(rt3.right+nTextAdd, rt1.top, rt3.right + 2.2*nItemWide, rt1.bottom);
- rt5.SetRect(rt4.right+nTextAdd, rt1.top, rt4.right +1.6*nItemWide, rt1.bottom);
- rt6.SetRect(rt5.right+nTextAdd, rt1.top, rt5.right + 1.6*nItemWide, rt1.bottom);
- rt7.SetRect(rt6.right+nTextAdd, rt1.top, rt6.right + nItemWide, rt1.bottom);
- rt8.SetRect(rt7.right+nTextAdd, rt1.top, rt7.right + nItemWide, rt1.bottom);
- rt9.SetRect(rt8.right+nTextAdd, rt1.top, rt8.right + nItemWide, rt1.bottom);
- rt10.SetRect(rt9.right+nTextAdd, rt1.top, rc.right, rt1.bottom);
-
- int nCountItem = pGridCtrl->GetRowCount();
- for(int i=1;i<nItem; i++)
- {
- strID = pGridCtrl->GetItemText(i+iStart, 1);
- strName = pGridCtrl->GetItemText(i+iStart, 2);
- strDate = pGridCtrl->GetItemText(i+iStart, 3);
- strSID = pGridCtrl->GetItemText(i+iStart, 4);
- strTime = pGridCtrl->GetItemText(i+iStart, 5);
- strAttTime = pGridCtrl->GetItemText(i+iStart, 6);
- strLate = pGridCtrl->GetItemText(i+iStart, 7);
- strEarlier = pGridCtrl->GetItemText(i+iStart, 8);
- strAbsent = pGridCtrl->GetItemText(i+iStart, 9);
- strLeave = pGridCtrl->GetItemText(i+iStart, 10);
-
- memDC.DrawText(strID, &rt1, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
- memDC.DrawText(strName, &rt2, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
- memDC.DrawText(strDate, &rt3, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
- memDC.DrawText(strSID, &rt4, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
- memDC.DrawText(strTime, &rt5, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
- memDC.DrawText(strAttTime, &rt6, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
- memDC.DrawText(strLate, &rt7, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
- memDC.DrawText(strEarlier, &rt8, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
- memDC.DrawText(strAbsent, &rt9, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
- memDC.DrawText(strLeave, &rt10, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
-
- memDC.MoveTo(rc.left, rc.bottom);
- memDC.LineTo(rc.right, rc.bottom);
- memDC.MoveTo(rt1.right, rt1.top);
- memDC.LineTo(rt1.right, rt1.bottom);
- memDC.MoveTo(rt2.right, rt1.top);
- memDC.LineTo(rt2.right, rt1.bottom);
- memDC.MoveTo(rt3.right, rt1.top);
- memDC.LineTo(rt3.right, rt1.bottom);
- memDC.MoveTo(rt4.right, rt1.top);
- memDC.LineTo(rt4.right, rt1.bottom);
- memDC.MoveTo(rt5.right, rt1.top);
- memDC.LineTo(rt5.right, rt1.bottom);
- memDC.MoveTo(rt6.right, rt1.top);
- memDC.LineTo(rt6.right, rt1.bottom);
- memDC.MoveTo(rt7.right, rt1.top);
- memDC.LineTo(rt7.right, rt1.bottom);
- memDC.MoveTo(rt8.right, rt1.top);
- memDC.LineTo(rt8.right, rt1.bottom);
- memDC.MoveTo(rt9.right, rt1.top);
- memDC.LineTo(rt9.right, rt1.bottom);
- memDC.MoveTo(rc.left, rt1.bottom);
- memDC.LineTo(rc.right, rt1.bottom);
-
- rc.top += fAdd;
- rc.bottom += fAdd;
- rt1.top = rc.top;
- rt1.bottom = rc.bottom;
- rt2.top = rt1.top;
- rt2.bottom = rt1.bottom;
- rt3.top = rt1.top;
- rt3.bottom = rt1.bottom;
- rt4.top = rt1.top;
- rt4.bottom = rt1.bottom;
- rt5.top = rt1.top;
- rt5.bottom = rt1.bottom;
- rt6.top = rt1.top;
- rt6.bottom = rt1.bottom;
- rt7.top = rt1.top;
- rt7.bottom = rt1.bottom;
- rt8.top = rt1.top;
- rt8.bottom = rt1.bottom;
- rt9.top = rt1.top;
- rt9.bottom = rt1.bottom;
- rt10.top = rt1.top;
- rt10.bottom = rt1.bottom;
-
- if((i+iStart+1)>=nCountItem)
- break;
- }
-
- memDC.MoveTo(rc.left, nTop);
- memDC.LineTo(rc.left, rc.top);
- memDC.MoveTo(rc.right, nTop);
- memDC.LineTo(rc.right, rc.top);
- memDC.DrawText(csLFinality, &rc, DT_LEFT | DT_VCENTER | DT_SINGLELINE);
- memDC.DrawText(csRFinality, &rc, DT_RIGHT| DT_VCENTER | DT_SINGLELINE);
- memDC.EndPage();
- memDC.SelectObject(oldfont);
- }
- }
- memDC.EndDoc();
- }
- }
- else
- {
-
-
- hPenOld = memDC.SelectObject(&cPen);
- rc.SetRect(0, 0, nPaperSize_X*xPix, nPaperSize_Y*yPix);
- memDC.Rectangle(&rc);
- memDC.SelectObject(hPenOld);
-
- oldfont = memDC.SelectObject(&TitleFont);
- int nItem = nNextLines;
- if(nCurPage == 1)
- {
- nItem = nOneLines;
- rc.SetRect(0, yPix*15, nPaperSize_X*xPix, yPix*25);
- memDC.DrawText(szTitle, &rc, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
- }
-
- memDC.SelectObject(&DetailFont);
- rc.SetRect(nLeft, nTop, nRight, nTop+fAdd);
-
- memDC.MoveTo(rc.left, rc.top);
- memDC.LineTo(rc.right, rc.top);
-
- rt1.SetRect(nLeft, nTop, rc.right -12.2*nItemWide, nTop+fAdd);
- rt2.SetRect(rt1.right, rt1.top, rt1.right + 1.5*nItemWide, rt1.bottom);
- rt3.SetRect(rt2.right, rt1.top, rt2.right + 1.5*nItemWide, rt1.bottom);
- rt4.SetRect(rt3.right, rt1.top, rt3.right + 2*nItemWide, rt1.bottom);
- rt5.SetRect(rt4.right, rt1.top, rt4.right + 1.6*nItemWide, rt1.bottom);
- rt6.SetRect(rt5.right, rt1.top, rt5.right + 1.6*nItemWide, rt1.bottom);
- rt7.SetRect(rt6.right, rt1.top, rt6.right + nItemWide, rt1.bottom);
- rt8.SetRect(rt7.right, rt1.top, rt7.right + nItemWide, rt1.bottom);
- rt9.SetRect(rt8.right, rt1.top, rt8.right + nItemWide, rt1.bottom);
- rt10.SetRect(rt9.right, rt1.top, rc.right, rt1.bottom);
- memDC.DrawText(_T("編 號"), &rt1, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
- memDC.DrawText(_T("姓 名"), &rt2, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
- memDC.DrawText(_T("考勤日期"), &rt3, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
- memDC.DrawText(_T("班 次"), &rt4, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
- memDC.DrawText(_T("時 段"), &rt5, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
- memDC.DrawText(_T("考勤時間"), &rt6, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
- memDC.DrawText(_T("遲到(分)"), &rt7, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
- memDC.DrawText(_T("早退(分)"), &rt8, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
- memDC.DrawText(_T("曠工(分)"), &rt9, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
- memDC.DrawText(_T("請假(分)"), &rt10, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
-
- memDC.MoveTo(rt1.right, rt1.top);
- memDC.LineTo(rt1.right, rt1.bottom);
- memDC.MoveTo(rt2.right, rt1.top);
- memDC.LineTo(rt2.right, rt1.bottom);
- memDC.MoveTo(rt3.right, rt1.top);
- memDC.LineTo(rt3.right, rt1.bottom);
- memDC.MoveTo(rt4.right, rt1.top);
- memDC.LineTo(rt4.right, rt1.bottom);
- memDC.MoveTo(rt5.right, rt1.top);
- memDC.LineTo(rt5.right, rt1.bottom);
- memDC.MoveTo(rt6.right, rt1.top);
- memDC.LineTo(rt6.right, rt1.bottom);
- memDC.MoveTo(rt7.right, rt1.top);
- memDC.LineTo(rt7.right, rt1.bottom);
- memDC.MoveTo(rt8.right, rt1.top);
- memDC.LineTo(rt8.right, rt1.bottom);
- memDC.MoveTo(rt9.right, rt1.top);
- memDC.LineTo(rt9.right, rt1.bottom);
- memDC.MoveTo(rc.left, rt1.bottom);
- memDC.LineTo(rc.right, rt1.bottom);
-
- CString strID, strName, strDate, strSID, strTime, strAttTime, strLate, strEarlier, strAbsent, strLeave;
- rc.SetRect(nLeft, nTop+fAdd, nRight, nTop+2*fAdd);
- rt1.SetRect(nLeft+nTextAdd, rc.top, rc.right-12.2*nItemWide, rc.bottom);
- rt2.SetRect(rt1.right+nTextAdd, rt1.top, rt1.right + 1.5*nItemWide, rt1.bottom);
- rt3.SetRect(rt2.right+nTextAdd, rt1.top, rt2.right + 1.5*nItemWide, rt1.bottom);
- rt4.SetRect(rt3.right+nTextAdd, rt1.top, rt3.right + 2*nItemWide, rt1.bottom);
- rt5.SetRect(rt4.right+nTextAdd, rt1.top, rt4.right + 1.6*nItemWide, rt1.bottom);
- rt6.SetRect(rt5.right+nTextAdd, rt1.top, rt5.right + 1.6*nItemWide, rt1.bottom);
- rt7.SetRect(rt6.right+nTextAdd, rt1.top, rt6.right + nItemWide, rt1.bottom);
- rt8.SetRect(rt7.right+nTextAdd, rt1.top, rt7.right + nItemWide, rt1.bottom);
- rt9.SetRect(rt8.right+nTextAdd, rt1.top, rt8.right + nItemWide, rt1.bottom);
- rt10.SetRect(rt9.right+nTextAdd, rt1.top, rc.right, rt1.bottom);
-
- int nCountItem = pGridCtrl->GetRowCount();
- for(int i=1;i<nItem; i++)
- {
- strID = pGridCtrl->GetItemText(i+iStart, 1);
- strName = pGridCtrl->GetItemText(i+iStart, 2);
- strDate = pGridCtrl->GetItemText(i+iStart, 3);
- strSID = pGridCtrl->GetItemText(i+iStart, 4);
- strTime = pGridCtrl->GetItemText(i+iStart, 5);
- strAttTime = pGridCtrl->GetItemText(i+iStart, 6);
- strLate = pGridCtrl->GetItemText(i+iStart, 7);
- strEarlier = pGridCtrl->GetItemText(i+iStart, 8);
- strAbsent = pGridCtrl->GetItemText(i+iStart, 9);
- strLeave = pGridCtrl->GetItemText(i+iStart, 10);
-
- memDC.DrawText(strID, &rt1, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
- memDC.DrawText(strName, &rt2, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
- memDC.DrawText(strDate, &rt3, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
- memDC.DrawText(strSID, &rt4, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
- memDC.DrawText(strTime, &rt5, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
- memDC.DrawText(strAttTime, &rt6, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
- memDC.DrawText(strLate, &rt7, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
- memDC.DrawText(strEarlier, &rt8, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
- memDC.DrawText(strAbsent, &rt9, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
- memDC.DrawText(strLeave, &rt10, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
-
- memDC.MoveTo(rc.left, rc.bottom);
- memDC.LineTo(rc.right, rc.bottom);
- memDC.MoveTo(rt1.right, rt1.top);
- memDC.LineTo(rt1.right, rt1.bottom);
- memDC.MoveTo(rt2.right, rt1.top);
- memDC.LineTo(rt2.right, rt1.bottom);
- memDC.MoveTo(rt3.right, rt1.top);
- memDC.LineTo(rt3.right, rt1.bottom);
- memDC.MoveTo(rt4.right, rt1.top);
- memDC.LineTo(rt4.right, rt1.bottom);
- memDC.MoveTo(rt5.right, rt1.top);
- memDC.LineTo(rt5.right, rt1.bottom);
- memDC.MoveTo(rt6.right, rt1.top);
- memDC.LineTo(rt6.right, rt1.bottom);
- memDC.MoveTo(rt7.right, rt1.top);
- memDC.LineTo(rt7.right, rt1.bottom);
- memDC.MoveTo(rt8.right, rt1.top);
- memDC.LineTo(rt8.right, rt1.bottom);
- memDC.MoveTo(rt9.right, rt1.top);
- memDC.LineTo(rt9.right, rt1.bottom);
- memDC.MoveTo(rc.left, rt1.bottom);
- memDC.LineTo(rc.right, rt1.bottom);
-
- rc.top += fAdd;
- rc.bottom += fAdd;
- rt1.top = rc.top;
- rt1.bottom = rc.bottom;
- rt2.top = rt1.top;
- rt2.bottom = rt1.bottom;
- rt3.top = rt1.top;
- rt3.bottom = rt1.bottom;
- rt4.top = rt1.top;
- rt4.bottom = rt1.bottom;
- rt5.top = rt1.top;
- rt5.bottom = rt1.bottom;
- rt6.top = rt1.top;
- rt6.bottom = rt1.bottom;
- rt7.top = rt1.top;
- rt7.bottom = rt1.bottom;
- rt8.top = rt1.top;
- rt8.bottom = rt1.bottom;
- rt9.top = rt1.top;
- rt9.bottom = rt1.bottom;
- rt10.top = rt1.top;
- rt10.bottom = rt1.bottom;
-
- if((i+iStart+1)>=nCountItem)
- break;
- }
-
- memDC.MoveTo(rc.left, nTop);
- memDC.LineTo(rc.left, rc.top);
- memDC.MoveTo(rc.right, nTop);
- memDC.LineTo(rc.right, rc.top);
- memDC.DrawText(csLFinality, &rc, DT_LEFT| DT_VCENTER | DT_SINGLELINE);
- memDC.DrawText(csRFinality, &rc, DT_RIGHT| DT_VCENTER | DT_SINGLELINE);
-
- memDC.SelectObject(oldfont);
- memDC.SelectObject(hPenOld);
- }
- TitleFont.DeleteObject();
- DetailFont.DeleteObject();
- cPen.DeleteObject();
- }