// DLG_Corp_LXR_SF.cpp : 实现文件 // #include "stdafx.h" #include "SmsManager.h" #include "DLG_Corp_LXR_SF.h" #include "afxdialogex.h" #include "MainFrm.h" #include "..\public\Barcode\Barcode.h" #include "..\public\PictureEx\PictureEx.h" //二维码 #include "..\public\QRCode\BitBuffer.hpp" #include "..\public\QRCode\QrCode.hpp" #include "..\public\QRCode\QrDrawVC.h" using std::uint8_t; using qrcodegen::QrCode; using qrcodegen::QrSegment; using qrcodegen::QrDrawVC; // DLG_Corp_LXR_SF 对话框 IMPLEMENT_DYNAMIC(DLG_Corp_LXR_SF, CDialogEx) DLG_Corp_LXR_SF::DLG_Corp_LXR_SF(CWnd* pParent /*=NULL*/) : CDialogEx(IDD_CORP_LXR_SF, pParent) , m_strCargo(_T("")) , m_strD_Address(_T("")) , m_strD_Company(_T("")) , m_strD_Contact(_T("")) , m_strD_Mobile(_T("")) , m_strD_Tel(_T("")) , m_strDestcode(_T("")) , m_lExpressType(0) , m_strJ_Contact(_T("")) , m_strJ_Mobile(_T("")) , m_strJ_Tel(_T("")) , m_strMailNo(_T("")) , m_strRemark(_T("")) , m_lPayMethod(0) , m_fPrice(0) { m_lYWYCount = 0; m_lDefaultYWYID=0; memset(&m_SF,0,sizeof(m_SF)); m_pYWYData = NULL; m_bNew = false; } DLG_Corp_LXR_SF::~DLG_Corp_LXR_SF() { } void DLG_Corp_LXR_SF::DoDataExchange(CDataExchange* pDX) { CDialogEx::DoDataExchange(pDX); DDX_CBString(pDX, IDC_CORP_SF_CARGO, m_strCargo); DDV_MaxChars(pDX, m_strCargo, 16); DDX_Text(pDX, IDC_CORP_SF_D_ADDRESS, m_strD_Address); DDV_MaxChars(pDX, m_strD_Address, 60); DDX_Text(pDX, IDC_CORP_SF_D_COMPANY, m_strD_Company); DDV_MaxChars(pDX, m_strD_Company, 32); DDX_Text(pDX, IDC_CORP_SF_D_CONTACT, m_strD_Contact); DDV_MaxChars(pDX, m_strD_Contact, 30); DDX_Text(pDX, IDC_CORP_SF_D_MOBILE, m_strD_Mobile); DDV_MaxChars(pDX, m_strD_Mobile, 16); DDX_Text(pDX, IDC_CORP_SF_D_TEL, m_strD_Tel); DDV_MaxChars(pDX, m_strD_Tel, 16); DDX_Text(pDX, IDC_CORP_SF_DESTCODE, m_strDestcode); DDV_MaxChars(pDX, m_strDestcode, 16); DDX_CBIndex(pDX, IDC_CORP_SF_EXPRESSTYPE, m_lExpressType); DDX_Text(pDX, IDC_CORP_SF_J_CONTACT, m_strJ_Contact); DDV_MaxChars(pDX, m_strJ_Contact, 30); DDX_Text(pDX, IDC_CORP_SF_J_MOBILE, m_strJ_Mobile); DDV_MaxChars(pDX, m_strJ_Mobile, 16); DDX_Text(pDX, IDC_CORP_SF_J_TEL, m_strJ_Tel); DDV_MaxChars(pDX, m_strJ_Tel, 16); DDX_Text(pDX, IDC_CORP_SF_MAILNO, m_strMailNo); DDV_MaxChars(pDX, m_strMailNo, 60); DDX_Text(pDX, IDC_CORP_SF_REMARK, m_strRemark); DDV_MaxChars(pDX, m_strRemark, 30); DDX_CBIndex(pDX, IDC_CORP_SF_PAYMETHOD, m_lPayMethod); DDX_Control(pDX, IDC_CORP_SF_ORDER, m_B_Order); DDX_Control(pDX, IDC_CORP_SF_PRINT, m_B_Print); DDX_Control(pDX, IDC_CORP_SF_PREVIEW, m_B_Preview); DDX_Text(pDX, IDC_CORP_SF_PRICE, m_fPrice); DDV_MinMaxDouble(pDX, m_fPrice, 0, 9999999); DDX_Control(pDX, IDC_CORP_SF_J_CONTACT, m_J_Contact); DDX_Control(pDX, IDC_CORP_SF_J_MOBILE, m_E_J_Mobile); DDX_Control(pDX, IDC_CORP_SF_J_TEL, m_E_J_Tel); DDX_Control(pDX, IDC_CORP_SF_CANCEL, m_B_SFCancel); DDX_Control(pDX, IDC_CORP_SF_ROUTE, m_B_SFRoute); DDX_Control(pDX, IDC_CORP_SF_S1, m_S1); } BEGIN_MESSAGE_MAP(DLG_Corp_LXR_SF, CDialogEx) ON_BN_CLICKED(IDOK, &DLG_Corp_LXR_SF::OnBnClickedOk) ON_BN_CLICKED(IDCANCEL, &DLG_Corp_LXR_SF::OnBnClickedCancel) ON_CBN_SELCHANGE(IDC_CORP_SF_J_CONTACT, &DLG_Corp_LXR_SF::OnCbnSelchangeCorpSfJContact) ON_BN_CLICKED(IDC_CORP_SF_ORDER, &DLG_Corp_LXR_SF::OnBnClickedCorpSfOrder) ON_CBN_EDITCHANGE(IDC_CORP_SF_J_CONTACT, &DLG_Corp_LXR_SF::OnCbnEditchangeCorpSfJContact) ON_CBN_SELENDOK(IDC_CORP_SF_J_CONTACT, &DLG_Corp_LXR_SF::OnCbnSelendokCorpSfJContact) ON_CBN_CLOSEUP(IDC_CORP_SF_J_CONTACT, &DLG_Corp_LXR_SF::OnCbnCloseupCorpSfJContact) ON_MESSAGE(WM_CORP_LXR_SF_RET, On_SF_Ret) ON_BN_CLICKED(IDC_CORP_SF_CANCEL, &DLG_Corp_LXR_SF::OnBnClickedCorpSfCancel) ON_BN_CLICKED(IDC_CORP_SF_ROUTE, &DLG_Corp_LXR_SF::OnBnClickedCorpSfRoute) ON_BN_CLICKED(IDC_CORP_SF_PREVIEW, &DLG_Corp_LXR_SF::OnBnClickedCorpSfPreview) ON_BN_CLICKED(IDC_CORP_SF_PRINT, &DLG_Corp_LXR_SF::OnBnClickedCorpSfPrint) END_MESSAGE_MAP() // DLG_Corp_LXR_SF 消息处理程序 void DLG_Corp_LXR_SF::OnBnClickedOk() { // TODO: 在此添加控件通知处理程序代码 //CDialogEx::OnOK(); } void DLG_Corp_LXR_SF::OnBnClickedCancel() { // TODO: 在此添加控件通知处理程序代码 CDialogEx::OnCancel(); } void DLG_Corp_LXR_SF::SetParam(long lYWYCount, long lDefaultYWYID,ANS_Corp_LXR_YWYData * pYWYData, ANS_Corp_SFData SF,BOOL bNew) { m_lYWYCount = lYWYCount; m_lDefaultYWYID = lDefaultYWYID; m_pYWYData = pYWYData; m_bNew = bNew; m_SF = SF; } BOOL DLG_Corp_LXR_SF::OnInitDialog() { CDialogEx::OnInitDialog(); if (m_bNew) { if (m_SF.lPayType > 0) //寄送内容为发票 { if (m_SF.fPrice>=5.0f && m_SF.fPrice < 1500.0f) //小于1500寄送发票为到付 m_SF.pay_method = 2; //收方付 } } m_lPayMethod = m_SF.pay_method; m_lExpressType = m_SF.express_type; m_strMailNo = m_SF.Res_mailno; m_strDestcode = m_SF.Res_destcode; m_strD_Company = m_SF.d_company; m_strD_Contact = m_SF.d_contact; m_strD_Tel = m_SF.d_tel; m_strD_Mobile = m_SF.d_mobile; m_strD_Address = m_SF.d_address; m_fPrice = m_SF.fPrice; //默认货物类型 m_SF.Cargo_count = 1; switch (m_SF.lPayType) { case 0: m_strCargo = _T("合同"); break; default: m_strCargo = _T("发票"); break; } int lYWYSel = 0; if (m_bNew) { for (int i = 0; i < m_lYWYCount; i++) { m_J_Contact.AddString(m_pYWYData[i].szName); if (m_pYWYData[i].lYWYID == m_lDefaultYWYID) { lYWYSel = i; m_strJ_Mobile = m_pYWYData[i].szMobile; m_strJ_Tel = m_pYWYData[i].szTel; } } } else { m_strJ_Contact = m_SF.j_contact; m_strJ_Mobile = m_SF.j_mobile; m_strJ_Tel = m_SF.j_tel; } UpdateData(false); if (m_bNew) m_J_Contact.SetCurSel(lYWYSel); //选中当前业务员 if (m_bNew) { m_B_Order.EnableWindow(true); m_B_Print.EnableWindow(false); m_B_Preview.EnableWindow(false); m_B_SFCancel.EnableWindow(false); m_B_SFRoute.EnableWindow(false); m_S1.SetWindowText(_T("顺丰选项 (未下单)")); } else { m_B_Order.EnableWindow(false); m_B_Print.EnableWindow(true); m_B_Preview.EnableWindow(true); m_B_SFCancel.EnableWindow(true); m_B_SFRoute.EnableWindow(true); CString strStatus; switch (m_SF.lStatus) { case 1: strStatus = _T("已取消"); break; case 2: strStatus = _T("已收件"); break; case 3: strStatus = _T("已签收"); break; case 0: default: strStatus = _T("已下单"); break; } CString str; str.Format(_T("顺丰选项 (%s %04d.%02d.%02d %02d:%02d)"), strStatus, m_SF.tCreate.wYear, m_SF.tCreate.wMonth, m_SF.tCreate.wDay, m_SF.tCreate.wHour, m_SF.tCreate.wMinute); m_S1.SetWindowText(str); EnableInputWindows(false); //只是显示的,禁止录入 } return TRUE; // return TRUE unless you set the focus to a control // 异常: OCX 属性页应返回 FALSE } void DLG_Corp_LXR_SF::OnCbnSelchangeCorpSfJContact() { long lSel = m_J_Contact.GetCurSel(); if (lSel >= 0 && lSel <= m_lYWYCount) { m_E_J_Tel.SetWindowText(m_pYWYData[lSel].szTel); m_E_J_Mobile.SetWindowText(m_pYWYData[lSel].szMobile); } /* CString strName; m_J_Contact.GetWindowText(strName); for (int i = 0; i < m_lYWYCount; i++) { if (strName == CString(m_pYWYData[i].szName)) { m_E_J_Tel.SetWindowText(m_pYWYData[i].szTel); m_E_J_Mobile.SetWindowText(m_pYWYData[i].szMobile); break; } } */ } void DLG_Corp_LXR_SF::OnCbnEditchangeCorpSfJContact() { //OnCbnSelchangeCorpSfJContact(); } void DLG_Corp_LXR_SF::OnBnClickedCorpSfOrder() { if (!UpdateData(true)) return; CMainFrame *pFrame = (CMainFrame*)(AfxGetApp()->m_pMainWnd); if (!pFrame) return; long lSize = sizeof(REQ_Corp_SF_Add) + sizeof(ANS_Corp_SFData); BYTE * pDataSend = new BYTE[lSize]; memset(pDataSend, 0, lSize); REQ_Corp_SF_Add * pAdd = (REQ_Corp_SF_Add*)pDataSend; ANS_Corp_SFData * pSFData = (ANS_Corp_SFData *)(pDataSend + sizeof(REQ_Corp_SF_Add)); pAdd->lCount = 1; //生成客户订单号 SYSTEMTIME t; GetLocalTime(&t); #ifdef _DEBUG _stprintf(m_SF.orderid, _T("%d_%04d%02d%02d%02d"), m_SF.lCorpID, t.wYear, t.wMonth, t.wDay, t.wHour); //_stprintf(m_SF.orderid,_T("%d_%04d%02d%02d%02d%02d%02d"), m_SF.lCorpID,t.wYear, t.wMonth, t.wDay,t.wHour,t.wMinute,t.wSecond); #else _stprintf(m_SF.orderid, _T("%d_%04d%02d%02d%02d"), m_SF.lCorpID, t.wYear, t.wMonth, t.wDay, t.wHour); #endif m_SF.pay_method = m_lPayMethod; m_SF.express_type = m_lExpressType; _tcscpy(m_SF.Res_mailno, m_strMailNo ); _tcscpy(m_SF.d_company,m_strD_Company); _tcscpy(m_SF.d_contact,m_strD_Contact); _tcscpy(m_SF.d_tel,m_strD_Tel); _tcscpy(m_SF.d_mobile,m_strD_Mobile); _tcscpy(m_SF.d_address,m_strD_Address); m_SF.fPrice = m_fPrice; _tcscpy(m_SF.Cargo_name,m_strCargo); _tcscpy(m_SF.j_contact, m_strJ_Contact); _tcscpy(m_SF.j_mobile,m_strJ_Mobile); _tcscpy(m_SF.j_tel, m_strJ_Tel); _tcscpy(m_SF.remark, this->m_strRemark); *pSFData = m_SF; pFrame->SendFrame(SMSFUNC_CORP_SF_ADD, pDataSend, lSize); EnableInputWindows(false); //下单后,禁止录入内容 } void DLG_Corp_LXR_SF::OnCbnSelendokCorpSfJContact() { } void DLG_Corp_LXR_SF::OnCbnCloseupCorpSfJContact() { } BOOL DLG_Corp_LXR_SF::ProcessSocket(Socket_Head_Add *pHead, BYTE *pFrame) { BYTE * pData = new BYTE[pHead->lFrameLen]; memcpy(pData, pFrame, pHead->lFrameLen); this->PostMessage(WM_CORP_LXR_SF_RET, (WPARAM)pData, (LPARAM)pHead->lFuncType); return true; } LONG DLG_Corp_LXR_SF::On_SF_Ret(WPARAM wParam, LPARAM lParam) { BYTE *pFrame = (BYTE *)wParam; if (!pFrame) return false; long lType = (long)lParam; switch (lType) { case SMSFUNC_CORP_SF_ADD: { ANS_Corp_SF_Add * pAdd = (ANS_Corp_SF_Add *)pFrame; ANS_Corp_SFData * pData = (ANS_Corp_SFData *)(pFrame + sizeof(ANS_Corp_SF_Add)); if (pAdd->lCount <= 0 || pAdd->lErrCode != 0) { CString str; str.Format(_T("顺丰下单失败,错误代码(%d)\r\n%s"), pAdd->lErrCode, pAdd->szMemo); MessageBox(str, _T("错误"), MB_ICONWARNING); EnableInputWindows(true); //下单失败后,允许重新录入内容 } else { m_SF = *pData; m_strMailNo = m_SF.Res_mailno; m_strDestcode = m_SF.Res_destcode; m_B_Order.EnableWindow(false); m_B_Print.EnableWindow(true); m_B_Preview.EnableWindow(true); m_B_SFCancel.EnableWindow(true); m_B_SFRoute.EnableWindow(true); UpdateData(false); CString str; str.Format(_T("顺丰选项 (%s %04d.%02d.%02d %02d:%02d)"), _T("已下单"), m_SF.tCreate.wYear, m_SF.tCreate.wMonth, m_SF.tCreate.wDay, m_SF.tCreate.wHour, m_SF.tCreate.wMinute); m_S1.SetWindowText(str); str.Format(_T("顺丰下单成功,运单号:%s,可以打印运单了。"), pData->Res_mailno); //MessageBox(str, _T("提示"), MB_ICONINFORMATION); MessageBox(pAdd->szMemo, _T("提示"), MB_ICONINFORMATION); } } break; case SMSFUNC_CORP_SF_CANCEL: { ANS_Corp_SF_Cancel * pCancel = (ANS_Corp_SF_Cancel *)pFrame; if (pCancel->lErrCode != 0) { CString str; str.Format(_T("顺丰取消订单失败,错误代码(%d)\r\n%s"), pCancel->lErrCode, pCancel->szMemo); MessageBox(str, _T("错误"), MB_ICONWARNING); } else { CString str; str.Format(_T("顺丰选项 (%s %04d.%02d.%02d %02d:%02d)"), _T("已取消"), m_SF.tCreate.wYear, m_SF.tCreate.wMonth, m_SF.tCreate.wDay, m_SF.tCreate.wHour, m_SF.tCreate.wMinute); m_S1.SetWindowText(str); str.Format(_T("顺丰取消订单成功:%d\r\n%s"), pCancel->lErrCode, pCancel->szMemo); MessageBox(str, _T("信息"), MB_ICONINFORMATION); } } break; case SMSFUNC_CORP_SF_ROUTE: { ANS_Corp_SF_Route * pRoute = (ANS_Corp_SF_Route *)pFrame; if (pRoute->lErrCode != 0) { CString str; str.Format(_T("顺丰查询路由失败,错误代码(%d)\r\n%s"), pRoute->lErrCode, pRoute->szMemo); MessageBox(str, _T("错误"), MB_ICONWARNING); } else { if (pRoute->lStatus != m_SF.lStatus) //更新状态 { m_SF.lStatus = pRoute->lStatus; CString strStatus; switch (m_SF.lStatus) { case 1: strStatus = _T("已取消"); break; case 2: strStatus = _T("已收件"); break; case 3: strStatus = _T("已签收"); break; case 0: default: strStatus = _T("已下单"); break; } CString str; str.Format(_T("顺丰选项 (%s %04d.%02d.%02d %02d:%02d)"), strStatus, m_SF.tCreate.wYear, m_SF.tCreate.wMonth, m_SF.tCreate.wDay, m_SF.tCreate.wHour, m_SF.tCreate.wMinute); m_S1.SetWindowText(str); } CString strRouteMsg = pRoute->szMemo; MessageBox(strRouteMsg,_T("路由信息"), MB_ICONINFORMATION); } } break; } delete pFrame; return true; } int DLG_Corp_LXR_SF::EnableInputWindows(BOOL bEnable) { if (bEnable) { GetDlgItem(IDC_CORP_SF_PAYMETHOD)->EnableWindow(true); GetDlgItem(IDC_CORP_SF_EXPRESSTYPE)->EnableWindow(true); GetDlgItem(IDC_CORP_SF_J_CONTACT)->EnableWindow(true); GetDlgItem(IDC_CORP_SF_CARGO)->EnableWindow(true); ((CEdit*)GetDlgItem(IDC_CORP_SF_D_COMPANY))->SetReadOnly(false); ((CEdit*)GetDlgItem(IDC_CORP_SF_D_CONTACT))->SetReadOnly(false); ((CEdit*)GetDlgItem(IDC_CORP_SF_D_MOBILE))->SetReadOnly(false); ((CEdit*)GetDlgItem(IDC_CORP_SF_D_TEL))->SetReadOnly(false); ((CEdit*)GetDlgItem(IDC_CORP_SF_D_ADDRESS))->SetReadOnly(false); ((CEdit*)GetDlgItem(IDC_CORP_SF_J_MOBILE))->SetReadOnly(false); ((CEdit*)GetDlgItem(IDC_CORP_SF_J_TEL))->SetReadOnly(false); ((CEdit*)GetDlgItem(IDC_CORP_SF_PRICE))->SetReadOnly(false); ((CEdit*)GetDlgItem(IDC_CORP_SF_REMARK))->SetReadOnly(false); } else { GetDlgItem(IDC_CORP_SF_PAYMETHOD)->EnableWindow(false); GetDlgItem(IDC_CORP_SF_EXPRESSTYPE)->EnableWindow(false); GetDlgItem(IDC_CORP_SF_J_CONTACT)->EnableWindow(false); GetDlgItem(IDC_CORP_SF_CARGO)->EnableWindow(false); //((CEdit*)GetDlgItem(IDC_CORP_SF_J_CONTACT))->SetReadOnly(true); //((CEdit*)GetDlgItem(IDC_CORP_SF_CARGO))->SetReadOnly(true); ((CEdit*)GetDlgItem(IDC_CORP_SF_D_COMPANY))->SetReadOnly(true); ((CEdit*)GetDlgItem(IDC_CORP_SF_D_CONTACT))->SetReadOnly(true); ((CEdit*)GetDlgItem(IDC_CORP_SF_D_MOBILE))->SetReadOnly(true); ((CEdit*)GetDlgItem(IDC_CORP_SF_D_TEL))->SetReadOnly(true); ((CEdit*)GetDlgItem(IDC_CORP_SF_D_ADDRESS))->SetReadOnly(true); ((CEdit*)GetDlgItem(IDC_CORP_SF_J_MOBILE))->SetReadOnly(true); ((CEdit*)GetDlgItem(IDC_CORP_SF_J_TEL))->SetReadOnly(true); ((CEdit*)GetDlgItem(IDC_CORP_SF_PRICE))->SetReadOnly(true); ((CEdit*)GetDlgItem(IDC_CORP_SF_REMARK))->SetReadOnly(true); } return 0; } void DLG_Corp_LXR_SF::OnBnClickedCorpSfCancel() { CMainFrame *pFrame = (CMainFrame*)(AfxGetApp()->m_pMainWnd); if (!pFrame) return; if (m_SF.lSFID <=0 || _tcslen(m_SF.Res_mailno) <=0) { MessageBox(_T("此顺丰订单还没下单成功,无法取消订单"), _T("错误"), MB_ICONWARNING); return; } CString str; str.Format(_T("真的要取消运单号(%s)的顺丰订单吗?"), m_SF.Res_mailno); int iRet = MessageBox(str, _T("提问"), MB_ICONQUESTION | MB_YESNO | MB_DEFBUTTON2); if (iRet != IDYES) return; long lSize = sizeof(REQ_Corp_SF_Cancel); BYTE * pDataSend = new BYTE[lSize]; memset(pDataSend, 0, lSize); REQ_Corp_SF_Cancel * pCancel = (REQ_Corp_SF_Cancel*)pDataSend; pCancel->lCount = 0; pCancel->lSFID = m_SF.lSFID; _tcscpy(pCancel->orderid, m_SF.orderid); _tcscpy(pCancel->mailno, m_SF.Res_mailno); pFrame->SendFrame(SMSFUNC_CORP_SF_CANCEL, pDataSend, lSize); } void DLG_Corp_LXR_SF::OnBnClickedCorpSfRoute() { CMainFrame *pFrame = (CMainFrame*)(AfxGetApp()->m_pMainWnd); if (!pFrame) return; if (m_SF.lSFID <= 0 || _tcslen(m_SF.Res_mailno) <= 0) { MessageBox(_T("此顺丰订单还没下单成功,无法查询路由"), _T("错误"), MB_ICONWARNING); return; } long lSize = sizeof(REQ_Corp_SF_Route); BYTE * pDataSend = new BYTE[lSize]; memset(pDataSend, 0, lSize); REQ_Corp_SF_Route * pCancel = (REQ_Corp_SF_Route*)pDataSend; pCancel->lCount = 0; pCancel->lStatus = m_SF.lStatus; pCancel->lSFID = m_SF.lSFID; _tcscpy(pCancel->orderid, m_SF.orderid); _tcscpy(pCancel->mailno, m_SF.Res_mailno); pFrame->SendFrame(SMSFUNC_CORP_SF_ROUTE, pDataSend, lSize); } void DLG_Corp_LXR_SF::OnBnClickedCorpSfPreview() { try { //预览 CPrnFrame * PrnFrame = new CPrnFrame(On_Print2, On_BeginPrint2, OnPreparePrinting2, this, this, false); PrnFrame->ShowWindow(SW_SHOW); PrnFrame->UpdateWindow(); //打印 //CPrnFrame * PrnFrame = new CPrnFrame(On_Print2,On_BeginPrint2,this,this,true); } catch (...) { AfxMessageBox(_T("print error")); } } void DLG_Corp_LXR_SF::OnBnClickedCorpSfPrint() { try { //打印 CPrnFrame * PrnFrame = new CPrnFrame(On_Print2, On_BeginPrint2, OnPreparePrinting2, this, this, true); } catch (...) { AfxMessageBox(_T("print error")); } } void DLG_Corp_LXR_SF::On_Print2(CDC *pDC, CPrintInfo *pInfo, void *pVoid) { DLG_Corp_LXR_SF * pDlg = (DLG_Corp_LXR_SF *)pVoid; CMemDCLJ dc(pDC); CPen Pen,Pen2; CPen* pOldPen=NULL; CFont* pOldfont = NULL; CGdiObject * pOldBrush = NULL; CFont font1, font2, font3, font4, font5, font6, font7, font9, font12; CPoint point; int nWidth = dc.GetDeviceCaps(HORZRES); int nHeight = dc.GetDeviceCaps(VERTRES); int xLogPixPerInch = dc.GetDeviceCaps(LOGPIXELSX); int yLogPixPerInch = dc.GetDeviceCaps(LOGPIXELSY); float xmm = ((float)xLogPixPerInch / 24.5f); float ymm = ((float)yLogPixPerInch / 24.5f); font1.CreateFont(-MulDiv(10, dc.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("黑体")); font2.CreateFont(-MulDiv(10, -dc.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("Arial")); font3.CreateFont(-MulDiv(14, -dc.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("黑体")); font4.CreateFont(-MulDiv(50, -dc.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("黑体")); font5.CreateFont(-MulDiv(36, -dc.GetDeviceCaps(LOGPIXELSY), 72), 0, 0, 0, FW_BOLD, 0, 0, 0, GB2312_CHARSET, OUT_STROKE_PRECIS, CLIP_STROKE_PRECIS, DRAFT_QUALITY, VARIABLE_PITCH | FF_SWISS, _T("Arial")); font6.CreateFont(-MulDiv(30, -dc.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("黑体")); font7.CreateFont(-MulDiv(8, -dc.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("黑体")); font9.CreateFont(-MulDiv(22, -dc.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("黑体")); font12.CreateFont(-MulDiv(23, -dc.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("黑体")); dc.SetBkMode(TRANSPARENT); pOldBrush = dc.SelectStockObject(NULL_BRUSH); Pen.CreatePen(PS_SOLID, int(0.3f*xmm), RGB(0, 0, 0)); //0.1000就是我需要的0.2mm笔宽 pOldPen = dc.SelectObject(&Pen); pOldfont = dc.SelectObject(&font1); dc.SetTextColor(RGB(0, 0, 0));//设置打印颜色 CString str; float x = 0, y = 0, w = 0, h = 0; float x2 = 0, y2 = 0, w2 = 0, h2 = 0; float lxBegin = 50; float lyBegin = 5; float fRectAdd = 0.0f; UINT uMask = 0; x = lxBegin; y = lyBegin; w = 23; h = 8; //第一格 //打印顺丰Logo CString strSFLogo; TCHAR szBuf[512] = { 0 }; GetCurrentPath(szBuf); strSFLogo.Format(_T("%s%s"), szBuf, _T("SFLogo\\logo.jpg")); //strSFLogo.Format(_T("%s%s"), szBuf, _T("SFLogo\\20_20 T6.png")); x2 = x + 1; y2 = y + 0.5; w2 = w - 2; h2 = h - 1; pDlg->Draw_Image(dc->GetSafeHdc(), strSFLogo,x2,y2,w2,h2,xmm,ymm); //strSFLogo.Format(_T("%s%s"), szBuf, _T("SFLogo\\热线.png")); //x2 = x + 74; y2 = y + 0.5; w2 = 22; h2 = h - 1; //pDlg->Draw_Image(dc->GetSafeHdc(), strSFLogo, x2, y2, w2, h2, xmm, ymm); /* CImage image; image.Load(strSFLogo); if (!image.IsNull()) { SIZE iSize = { image.GetWidth(),image.GetHeight() }; pDlg->MakeRect_Pict(x2, y2, w2, h2, iSize); CRect pRect = pDlg->MakeRect(x2, y2, w2, h2, xmm, ymm); //image.Draw(dc->m_hDC, pRect); dc.SetStretchBltMode(COLORONCOLOR);//设置图像的拉伸方式 //image.StretchBlt(dc.m_hDC, 0, 0, pRect.left, pRect.top, 0, 0, pRect.Width(), pRect.Height());//将图像写入打印机设备 image.StretchBlt(dc.m_hDC, pRect); } */ //打印产品代码 dc.SelectObject(&font5); dc.DrawText(pDlg->m_SF.Res_proCode, &pDlg->MakeRect(x + 60, y, 36, h+5, xmm, ymm), DT_RIGHT | DT_SINGLELINE); //打印系统来源与时间 SYSTEMTIME t; ::GetLocalTime(&t); str.Format(_T("Mobset CRM ZJ 打印时间%d年%d月%d日 %02d:%02d"), t.wYear, t.wMonth, t.wDay, t.wHour, t.wMinute); dc.SelectObject(&font7); dc.DrawText(str, &pDlg->MakeRect(x+6.0f, y+h-0.5f, 72, 5, xmm, ymm), DT_LEFT | DT_VCENTER | DT_SINGLELINE); //第二格 //打印条码与运单号 lyBegin = lyBegin + 12; //打印运单号条码 x = lxBegin + 6; y = lyBegin; w = 82; h = 17; COLORREF clrBar = RGB(0, 0, 0); COLORREF clrSpace = RGB(255, 255, 255); Barcode128 code; char szBarCode[64] = { 0 }; strcpy(szBarCode, CW2A(pDlg->m_SF.Res_mailno)); code.Encode128B(szBarCode); code.DrawBarcode(dc.m_hDC, int((float)x*xmm + 0.5f), int((float)(y+0.5f)*ymm + 0.5f), int((float)(y + h - 1)*ymm + 0.5f), int((float)(y + h)*ymm + 0.5f), clrBar, clrSpace, int(0.41f*xmm + 0.5f)); //打印“运单号:” x = lxBegin + 3; y = lyBegin + h-0.5f; w = 82; h = 5; dc.SelectObject(&font1); //黑体,10号 //打印运单号 long lLen = _tcslen(pDlg->m_SF.Res_mailno); CString strMailNo; long lSplit = 3; for (int i = 0; i < 20; i += lSplit) //最多打印6组 { TCHAR szPrint[32] = { 0 }; _tcsncpy(szPrint, pDlg->m_SF.Res_mailno + i, lSplit); if (_tcslen(szPrint) > 0) { if (i == 0) strMailNo = szPrint; else strMailNo = strMailNo + CString(_T(" ")) + CString(szPrint); } if (_tcslen(szPrint) < lSplit) break; } dc.DrawText(CString(_T("运单号:")) + strMailNo, &pDlg->MakeRect(x, y, w, h, xmm, ymm), DT_CENTER | DT_VCENTER | DT_SINGLELINE); /* //打印T1/T4/T6/T8 x = lxBegin + 74; y = lyBegin; w = 22; h = 23; dc.Rectangle(&pDlg->MakeRect(x, y, w, h+ fRectAdd, xmm, ymm)); strSFLogo.Format(_T("%sSFLogo\\20_20 %s.png"), szBuf, pDlg->m_SF.Res_proCode); x2 = x + 0.5; y2 = y + 0.5; w2 = w - 1; h2 = h - 1; pDlg->Draw_Image(dc->GetSafeHdc(), strSFLogo, x2, y2, w2, h2, xmm, ymm); */ //第三格 //打印收件人信息 lyBegin = lyBegin + 23; //画框 x = lxBegin ; y = lyBegin; w = 96; h = 27; dc.Rectangle(&pDlg->MakeRect(x, y, w, h + fRectAdd, xmm, ymm)); //打印路由信息 str = pDlg->m_SF.Res_destRouteLabel; if (str.GetLength() <= 0) str = pDlg->m_SF.Res_destcode; dc.SelectObject(&font6); //黑体,10号 x = lxBegin+2; y = lyBegin+0.3f; w = 92; h = 10; dc.DrawText(str, &pDlg->MakeRect(x, y, w, h, xmm, ymm), DT_LEFT | DT_WORDBREAK); //打印"收"图标 strSFLogo.Format(_T("%sSFLogo\\收(7mm).png"), szBuf); x = lxBegin+0.5f; y = lyBegin+9.0f; w = 9.0f; h = 17.5f; pDlg->Draw_Image(dc->GetSafeHdc(), strSFLogo, x, y, w, h, xmm, ymm); //打印收件人 CString strMobile= pDlg->m_SF.d_mobile; CString strTel = pDlg->m_SF.d_tel; CString strCompany = pDlg->m_SF.d_company; for (int i = 0; i < 4; i++) if (4 + i < strMobile.GetLength()) strMobile.SetAt(3 + i, L'*'); for (int i = 0; i < 4; i++) if (4 + i < strTel.GetLength()) strTel.SetAt(3 + i, L'*'); str = pDlg->m_SF.d_contact; if (strMobile.GetLength() > 0) str = str + CString(_T(" ")) + strMobile; if (strTel.GetLength() > 0) str = str + CString(_T(" ")) + strTel; uMask = DT_SINGLELINE; if (strCompany.GetLength() > 0) { str = str + CString(_T("\r\n")) + strCompany; uMask = 0; } x = lxBegin+10.5f; y = lyBegin + 10.5f; w = 85; h = 7; dc.SelectObject(&font1); //黑体,10号 dc.DrawText(str, &pDlg->MakeRect(x, y, w, h, xmm, ymm), DT_LEFT | DT_VCENTER | DT_WORDBREAK | uMask); //打印地址 str = pDlg->m_SF.d_address; if (str.GetLength() > 6) for (int i = 1; i <= 5; i++) str.SetAt(str.GetLength() - i, L'*'); x = lxBegin + 10.5f; y = lyBegin + 18.0f; w = 86; h = 16; //如果需要打印COD标,则w=75,不打印为85。 dc.DrawText(str, &pDlg->MakeRect(x, y, w, h, xmm, ymm), DT_LEFT | DT_WORDBREAK); //打印COD标,暂时不用打印COD标 //strSFLogo.Format(_T("%sSFLogo\\COD图片(宽17mm高9mm).png"), szBuf); //x = lxBegin+85.5f; y = lyBegin + 10; w = 10.5f; h = 16.0f; //pDlg->Draw_Image(dc->GetSafeHdc(), strSFLogo, x, y, w, h, xmm, ymm); //第四格 lyBegin = lyBegin + 27; CString strPayMathod; switch (pDlg->m_SF.pay_method) { case 0: strPayMathod = _T("寄付月结"); break; case 1: strPayMathod = _T("寄方付"); break; case 2: strPayMathod = _T("收方付"); break; case 3: strPayMathod = _T("第三方付"); break; } //画框 x = lxBegin; y = lyBegin; w = 96; h = 26; dc.Rectangle(&pDlg->MakeRect(x, y, w, h + fRectAdd, xmm, ymm)); x = lxBegin; y = lyBegin; w = 33; h = 6; dc.Rectangle(&pDlg->MakeRect(x, y, w, h + fRectAdd, xmm, ymm)); dc.SelectObject(&font3); //黑体,10号 dc.DrawText(strPayMathod, &pDlg->MakeRect(x, y, w, h, xmm, ymm), DT_CENTER|DT_VCENTER| DT_SINGLELINE); //付款方式 x = lxBegin; y = lyBegin+6; w = 33; h = 11; dc.Rectangle(&pDlg->MakeRect(x, y, w, h + fRectAdd, xmm, ymm)); dc.SelectObject(&font12); //黑体,10号 str = pDlg->m_SF.Res_codingMapping; dc.DrawText(str, &pDlg->MakeRect(x, y, w, h, xmm, ymm), DT_CENTER | DT_VCENTER | DT_SINGLELINE); //进港信息 x = lxBegin; y = lyBegin + 6+11; w = 33; h = 9; dc.Rectangle(&pDlg->MakeRect(x, y, w, h + fRectAdd, xmm, ymm)); //dc.SelectObject(&font12); //黑体,10号 //str = pDlg->m_SF.Res_sourceTransferCode; //dc.DrawText(str, &pDlg->MakeRect(x, y, w, h, xmm, ymm), DT_CENTER | DT_VCENTER | DT_SINGLELINE); //出港信息 //打印二维码 x = lxBegin + 33 ; y = lyBegin; w = 32; h = 26; char szQRCode[600] = { 0 }; strcpy(szQRCode, CW2A(pDlg->m_SF.Res_twoDimensionCode)); QrCode qr0 = QrCode::encodeText((const char*)szQRCode, QrCode::Ecc::MEDIUM); CRect rect = pDlg->MakeRect(x+3.5, y+0.5, w-1, h-1, xmm, ymm); QrDrawVC::Draw(qr0, dc, rect); x = lxBegin+33+32; y = lyBegin; w = 10; h = 26; dc.Rectangle(&pDlg->MakeRect(x, y, w + fRectAdd, h + fRectAdd, xmm, ymm)); //打印已验视 dc.SetTextColor(RGB(192, 192, 192)); dc.SelectObject(&font9); //黑体,10号 str = _T("已验视"); dc.DrawText(str, &pDlg->MakeRect(x, y+1.5f, w, h, xmm, ymm), DT_CENTER | DT_VCENTER | DT_WORDBREAK); //已验视 dc.SetTextColor(RGB(0, 0, 0)); x = lxBegin + 33 + 32+10; y = lyBegin; w = 21; h = 17; dc.Rectangle(&pDlg->MakeRect(x, y, w, h + fRectAdd, xmm, ymm)); dc.SelectObject(&font9); //黑体,10号 str = pDlg->m_SF.Res_proName; dc.DrawText(str, &pDlg->MakeRect(x, y+1, w, h+20, xmm, ymm), DT_CENTER | DT_WORDBREAK); //产品名称 x = lxBegin + 33 + 32 + 10; y = lyBegin+17; w = 21; h = 9; dc.Rectangle(&pDlg->MakeRect(x, y, w, h + fRectAdd, xmm, ymm)); //打印A/B标 strSFLogo = _T(""); if (pDlg->m_SF.Res_abFlag[0] == L'A') strSFLogo.Format(_T("%sSFLogo\\A标.jpg"), szBuf); if (pDlg->m_SF.Res_abFlag[0] == L'B') strSFLogo.Format(_T("%sSFLogo\\B标.jpg"), szBuf); if (strSFLogo.GetLength() > 0) pDlg->Draw_Image(dc->GetSafeHdc(), strSFLogo, x + 0.5f, y + 0.5f, w - 1, h - 1, xmm, ymm); //第五格 lyBegin = lyBegin + 26; //画框 x = lxBegin; y = lyBegin; w = 96; h = 12; dc.Rectangle(&pDlg->MakeRect(x, y, w, h + fRectAdd, xmm, ymm)); //打印"寄"图标 strSFLogo.Format(_T("%sSFLogo\\寄(7mm).png"), szBuf); x = lxBegin + 0.5f; y = lyBegin + 0.5f; w = 9.0f; h = 11.0f; pDlg->Draw_Image(dc->GetSafeHdc(), strSFLogo, x, y, w, h, xmm, ymm); //打印寄件人 strMobile = pDlg->m_SF.j_mobile; strTel = pDlg->m_SF.j_tel; strCompany = pDlg->m_SF.j_company; for (int i = 0; i < 4; i++) if (4 + i < strMobile.GetLength()) strMobile.SetAt(3 + i, L'*'); for (int i = 0; i < 4; i++) if (4 + i < strTel.GetLength()) strTel.SetAt(3 + i, L'*'); str = pDlg->m_SF.j_contact; if (strMobile.GetLength() > 0) str = str + CString(_T(" ")) + strMobile; if (strTel.GetLength() > 0) str = str + CString(_T(" ")) + strTel; uMask = DT_SINGLELINE; if (strCompany.GetLength() > 0) { str = str + CString(_T("\r\n")) + strCompany; uMask = 0; } x = lxBegin + 10.5f; y = lyBegin+0.5f ; w = 85; h = 7; dc.SelectObject(&font1); //黑体,10号 dc.DrawText(str, &pDlg->MakeRect(x, y, w, h, xmm, ymm), DT_LEFT | DT_VCENTER | DT_WORDBREAK | uMask); //打印地址 str = pDlg->m_SF.j_address; if (str.GetLength() > 6) for (int i = 1; i <= 5; i++) str.SetAt(str.GetLength() - i, L'*'); x = lxBegin + 10.5f; y = lyBegin + 7.5f; w = 86; h = 16; dc.DrawText(str, &pDlg->MakeRect(x, y, w, h, xmm, ymm), DT_LEFT | DT_WORDBREAK); //第六格 lyBegin = lyBegin + 12; //打印首易Logo x = lxBegin + 1.0f; y = lyBegin + 9.5f; w = 94; h = 16; strSFLogo.Format(_T("%sSFLogo\\mobset_logo2.png"), szBuf); pDlg->Draw_Image(dc->GetSafeHdc(), strSFLogo, x, y, w, h, xmm, ymm); //画框 x = lxBegin; y = lyBegin; w = 96; h = 26; dc.Rectangle(&pDlg->MakeRect(x, y, w, h + fRectAdd, xmm, ymm)); // str.Format(_T("增值服务:\r\n托寄物:%s\r\n件数:%d\r\n备注:%s"), pDlg->m_SF.Cargo_name, pDlg->m_SF.Cargo_count,pDlg->m_SF.remark); x = lxBegin+1.0f; y = lyBegin+2.0f; w = 90; h = 26; dc.SelectObject(&font7); //黑体,8号 dc.DrawText(str, &pDlg->MakeRect(x, y, w, h, xmm, ymm), DT_LEFT | DT_WORDBREAK); str.Format(_T("\r\n实际重量是:\r\n计费重量:") ); x = lxBegin + 1.0f+33.0f; y = lyBegin + 2.0f; w = 60; h = 26; dc.DrawText(str, &pDlg->MakeRect(x, y, w, h, xmm, ymm), DT_LEFT | DT_WORDBREAK); CString strCustid = pDlg->m_SF.custid; for (int i = 0; i < 6; i++) if (2 + i < strCustid.GetLength()) strCustid.SetAt(2 + i, L'*'); str.Format(_T("\r\n月结卡号:%s\r\n费用合计:"), strCustid); x = lxBegin + 1.0f + 33.0f+30.0f; y = lyBegin + 2.0f; w = 30; h = 26; dc.DrawText(str, &pDlg->MakeRect(x, y, w, h, xmm, ymm), DT_LEFT | DT_WORDBREAK); //第七格 lyBegin = lyBegin + 26; //画框 x = lxBegin; y = lyBegin; w = 96; h = 22; dc.Rectangle(&pDlg->MakeRect(x, y, w, h + fRectAdd, xmm, ymm)); //第二格 //画虚线 lyBegin = lyBegin + 23; //PS_DASH PS_DOT PS_DASHDOT PS_DASHDOTDOT Pen2.CreatePen(PS_DASHDOTDOT, int(0.2f*xmm), RGB(0, 0, 0)); //0.1000就是我需要的0.2mm笔宽 dc.SelectObject(&Pen2); x = lxBegin; y = lyBegin ; w = 96; h = 60; dc.LineX(pDlg->MakePoint(x, y, xmm, ymm), pDlg->MakePoint(x+w, y, xmm, ymm)); //空15mm,画100*60的框 lyBegin = lyBegin + 1; dc.SelectObject(&Pen); x = lxBegin; y = lyBegin; w = 96; h = 60; dc.Rectangle(&pDlg->MakeRect(x, y, w, h, xmm, ymm)); strSFLogo.Format(_T("%s%s"), szBuf, _T("SFLogo\\logo.jpg")); x2 = x + 1; y2 = y + 0.5; w2 = 25; h2 = 7; pDlg->Draw_Image(dc->GetSafeHdc(), strSFLogo, x2, y2, w2, h2, xmm, ymm); strSFLogo.Format(_T("%s%s"), szBuf, _T("SFLogo\\热线.png")); x2 = x + 1; y2 = y + 7+0.5f; w2 = 25; h2 = 7; pDlg->Draw_Image(dc->GetSafeHdc(), strSFLogo, x2, y2, w2, h2, xmm, ymm); x = lxBegin + 29; y = lyBegin + 1.5f; w = 48; h = 9.5f; code.DrawBarcode(dc.m_hDC, int((float)x*xmm + 0.5f), int((float)y*ymm + 0.5f), int((float)(y + h - 1)*ymm + 0.5f), int((float)(y + h)*ymm + 0.5f), clrBar, clrSpace, int(0.31f*xmm + 0.5f)); //打印“运单号:” x = lxBegin + 38 + 2; y = lyBegin + 2+9.1f; w = 48; h = 6; dc.SelectObject(&font1); //黑体,10号 dc.DrawText(CString(_T("运单号:")) + strMailNo, &pDlg->MakeRect(x, y, w, h, xmm, ymm), DT_LEFT | DT_SINGLELINE); x = lxBegin; y = lyBegin; w = 27; h = 15; //dc.Rectangle(&pDlg->MakeRect(x, y, w, h, xmm, ymm)); dc.LineX(pDlg->MakePoint(x+w, y, xmm, ymm), pDlg->MakePoint(x + w, y+15, xmm, ymm)); //9、 //打印收件人 x = lxBegin + 1; y = lyBegin + 15 ; w = 6; h = 10; //dc.SelectObject(&font1); //黑体,9号 //dc.DrawText(_T("收件人"), &pDlg->MakeRect(x, y, w, h, xmm, ymm), DT_CENTER | DT_WORDBREAK); //打印"收"图标 strSFLogo.Format(_T("%sSFLogo\\收(7mm).png"), szBuf); pDlg->Draw_Image(dc->GetSafeHdc(), strSFLogo, x, y, w, h, xmm, ymm); //打印收件人信息 dc.SelectObject(&font7); //黑体,9号 x = lxBegin + 8 + 1; y = lyBegin + 15 + 1.4f; w = 96 - 8 - 1; h = 10; strMobile = pDlg->m_SF.d_mobile; strTel = pDlg->m_SF.d_tel; strCompany = pDlg->m_SF.d_company; for (int i = 0; i < 4; i++) if (4 + i < strMobile.GetLength()) strMobile.SetAt(3 + i, L'*'); for (int i = 0; i < 4; i++) if (4 + i < strTel.GetLength()) strTel.SetAt(3 + i, L'*'); str = pDlg->m_SF.d_contact; if (strMobile.GetLength() > 0) str = str + CString(_T(" ")) + strMobile; if (strTel.GetLength() > 0) str = str + CString(_T(" ")) + strTel; if (strCompany.GetLength() > 0) str = str + CString(_T(" ")) + strCompany; dc.DrawText(str, &pDlg->MakeRect(x, y, w, h, xmm, ymm), DT_LEFT | DT_SINGLELINE); x = lxBegin + 8 + 1; y = lyBegin + 15 + 1 + 4.8f; w = 96 - 8 - 1; h = 10; str = pDlg->m_SF.d_address; if (str.GetLength() > 6) for (int i = 1; i <= 5; i++) str.SetAt(str.GetLength() - i, L'*'); dc.DrawText(str, &pDlg->MakeRect(x, y, w, h, xmm, ymm), DT_LEFT | DT_SINGLELINE); x = lxBegin; y = lyBegin+15; w = 96; h = 10; dc.Rectangle(&pDlg->MakeRect(x, y, w, h, xmm, ymm)); x = lxBegin; y = lyBegin + 15; w = 8; h = 10+10; //dc.Rectangle(&pDlg->MakeRect(x, y, w, h, xmm, ymm)); dc.LineX(pDlg->MakePoint(x+w, y, xmm, ymm), pDlg->MakePoint(x + w, y + h, xmm, ymm)); //10、 //打印寄件人 x = lxBegin + 1.2f; y = lyBegin + 15+10 ; w = 6; h = 10; //dc.SelectObject(&font1); //黑体,9号 //dc.DrawText(_T("寄件人"), &pDlg->MakeRect(x, y, w, h, xmm, ymm), DT_CENTER | DT_WORDBREAK); strSFLogo.Format(_T("%sSFLogo\\寄(7mm).png"), szBuf); pDlg->Draw_Image(dc->GetSafeHdc(), strSFLogo, x, y, w, h, xmm, ymm); //打印寄件人信息 x = lxBegin + 8 + 1; y = lyBegin + 15+10 + 1.4f; w = 96 - 8 - 1; h = 10; strMobile = pDlg->m_SF.j_mobile; strTel = pDlg->m_SF.j_tel; strCompany = pDlg->m_SF.j_company; for (int i = 0; i < 4; i++) if (4 + i < strMobile.GetLength()) strMobile.SetAt(3 + i, L'*'); for (int i = 0; i < 4; i++) if (4 + i < strTel.GetLength()) strTel.SetAt(3 + i, L'*'); str = pDlg->m_SF.j_contact; if (strMobile.GetLength() > 0) str = str + CString(_T(" ")) + strMobile; if (strTel.GetLength() > 0) str = str + CString(_T(" ")) + strTel; if (strCompany.GetLength() > 0) str = str + CString(_T(" ")) + strCompany; dc.SelectObject(&font7); //黑体,9号 dc.DrawText(str, &pDlg->MakeRect(x, y, w, h, xmm, ymm), DT_LEFT | DT_SINGLELINE); x = lxBegin + 8 + 1; y = lyBegin + 15 + 10 + 1 + 4.8f; w = 96 - 8 - 1; h = 10; str = pDlg->m_SF.j_address; if (str.GetLength() > 6) for (int i = 1; i <= 5; i++) str.SetAt(str.GetLength() - i, L'*'); dc.DrawText(str, &pDlg->MakeRect(x, y, w, h, xmm, ymm), DT_LEFT | DT_SINGLELINE); x = lxBegin; y = lyBegin + 15+10+10; w = 96; h = 10; //dc.Rectangle(&pDlg->MakeRect(x, y, w, h, xmm, ymm)); dc.LineX(pDlg->MakePoint(x, y, xmm, ymm), pDlg->MakePoint(x + w, y, xmm, ymm)); //11、 str.Format(_T("付款方式:%s\r\n月结帐号:%s\r\n包裹数量:%d"), strPayMathod, strCustid, pDlg->m_SF.Cargo_count); x = lxBegin + 1; y = lyBegin + 15 + 10 + 10 + 2; w = 30; h = 25; dc.SelectObject(&font7); //黑体,8号 dc.DrawText(str, &pDlg->MakeRect(x, y, w, h, xmm, ymm), DT_LEFT | DT_WORDBREAK); str = _T("计费重量:\r\n声明价格:\r\n保价费用:"); x = lxBegin + 1 + 29; y = lyBegin + 15 + 10 + 10 + 2; w = 23; h = 25; dc.DrawText(str, &pDlg->MakeRect(x, y, w, h, xmm, ymm), DT_LEFT | DT_WORDBREAK); x = lxBegin + 1 + 29 + 20; y = lyBegin + 15 + 10 + 10 + 2; w = 23; h = 25; str = _T("包装费用:\r\n运费:\r\n费用合计:"); dc.DrawText(str, &pDlg->MakeRect(x, y, w, h, xmm, ymm), DT_LEFT | DT_WORDBREAK); //打印产品名称 CString strSFType; switch (pDlg->m_SF.express_type) { case 0: strSFType = _T("顺丰标快"); break; case 1: strSFType = _T("顺丰特惠"); break; case 2: strSFType = _T("顺丰即日"); break; case 3: strSFType = _T("顺丰次晨"); break; } //打收寄件日期 str.Format(_T("产品:%s\r\n收件员:\r\n\r\n%04d.%02d.%02d %02d:%02d"), strSFType,pDlg->m_SF.tCreate.wYear,pDlg->m_SF.tCreate.wMonth, pDlg->m_SF.tCreate.wDay, pDlg->m_SF.tCreate.wHour, pDlg->m_SF.tCreate.wMinute); x = lxBegin + 1 + 29 + 25+17; y = lyBegin + 15 + 10 + 10 + 2; w = 23; h = 25; dc.DrawText(str, &pDlg->MakeRect(x, y, w, h, xmm, ymm), DT_LEFT | DT_WORDBREAK); //打印托寄物 //str.Format(_T("企业ID:%d  托寄物:%s"), pDlg->m_SF.lCorpID,pDlg->m_SF.Cargo_name); str.Format(_T("托寄物:%s"), pDlg->m_SF.Cargo_name); x = lxBegin + 1; y = lyBegin + 15 + 10 + 10 + 16.5f; w = 96-2; h = 10; dc.DrawText(str, &pDlg->MakeRect(x, y, w, h, xmm, ymm), DT_LEFT | DT_WORDBREAK); str.Format(_T("备注:%s"), pDlg->m_SF.remark); x = lxBegin + 1; y = lyBegin + 15 + 10 + 10 + 18+2.5f; w = 96 - 20-2; h = 10; dc.DrawText(str, &pDlg->MakeRect(x, y, w, h, xmm, ymm), DT_LEFT | DT_WORDBREAK); //最后打印下单日期 //x = lxBegin + 1; y = lyBegin + 15 + 10 + 10 + 18 + 2.5f; w = 96 - 2; h = 10; //str.Format(_T("%04d.%02d.%02d %02d:%02d"), pDlg->m_SF.tCreate.wYear, pDlg->m_SF.tCreate.wMonth, pDlg->m_SF.tCreate.wDay, pDlg->m_SF.tCreate.wHour, pDlg->m_SF.tCreate.wMinute); //dc.SelectObject(&font7); //黑体,7号 //dc.DrawText(str, &pDlg->MakeRect(x, y, w, h, xmm, ymm), DT_RIGHT | DT_WORDBREAK); if (pOldBrush) dc.SelectObject(pOldBrush); if (pOldPen) dc.SelectObject(pOldPen); if (pOldfont) dc.SelectObject(pOldfont); font1.DeleteObject(); font2.DeleteObject(); font3.DeleteObject(); font4.DeleteObject(); font5.DeleteObject(); font6.DeleteObject(); font7.DeleteObject(); font9.DeleteObject(); font12.DeleteObject(); } void DLG_Corp_LXR_SF::On_Print2_b(CDC *pDC, CPrintInfo *pInfo, void *pVoid) { DLG_Corp_LXR_SF * pDlg = (DLG_Corp_LXR_SF *)pVoid; CMemDCLJ dc(pDC); CPen Pen, Pen2; CPen* pOldPen = NULL; CFont* pOldfont = NULL; CGdiObject * pOldBrush = NULL; CFont font1, font2, font3, font4, font5, font6, font7, font9, font12; CPoint point; int nWidth = dc.GetDeviceCaps(HORZRES); int nHeight = dc.GetDeviceCaps(VERTRES); int xLogPixPerInch = dc.GetDeviceCaps(LOGPIXELSX); int yLogPixPerInch = dc.GetDeviceCaps(LOGPIXELSY); float xmm = ((float)xLogPixPerInch / 24.5f); float ymm = ((float)yLogPixPerInch / 24.5f); font1.CreateFont(-MulDiv(10, dc.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("黑体")); font2.CreateFont(-MulDiv(10, -dc.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("Arial")); font3.CreateFont(-MulDiv(14, -dc.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("黑体")); font4.CreateFont(-MulDiv(50, -dc.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("黑体")); font5.CreateFont(-MulDiv(36, -dc.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("Arial")); font6.CreateFont(-MulDiv(36, -dc.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("黑体")); font7.CreateFont(-MulDiv(8, -dc.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("黑体")); font9.CreateFont(-MulDiv(9, -dc.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("黑体")); font12.CreateFont(-MulDiv(12, -dc.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("黑体")); dc.SetBkMode(TRANSPARENT); pOldBrush = dc.SelectStockObject(NULL_BRUSH); Pen.CreatePen(PS_SOLID, int(0.3f*xmm), RGB(0, 0, 0)); //0.1000就是我需要的0.2mm笔宽 pOldPen = dc.SelectObject(&Pen); pOldfont = dc.SelectObject(&font1); dc.SetTextColor(RGB(0, 0, 0));//设置打印颜色 float x = 0, y = 0, w = 0, h = 0; //第一格 //画100*90的框 float lxBegin = 5; float lyBegin = 5; x = lxBegin; y = lyBegin; w = 100; h = 90; dc.Rectangle(&pDlg->MakeRect(x, y, w, h, xmm, ymm)); //1、 //打印顺丰Logo CString strSFLogo; TCHAR szBuf[512] = { 0 }; GetCurrentPath(szBuf); strSFLogo.Format(_T("%s%s"), szBuf, _T("SF_Logo1.jpg")); CPictureEx pict; if (pict.Load(strSFLogo)) { SIZE iSize = pict.GetSize(); x = lxBegin + 2; y = lyBegin + 1; w = 25; h = 13 - 2; float w1 = (h * (float)iSize.cx) / (float)iSize.cy; float h1 = (w * (float)iSize.cy) / (float)iSize.cx; if (h1 > h) //按长计算宽,但新宽过长。 { x = x + (w - w1) / 2.0f; w = w1; } if (w1 > w) //按宽计算长,但新长过长。 { y = y + (h - h1) / 2.0f; h = h1; } pict.Draw(&dc, pDlg->MakeRect(x, y, w, h, xmm, ymm)); } strSFLogo.Format(_T("%s%s"), szBuf, _T("SF_Logo2.jpg")); CPictureEx pict2; if (pict2.Load(strSFLogo)) { SIZE iSize = pict2.GetSize(); x = lxBegin + 68; y = lyBegin + 1; w = 30; h = 13 - 2; float w1 = (h * (float)iSize.cx) / (float)iSize.cy; float h1 = (w * (float)iSize.cy) / (float)iSize.cx; if (h1 > h) //按长计算宽,但新宽过长。 { x = x + (w - w1) / 2.0f; w = w1; } if (w1 > w) //按宽计算长,但新长过长。 { y = y + (h - h1) / 2.0f; h = h1; } pict2.Draw(&dc, pDlg->MakeRect(x, y, w, h, xmm, ymm)); } //打印E标 if (pDlg->m_SF.express_type == 1) //顺丰特惠 { x = lxBegin + 31; y = lyBegin; w = 10; h = 13; dc.SelectObject(&font5); //Arial,36号 dc.DrawText(_T("E"), &pDlg->MakeRect(x, y, w, h, xmm, ymm), DT_CENTER | DT_VCENTER | DT_SINGLELINE); } //打印加急标 if (pDlg->m_SF.express_type == 2 || pDlg->m_SF.express_type == 3) //顺丰即日 顺丰次晨 { x = lxBegin + 40; y = lyBegin; w = 26; h = 13; dc.SelectObject(&font6); //黑体,36号 dc.DrawText(_T("加急"), &pDlg->MakeRect(x, y, w, h, xmm, ymm), DT_CENTER | DT_VCENTER | DT_SINGLELINE); } //2、 x = lxBegin; y = lyBegin + 13; w = 100; h = 20; dc.Rectangle(&pDlg->MakeRect(x, y, w, h, xmm, ymm)); x = lxBegin + 72; y = lyBegin + 13; w = 100 - 72; h = 20; dc.Rectangle(&pDlg->MakeRect(x, y, w, h, xmm, ymm)); x = lxBegin + 72; y = lyBegin + 13; w = 100 - 72; h = 7; dc.Rectangle(&pDlg->MakeRect(x, y, w, h, xmm, ymm)); //打印产品名称 CString str; switch (pDlg->m_SF.express_type) { case 0: str = _T("顺丰标快"); break; case 1: str = _T("顺丰特惠"); break; case 2: str = _T("顺丰即日"); break; case 3: str = _T("顺丰次晨"); break; } dc.SelectObject(&font3); //黑体,14号 dc.DrawText(str, &pDlg->MakeRect(x, y, w, h, xmm, ymm), DT_CENTER | DT_VCENTER | DT_SINGLELINE); //打印运单号条码 x = lxBegin + 3; y = lyBegin + 13 + 3; w = 60; h = 11; COLORREF clrBar = RGB(0, 0, 0); COLORREF clrSpace = RGB(255, 255, 255); Barcode128 code; char szBarCode[64] = { 0 }; strcpy(szBarCode, CW2A(pDlg->m_SF.Res_mailno)); code.Encode128B(szBarCode); code.DrawBarcode(dc.m_hDC, int((float)x*xmm + 0.5f), int((float)y*ymm + 0.5f), int((float)(y + h - 1)*ymm + 0.5f), int((float)(y + h)*ymm + 0.5f), clrBar, clrSpace, int(0.32f*xmm + 0.5f)); //打印“运单号:” x = lxBegin + 6 + 5.5f; y = lyBegin + 13 + 3 + 12; w = 60; h = 6; dc.SelectObject(&font1); //黑体,10号 //打印运单号 long lLen = _tcslen(pDlg->m_SF.Res_mailno); CString strMailNo; long lSplit = 3; for (int i = 0; i < 20; i += lSplit) //最多打印6组 { TCHAR szPrint[32] = { 0 }; _tcsncpy(szPrint, pDlg->m_SF.Res_mailno + i, lSplit); if (_tcslen(szPrint) > 0) { if (i == 0) strMailNo = szPrint; else strMailNo = strMailNo + CString(_T(" ")) + CString(szPrint); } if (_tcslen(szPrint) < lSplit) break; } dc.DrawText(CString(_T("运单号:")) + strMailNo, &pDlg->MakeRect(x, y, w, h, xmm, ymm), DT_LEFT | DT_SINGLELINE); //x = lxBegin + 6 + 5 +12; y = lyBegin + 13 + 3 + 12; w = 60; h = 6; //dc.SelectObject(&font2); //Arial,10号 //dc.DrawText(strMailNo, &pDlg->MakeRect(x, y, w, h, xmm, ymm), DT_LEFT | DT_SINGLELINE); //3、 x = lxBegin; y = lyBegin + 13 + 20; w = 8; h = 14 + 13 + 9; dc.LineX(pDlg->MakePoint(x + w, y, xmm, ymm), pDlg->MakePoint(x + w, y + h, xmm, ymm)); //打印目的地 x = lxBegin + 1; y = lyBegin + 13 + 20 + 2; w = 6; h = 14; dc.SelectObject(&font1); //黑体,10号 dc.DrawText(_T("目的地"), &pDlg->MakeRect(x, y, w, h, xmm, ymm), DT_CENTER | DT_WORDBREAK); //打印目的地代码 x = lxBegin + 8 + 1; y = lyBegin + 13 + 20; w = 100; h = 14; dc.SelectObject(&font4); //黑体,50号 dc.DrawText(pDlg->m_SF.Res_destcode, &pDlg->MakeRect(x, y, w, h, xmm, ymm), DT_LEFT | DT_VCENTER | DT_SINGLELINE); //4、 x = lxBegin; y = lyBegin + 13 + 20 + 14; w = 100; h = 13; dc.Rectangle(&pDlg->MakeRect(x, y, w, h, xmm, ymm)); //打印收件人 x = lxBegin + 1; y = lyBegin + 13 + 20 + 14 + 1.5f; w = 6; h = 13; dc.SelectObject(&font1); //黑体,10号 dc.DrawText(_T("收件人"), &pDlg->MakeRect(x, y, w, h, xmm, ymm), DT_CENTER | DT_WORDBREAK); //打印收件人信息 //dc.SelectObject(&font3); //黑体,14号 dc.SelectObject(&font12); //黑体,12号 x = lxBegin + 8 + 1; y = lyBegin + 13 + 20 + 14 + 1.2f; w = 100 - 8 - 2; h = 13; str = pDlg->m_SF.d_contact + CString(_T(" ")) + pDlg->m_SF.d_mobile + CString(_T(" ")) + pDlg->m_SF.d_tel + CString(_T(" ")) + pDlg->m_SF.d_company; dc.DrawText(str, &pDlg->MakeRect(x, y, w, h, xmm, ymm), DT_LEFT | DT_SINGLELINE); x = lxBegin + 8 + 1; y = lyBegin + 13 + 20 + 14 + 1 + 5.5f; w = 100 - 8 - 2; h = 13; str = pDlg->m_SF.d_address; dc.DrawText(str, &pDlg->MakeRect(x, y, w, h, xmm, ymm), DT_LEFT | DT_WORDBREAK); //5、 x = lxBegin; y = lyBegin + 13 + 20 + 14 + 13; w = 100; h = 9; dc.LineX(pDlg->MakePoint(x, y + h, xmm, ymm), pDlg->MakePoint(x + w, y + h, xmm, ymm)); x = lxBegin + 78; y = lyBegin + 13 + 20 + 14 + 13; w = 100 - 78; h = 9 + 12 + 9; dc.LineX(pDlg->MakePoint(x, y, xmm, ymm), pDlg->MakePoint(x, y + h, xmm, ymm)); //打印寄件人 x = lxBegin + 1.2f; y = lyBegin + 13 + 20 + 14 + 13 + 0.5f; w = 5; h = 9; dc.SelectObject(&font7); //黑体,8号 dc.DrawText(_T("寄件人"), &pDlg->MakeRect(x, y, w, h, xmm, ymm), DT_CENTER | DT_WORDBREAK); //打印寄件人信息 x = lxBegin + 8 + 1; y = lyBegin + 13 + 20 + 14 + 13 + 1; w = 78 - 8 - 2; h = 9; str = pDlg->m_SF.j_contact + CString(_T(" ")) + pDlg->m_SF.j_mobile + CString(_T(" ")) + pDlg->m_SF.j_tel + CString(_T(" ")) + pDlg->m_SF.j_company; dc.SelectObject(&font7); //黑体,8号 dc.DrawText(str, &pDlg->MakeRect(x, y, w, h, xmm, ymm), DT_LEFT | DT_SINGLELINE); x = lxBegin + 8 + 1; y = lyBegin + 13 + 20 + 14 + 13 + 1 + 4; w = 78 - 8 - 2; h = 9; str = pDlg->m_SF.j_address; dc.DrawText(str, &pDlg->MakeRect(x, y, w, h, xmm, ymm), DT_LEFT | DT_WORDBREAK); //6、 x = lxBegin; y = lyBegin + 13 + 20 + 14 + 13; w = 78; h = 9 + 12 + 9; //dc.Rectangle(&pDlg->MakeRect(x, y, w, h, xmm, ymm)); //打印付款方式 CString strPayMathod; switch (pDlg->m_SF.pay_method) { case 0: strPayMathod = _T("寄付月结"); break; case 1: strPayMathod = _T("寄方付"); break; case 2: strPayMathod = _T("收方付"); break; case 3: strPayMathod = _T("第三方付"); break; } str.Format(_T("付款方式:%s\r\n月结帐号:%s\r\n包裹数量:%d"), strPayMathod, pDlg->m_SF.custid, pDlg->m_SF.Cargo_count); x = lxBegin + 1; y = lyBegin + 13 + 20 + 14 + 13 + 9 + 2; w = 30; h = 12; dc.SelectObject(&font7); //黑体,8号 dc.DrawText(str, &pDlg->MakeRect(x, y, w, h, xmm, ymm), DT_LEFT | DT_WORDBREAK); str = _T("计费重量:\r\n声明价格:\r\n保价费用:"); x = lxBegin + 1 + 29; y = lyBegin + 13 + 20 + 14 + 13 + 9 + 2; w = 23; h = 12; dc.DrawText(str, &pDlg->MakeRect(x, y, w, h, xmm, ymm), DT_LEFT | DT_WORDBREAK); x = lxBegin + 1 + 29 + 25; y = lyBegin + 13 + 20 + 14 + 13 + 9 + 2; w = 23; h = 12; str = _T("包装费用:\r\n运费:\r\n费用合计:"); dc.DrawText(str, &pDlg->MakeRect(x, y, w, h, xmm, ymm), DT_LEFT | DT_WORDBREAK); //打印签名 x = lxBegin + 1 + 78; y = lyBegin + 13 + 20 + 14 + 13 + 9 + 1; w = 10; h = 9; str = _T("签名:"); dc.SelectObject(&font9); //黑体,9号 dc.DrawText(str, &pDlg->MakeRect(x, y, w, h, xmm, ymm), DT_LEFT | DT_SINGLELINE); x = lxBegin + 1 + 80; y = lyBegin + 13 + 20 + 14 + 13 + 9 + 12 + 9 - 5; w = 18.5f; h = 9; str = _T("年 月 日"); dc.DrawText(str, &pDlg->MakeRect(x, y, w, h, xmm, ymm), DT_RIGHT | DT_SINGLELINE); //7、 x = lxBegin; y = lyBegin + 13 + 20 + 14 + 13 + 9 + 12; w = 78; h = 9; //dc.Rectangle(&pDlg->MakeRect(x, y, w, h, xmm, ymm)); dc.LineX(pDlg->MakePoint(x, y, xmm, ymm), pDlg->MakePoint(x + w, y, xmm, ymm)); x = lxBegin; y = lyBegin + 13 + 20 + 14 + 13 + 9 + 12; w = 8; h = 9; //dc.Rectangle(&pDlg->MakeRect(x, y, w, h, xmm, ymm)); dc.LineX(pDlg->MakePoint(x + w, y, xmm, ymm), pDlg->MakePoint(x + w, y + h, xmm, ymm)); x = lxBegin + 60; y = lyBegin + 13 + 20 + 14 + 13 + 9 + 12; w = 78 - 60; h = 9; //dc.Rectangle(&pDlg->MakeRect(x, y, w, h, xmm, ymm)); dc.LineX(pDlg->MakePoint(x, y, xmm, ymm), pDlg->MakePoint(x, y + h, xmm, ymm)); //打印托寄物 x = lxBegin + 1.2f; y = lyBegin + 13 + 20 + 14 + 13 + 9 + 12 + 0.5f; w = 5; h = 9; dc.SelectObject(&font7); //黑体,8号 dc.DrawText(_T("托寄物"), &pDlg->MakeRect(x, y, w, h, xmm, ymm), DT_CENTER | DT_WORDBREAK); x = lxBegin + 7 + 1.2f; y = lyBegin + 13 + 20 + 14 + 13 + 9 + 12 + 1; w = 50; h = 9; str.Format(_T("托管物:%s\r\n备注:%s\r\n"), pDlg->m_SF.Cargo_name, pDlg->m_SF.remark); dc.SelectObject(&font9); //黑体,9号 dc.DrawText(str, &pDlg->MakeRect(x, y, w, h, xmm, ymm), DT_LEFT | DT_WORDBREAK); //打收寄件日期 str.Format(_T("收件员:\r\n日期:%02d月%02d日\r\n派件员:"), pDlg->m_SF.tCreate.wMonth, pDlg->m_SF.tCreate.wDay); x = lxBegin + 60 + 0.3f; y = lyBegin + 13 + 20 + 14 + 13 + 9 + 12 + 0.3f; w = 20; h = 9; dc.SelectObject(&font7); //黑体,8号 dc.DrawText(str, &pDlg->MakeRect(x, y, w, h, xmm, ymm), DT_LEFT | DT_WORDBREAK); //第二格 //画虚线 lyBegin = lyBegin + 90; //PS_DASH PS_DOT PS_DASHDOT PS_DASHDOTDOT Pen2.CreatePen(PS_DASHDOTDOT, int(0.2f*xmm), RGB(0, 0, 0)); //0.1000就是我需要的0.2mm笔宽 dc.SelectObject(&Pen2); x = lxBegin; y = lyBegin + 7; w = 100; h = 60; dc.LineX(pDlg->MakePoint(x, y, xmm, ymm), pDlg->MakePoint(x + w, y, xmm, ymm)); //空15mm,画100*60的框 lyBegin = lyBegin + 15; dc.SelectObject(&Pen); x = lxBegin; y = lyBegin; w = 100; h = 60; dc.Rectangle(&pDlg->MakeRect(x, y, w, h, xmm, ymm)); //8、 //打印顺丰Logo; if (pict.m_bIsInitialized) { SIZE iSize = pict.GetSize(); x = lxBegin + 2; y = lyBegin + 0.5f; w = 28 - 2; h = 7; float w1 = (h * (float)iSize.cx) / (float)iSize.cy; float h1 = (w * (float)iSize.cy) / (float)iSize.cx; if (h1 > h) //按长计算宽,但新宽过长。 { x = x + (w - w1) / 2.0f; w = w1; } if (w1 > w) //按宽计算长,但新长过长。 { y = y + (h - h1) / 2.0f; h = h1; } pict.Draw(&dc, pDlg->MakeRect(x, y, w, h, xmm, ymm)); } if (pict2.m_bIsInitialized) { SIZE iSize = pict2.GetSize(); x = lxBegin + 2; y = lyBegin + 7 + 0.5f; w = 28 - 2; h = 7; float w1 = (h * (float)iSize.cx) / (float)iSize.cy; float h1 = (w * (float)iSize.cy) / (float)iSize.cx; if (h1 > h) //按长计算宽,但新宽过长。 { x = x + (w - w1) / 2.0f; w = w1; } if (w1 > w) //按宽计算长,但新长过长。 { y = y + (h - h1) / 2.0f; h = h1; } pict2.Draw(&dc, pDlg->MakeRect(x, y, w, h, xmm, ymm)); } x = lxBegin + 31; y = lyBegin + 1.5f; w = 48; h = 9.5f; code.DrawBarcode(dc.m_hDC, int((float)x*xmm + 0.5f), int((float)y*ymm + 0.5f), int((float)(y + h - 1)*ymm + 0.5f), int((float)(y + h)*ymm + 0.5f), clrBar, clrSpace, int(0.32f*xmm + 0.5f)); //打印“运单号:” x = lxBegin + 38 + 6; y = lyBegin + 2 + 9.1f; w = 48; h = 6; dc.SelectObject(&font1); //黑体,10号 dc.DrawText(CString(_T("运单号:")) + strMailNo, &pDlg->MakeRect(x, y, w, h, xmm, ymm), DT_LEFT | DT_SINGLELINE); x = lxBegin; y = lyBegin; w = 28; h = 15; //dc.Rectangle(&pDlg->MakeRect(x, y, w, h, xmm, ymm)); dc.LineX(pDlg->MakePoint(x + w, y, xmm, ymm), pDlg->MakePoint(x + w, y + 15, xmm, ymm)); //9、 //打印收件人 x = lxBegin + 1; y = lyBegin + 15 + 0.5f; w = 6; h = 10; dc.SelectObject(&font9); //黑体,9号 dc.DrawText(_T("收件人"), &pDlg->MakeRect(x, y, w, h, xmm, ymm), DT_CENTER | DT_WORDBREAK); //打印收件人信息 dc.SelectObject(&font9); //黑体,9号 x = lxBegin + 8 + 1; y = lyBegin + 15 + 1.4f; w = 100 - 8 - 2; h = 10; str = pDlg->m_SF.d_contact + CString(_T(" ")) + pDlg->m_SF.d_mobile + CString(_T(" ")) + pDlg->m_SF.d_tel + CString(_T(" ")) + pDlg->m_SF.d_company; dc.DrawText(str, &pDlg->MakeRect(x, y, w, h, xmm, ymm), DT_LEFT | DT_SINGLELINE); x = lxBegin + 8 + 1; y = lyBegin + 15 + 1 + 4.8f; w = 100 - 8 - 2; h = 10; str = pDlg->m_SF.d_address; dc.DrawText(str, &pDlg->MakeRect(x, y, w, h, xmm, ymm), DT_LEFT | DT_SINGLELINE); x = lxBegin; y = lyBegin + 15; w = 100; h = 10; dc.Rectangle(&pDlg->MakeRect(x, y, w, h, xmm, ymm)); x = lxBegin; y = lyBegin + 15; w = 8; h = 10 + 10; //dc.Rectangle(&pDlg->MakeRect(x, y, w, h, xmm, ymm)); dc.LineX(pDlg->MakePoint(x + w, y, xmm, ymm), pDlg->MakePoint(x + w, y + h, xmm, ymm)); //10、 //打印寄件人 x = lxBegin + 1.2f; y = lyBegin + 15 + 10 + 0.5f; w = 5; h = 9; dc.SelectObject(&font9); //黑体,9号 dc.DrawText(_T("寄件人"), &pDlg->MakeRect(x, y, w, h, xmm, ymm), DT_CENTER | DT_WORDBREAK); //打印寄件人信息 x = lxBegin + 8 + 1; y = lyBegin + 15 + 10 + 1.4f; w = 100 - 8 - 2; h = 10; str = pDlg->m_SF.j_contact + CString(_T(" ")) + pDlg->m_SF.j_mobile + CString(_T(" ")) + pDlg->m_SF.j_tel + CString(_T(" ")) + pDlg->m_SF.j_company; dc.SelectObject(&font9); //黑体,9号 dc.DrawText(str, &pDlg->MakeRect(x, y, w, h, xmm, ymm), DT_LEFT | DT_SINGLELINE); x = lxBegin + 8 + 1; y = lyBegin + 15 + 10 + 1 + 4.8f; w = 100 - 8 - 2; h = 10; str = pDlg->m_SF.j_address; dc.DrawText(str, &pDlg->MakeRect(x, y, w, h, xmm, ymm), DT_LEFT | DT_SINGLELINE); x = lxBegin; y = lyBegin + 15 + 10 + 10; w = 100; h = 10; //dc.Rectangle(&pDlg->MakeRect(x, y, w, h, xmm, ymm)); dc.LineX(pDlg->MakePoint(x, y, xmm, ymm), pDlg->MakePoint(x + w, y, xmm, ymm)); //11、 str.Format(_T("付款方式:%s\r\n月结帐号:%s\r\n包裹数量:%d"), strPayMathod, pDlg->m_SF.custid, pDlg->m_SF.Cargo_count); x = lxBegin + 1; y = lyBegin + 15 + 10 + 10 + 2; w = 30; h = 25; dc.SelectObject(&font7); //黑体,8号 dc.DrawText(str, &pDlg->MakeRect(x, y, w, h, xmm, ymm), DT_LEFT | DT_WORDBREAK); str = _T("计费重量:\r\n声明价格:\r\n保价费用:"); x = lxBegin + 1 + 29; y = lyBegin + 15 + 10 + 10 + 2; w = 23; h = 25; dc.DrawText(str, &pDlg->MakeRect(x, y, w, h, xmm, ymm), DT_LEFT | DT_WORDBREAK); x = lxBegin + 1 + 29 + 25; y = lyBegin + 15 + 10 + 10 + 2; w = 23; h = 25; str = _T("包装费用:\r\n运费:\r\n费用合计:"); dc.DrawText(str, &pDlg->MakeRect(x, y, w, h, xmm, ymm), DT_LEFT | DT_WORDBREAK); //打收寄件日期 str.Format(_T("收件员:\r\n\r\n日期:%02d月%02d日"), pDlg->m_SF.tCreate.wMonth, pDlg->m_SF.tCreate.wDay); x = lxBegin + 1 + 29 + 25 + 25; y = lyBegin + 15 + 10 + 10 + 2; w = 23; h = 25; dc.DrawText(str, &pDlg->MakeRect(x, y, w, h, xmm, ymm), DT_LEFT | DT_WORDBREAK); //打印托寄物 //str.Format(_T("企业ID:%d  托寄物:%s"), pDlg->m_SF.lCorpID,pDlg->m_SF.Cargo_name); str.Format(_T("托寄物:%s"), pDlg->m_SF.Cargo_name); x = lxBegin + 1; y = lyBegin + 15 + 10 + 10 + 16.5f; w = 100 - 2; h = 10; dc.DrawText(str, &pDlg->MakeRect(x, y, w, h, xmm, ymm), DT_LEFT | DT_WORDBREAK); str.Format(_T("备注:%s"), pDlg->m_SF.remark); x = lxBegin + 1; y = lyBegin + 15 + 10 + 10 + 18 + 2.5f; w = 100 - 20 - 2; h = 10; dc.DrawText(str, &pDlg->MakeRect(x, y, w, h, xmm, ymm), DT_LEFT | DT_WORDBREAK); //最后打印下单日期 x = lxBegin + 1; y = lyBegin + 15 + 10 + 10 + 18 + 2.5f; w = 100 - 2; h = 10; str.Format(_T("%04d.%02d.%02d %02d:%02d"), pDlg->m_SF.tCreate.wYear, pDlg->m_SF.tCreate.wMonth, pDlg->m_SF.tCreate.wDay, pDlg->m_SF.tCreate.wHour, pDlg->m_SF.tCreate.wMinute); dc.SelectObject(&font7); //黑体,7号 dc.DrawText(str, &pDlg->MakeRect(x, y, w, h, xmm, ymm), DT_RIGHT | DT_WORDBREAK); //打印二维码测试 CString strQrTextA = CW2A(pDlg->m_SF.Res_mailno); QrCode qr0 = QrCode::encodeText((const char*)szBarCode, QrCode::Ecc::MEDIUM); x = lxBegin + 10; y = lyBegin + 15 + 10 + 10 + 18 + 2.5f; w = 20; h = 20; CRect rect = pDlg->MakeRect(x, y, w, h, xmm, ymm); QrDrawVC::Draw(qr0, dc, rect); if (pOldBrush) dc.SelectObject(pOldBrush); if (pOldPen) dc.SelectObject(pOldPen); if (pOldfont) dc.SelectObject(pOldfont); font1.DeleteObject(); font2.DeleteObject(); font3.DeleteObject(); font4.DeleteObject(); font5.DeleteObject(); font6.DeleteObject(); font7.DeleteObject(); font9.DeleteObject(); font12.DeleteObject(); } void DLG_Corp_LXR_SF::On_BeginPrint2(CDC *pDC, CPrintInfo *pInfo, void *pVoid) { // pInfo->SetMaxPage(1); //只有1页 } RECT DLG_Corp_LXR_SF::MakeRect(float x, float y, float w, float h,float xrate, float yrate) { RECT rect = { int((float)x*xrate+0.5f),int((float)y*yrate + 0.5f),int(float(x + w)*xrate+0.5f),int((float)(y + h)*yrate +0.5f) }; return rect; } POINT DLG_Corp_LXR_SF::MakePoint(float x, float y, float xrate, float yrate) { POINT point = { int((float)x*xrate + 0.5f),int((float)y*yrate + 0.5f) }; return point; } void DLG_Corp_LXR_SF::Draw_Image(HDC pDc, CString strName, float x,float y,float w,float h,float xmm,float ymm) { CImage image; image.Load(strName); if (!image.IsNull()) { SIZE iSize = { image.GetWidth(),image.GetHeight() }; MakeRect_Pict(x, y, w, h, iSize); CRect pRect = MakeRect(x, y, w, h, xmm, ymm); //image.Draw(pDc, pRect); SetStretchBltMode(pDc, STRETCH_HALFTONE);//设置图像的拉伸方式 //SetStretchBltMode(pDc, WHITEONBLACK); //保持图片不失真 image.StretchBlt(pDc, pRect); } } void DLG_Corp_LXR_SF::MakeRect_Pict(float &x, float &y, float &w, float &h, SIZE iSize) { float w1 = (h * (float)iSize.cx) / (float)iSize.cy; float h1 = (w * (float)iSize.cy) / (float)iSize.cx; if (h1 > h) //按长计算宽,但新宽过长。 { x = x + (w - w1) / 2.0f; w = w1; } if (w1 > w) //按宽计算长,但新长过长。 { y = y + (h - h1) / 2.0f; h = h1; } } void DLG_Corp_LXR_SF::OnPreparePrinting2(CPrintInfo *pInfo) { pInfo->SetMaxPage(1); //只有1页 //设横向 CWinApp* pApp = AfxGetApp(); pApp->GetPrinterDeviceDefaults(&pInfo->m_pPD->m_pd); if (pInfo) { LPDEVMODE lpDevmode = pInfo->m_pPD->GetDevMode(); if (lpDevmode) { //if (m_lPrintType == 1) // lpDevmode->dmOrientation = DMORIENT_PORTRAIT; //纵向 //else // lpDevmode->dmOrientation = DMORIENT_LANDSCAPE; //横向 } } } void DLG_Corp_LXR_SF::GetCurrentPath(TCHAR *pPath) { ::GetModuleFileName(NULL, pPath, 512); for (int j = _tcslen(pPath); j>0; j--) { if (pPath[j] == '\\') break; } pPath[j + 1] = 0; }