




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
1、票據(jù)打印工作任務(wù):在Windows平臺(tái),通過調(diào)用CPrintDialog,實(shí)現(xiàn)POS機(jī)上的票據(jù)打印。設(shè)備:佳博GP-5860III最后實(shí)現(xiàn)的打印效果圖,如下:代碼主要功能:1. 調(diào)用CPrintDialog,使用默認(rèn)打印機(jī)打印。2. 調(diào)用CreateFont,創(chuàng)建打印字體。3. StartPage EndPage完成一頁文檔的打印。其中關(guān)鍵的幾點(diǎn):1. 當(dāng)一行顯示不下產(chǎn)品信息內(nèi)容時(shí),如何自動(dòng)換行。2. 如何調(diào)整打印字體的大小。下面是實(shí)現(xiàn)打印功能時(shí),分別封裝的幾個(gè)函數(shù)。void CPosDemoDlgMain:PrintNote() /Get the default printer CPrint
2、Dialog dlg(FALSE); dlg.GetDefaults(); /Is a default printer set up? HDC hdcPrinter = dlg.GetPrinterDC(); if (hdcPrinter = NULL) MessageBox(_T("Printer not found!"); else /Create a CDC and attach it to the default printer CDC dcPrinter; dcPrinter.Attach(hdcPrinter); /Call StartDoc() to begi
3、n printing DOCINFO docinfo; memset(&docinfo, 0, sizeof(docinfo); docinfo.cbSize = sizeof(docinfo); docinfo.lpszDocName = _T("CDC:StartDoc() Code Fragment"); /If it fails, complain and exit gracefully if (dcPrinter.StartDoc(&docinfo) < 0) MessageBox(_T("Printer not initalize
4、d."); else /Start a page if (dcPrinter.StartPage() < 0) MessageBox(_T("Could not start page"); dcPrinter.AbortDoc(); else /Actually do some printing INT y = 2, LOGO_H = 115; printLogo(&dcPrinter,y); y += LOGO_H; y += 5; /CGdiObject* pOldFont = dcPrinter.SelectStockObject(SYSTEM
5、_FONT); /CFont DataFont; /DataFont.CreatePointFont(120,_T("Arial Narrow"),&dcPrinter); CFont font; font.CreateFont( 18, / nHeight 0, / nWidth 0, / nEscapement 0, / nOrientation FW_NORMAL, / nWeight FALSE, / bItalic FALSE, / bUnderline 0, / cStrikeOut ANSI_CHARSET, / nCharSet OUT_DEFAUL
6、T_PRECIS, / nOutPrecision CLIP_DEFAULT_PRECIS, / nClipPrecision DEFAULT_QUALITY, / nQuality DEFAULT_PITCH | FF_SWISS, / nPitchAndFamily _T("Arial"); / lpszFacename CFont* def_font = dcPrinter.SelectObject(&font); printDate(&dcPrinter,y); y += 48; y = printProductList(&dcPrinter
7、,y); y += 10; printTotal(&dcPrinter, y); dcPrinter.EndPage(); dcPrinter.EndDoc(); dcPrinter.SelectObject(def_font); font.DeleteObject(); /dcPrinter.SelectObject(pOldFont); DeleteDC(hdcPrinter); void CPosDemoDlgMain:printLogo(CDC* pdc, INT sy) HDC dcMem; HBITMAP hBitmap; dcMem = CreateCompatibleD
8、C(0); hBitmap = (HBITMAP)LoadImage(AfxGetInstanceHandle(),_T("market.bmp"),IMAGE_BITMAP,0,0,LR_LOADFROMFILE|LR_CREATEDIBSECTION);/導(dǎo)入圖片 HBITMAP hOldBmp = (HBITMAP):SelectObject(dcMem, hBitmap);/把圖片選擇設(shè)備 BitBlt(pdc->m_hDC,10,sy,362,115,dcMem,0,0,SRCCOPY); /* :StretchBlt(pdc->m_hDC, 0, 0
9、, 380, 170, dcMem,0,0,575,178,SRCCOPY); */ :SelectObject(dcMem,hOldBmp); :DeleteDC(dcMem); :DeleteObject(hBitmap);void CPosDemoDlgMain:printDate(CDC* pdc,INT sy) SYSTEMTIME st; INT y = sy; WCHAR wcMonth12=_T("JAN"),_T("FEB"),_T("MAR"),_T("APR"),_T("MAY&qu
10、ot;),_T("JUN"), _T("JUL"),_T("AUG"),_T("SEP"),_T("OCT"),_T("NOV"),_T("DEC"); WCHAR am_pm =_T("am"); CString strDate; GetLocalTime(&st); if(st.wHour > 12) /Set up extension. wcscpy( am_pm, _T("pm"); if(st
11、.wHour > 12) /Convert from 24-hour st.wHour -= 12; /to 12-hour clock. if(st.wHour = 0) /Set hour to 12 if midnight. st.wHour = 12; strDate.Format(_T("%2d %s %4d %02d:%02d%s"),st.wDay, wcMonthst.wMonth-1, st.wYear, st.wHour,st.wMinute,am_pm); pdc->TextOut(5, y, strDate, strDate.GetLen
12、gth(); y += 38; pdc->MoveTo(2,y); pdc->LineTo(420,y);INT CPosDemoDlgMain:printProductList(CDC* pdc, INT sy)UINT i; INT x, y = sy; INT WIDTH = 188; INT len = 0, height, left, width; CRect rc(2,y,WIDTH,y+40); ProductList *pProduct = NULL;for (i=0; i< giProductListNum; i+) rc.left = 2; rc.top
13、= y; rc.right = rc.left + WIDTH; rc.bottom = y+40; pProduct = gProductList+i; height = pdc->DrawText(pProduct->wsName, -1, &rc, DT_CALCRECT|DT_LEFT|DT_TOP|DT_WORDBREAK); pdc->DrawText(pProduct->wsName, -1, &rc, DT_LEFT|DT_TOP|DT_WORDBREAK); /draw number width = 20; rc.right = rc.
14、left + WIDTH; rc.right += 10; rc.right += width; rc.left = rc.right - width; pdc->DrawText(pProduct->wsNum, -1, &rc, DT_RIGHT|DT_TOP); width = 6; rc.right += 2; rc.right += width; rc.left = rc.right - width; pdc->DrawText(L"x", -1, &rc, DT_CENTER|DT_TOP); /draw price width
15、 = 70; rc.right += 2; rc.right += width; rc.left = rc.right - width; pdc->DrawText(pProduct->wsPrice, -1, &rc, DT_RIGHT|DT_TOP|DT_SINGLELINE); /draw sub-total width = 80; rc.right += 2; rc.right += width; rc.left = rc.right - width; pdc->DrawText(pProduct->wsSubTotal, -1, &rc, DT
16、_RIGHT|DT_TOP|DT_SINGLELINE); y += height + 14; /10: 如果下一行也換行,會(huì)打印亂碼; 12: 不會(huì)亂碼; 但為了安全起見,上下兩行間隔14個(gè)像素。 pdc->MoveTo(2,y); pdc->LineTo(420,y); return y;void CPosDemoDlgMain:printTotal(CDC* pdc, INT sy)UINT i; INT x, y = sy; INT len = 0, line = 0; const INT LEFT = 2, RIGHT = 382, LINE_HEIGHT = 30; c
17、onst INT TITLE_WIDTH = 100, NUM_WIDTH = 100; CRect rc(2,y,220,y+LINE_HEIGHT);WCHAR wsBuffer256; rc.left = LEFT; rc.top = y; /draw Tax rc.top = y + line * LINE_HEIGHT; rc.bottom = rc.top + LINE_HEIGHT; rc.right = rc.left + TITLE_WIDTH; pdc->DrawText(L"Tax", -1, &rc, DT_LEFT|DT_TOP);
18、rc.left = RIGHT - NUM_WIDTH; rc.right = RIGHT; swprintf(wsBuffer, L"%d.%02d", 0, 0);pdc->DrawText(wsBuffer, -1, &rc, DT_RIGHT|DT_TOP); line+; /= /draw total rc.top = y + line * LINE_HEIGHT; rc.bottom = rc.top + LINE_HEIGHT; rc.left = LEFT; rc.right = rc.left + TITLE_WIDTH; pdc->D
19、rawText(L"Total", -1, &rc, DT_LEFT|DT_TOP); rc.left = RIGHT - NUM_WIDTH; rc.right = RIGHT;swprintf(wsBuffer, L"%d.%02d", gTotalPrice/100, gTotalPrice%100);pdc->DrawText(wsBuffer, -1, &rc, DT_RIGHT|DT_TOP); line+; /= /draw payment rc.top = y + line * LINE_HEIGHT; rc.bot
20、tom = rc.top + LINE_HEIGHT; rc.left = LEFT; rc.right = rc.left + TITLE_WIDTH; pdc->DrawText(L"Payment", -1, &rc, DT_LEFT|DT_TOP); rc.left = RIGHT - NUM_WIDTH; rc.right = RIGHT;swprintf(wsBuffer, L"%d.%02d", m_Payment/100, m_Payment%100);pdc->DrawText(wsBuffer, -1, &rc, DT_RIGHT|DT_TOP); line+; /= /draw cash change rc.top = y + line * LINE_HEIGHT; rc.bottom = rc.top + LINE_HEIGH
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 小區(qū)文化設(shè)計(jì)合同范本
- 南大版一年級(jí)心理健康第13課《我已經(jīng)長大了》課件
- 福建農(nóng)林大學(xué)金山學(xué)院《電磁場(chǎng)理論B》2023-2024學(xué)年第二學(xué)期期末試卷
- 甘肅林業(yè)職業(yè)技術(shù)學(xué)院《工程項(xiàng)目管理(B)》2023-2024學(xué)年第二學(xué)期期末試卷
- 浙江樹人學(xué)院《科研倫理與學(xué)術(shù)規(guī)范》2023-2024學(xué)年第二學(xué)期期末試卷
- 西安財(cái)經(jīng)大學(xué)行知學(xué)院《時(shí)尚、游戲與娛樂設(shè)計(jì)》2023-2024學(xué)年第二學(xué)期期末試卷
- 眉山藥科職業(yè)學(xué)院《幼兒鋼琴彈唱》2023-2024學(xué)年第二學(xué)期期末試卷
- 齊齊哈爾工程學(xué)院《數(shù)據(jù)庫原理與應(yīng)用實(shí)驗(yàn)》2023-2024學(xué)年第二學(xué)期期末試卷
- 種植合同范本
- 日志分析與問題追蹤制度
- 教育專家報(bào)告合集:年度得到:沈祖蕓全球教育報(bào)告(2023-2024)
- 兒童尿道黏膜脫垂介紹演示培訓(xùn)課件
- 下肢骨關(guān)節(jié)損傷課件
- 2023發(fā)電企業(yè)防汛工作管理辦法
- 食品安全風(fēng)險(xiǎn)評(píng)估的課件
- 復(fù)方板藍(lán)根顆粒工藝驗(yàn)證方案大全
- 信息技術(shù)拓展模塊高職PPT完整全套教學(xué)課件
- 《動(dòng)物王國開大會(huì)》說課PPT
- 春玉米套種秋黃瓜技術(shù)
- QC成果提高工業(yè)廠房基礎(chǔ)預(yù)埋地腳螺栓的精確度
- 四年級(jí)下冊(cè)勞動(dòng)技術(shù)教案
評(píng)論
0/150
提交評(píng)論