123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636 |
- // Test.cpp : 定义应用程序的类行为。
- //
- #include "stdafx.h"
- #include "Test.h"
- #include "TestDlg.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #endif
- #if 0
- #define MAKEWORD(a, b) ((WORD)(((BYTE)(((DWORD_PTR)(a)) & 0xff)) | ((WORD)((BYTE)(((DWORD_PTR)(b)) & 0xff))) << 8))
- #define MAKELONG(a, b) ((LONG)(((WORD)(((DWORD_PTR)(a)) & 0xffff)) | ((DWORD)((WORD)(((DWORD_PTR)(b)) & 0xffff))) << 16))
- #define LOWORD(l) ((WORD)(((DWORD_PTR)(l)) & 0xffff))
- #define HIWORD(l) ((WORD)((((DWORD_PTR)(l)) >> 16) & 0xffff))
- #define LOBYTE(w) ((BYTE)(((DWORD_PTR)(w)) & 0xff))
- #define HIBYTE(w) ((BYTE)((((DWORD_PTR)(w)) >> 8) & 0xff))
- //#define MAKEINT32(mark,len) ((INT32)(mark<<19 & 0x7FFF) | (INT32)(len & 0x1FFF))
- #endif
- // CTestApp
- BEGIN_MESSAGE_MAP(CTestApp, CWinAppEx)
- ON_COMMAND(ID_HELP, &CWinApp::OnHelp)
- END_MESSAGE_MAP()
- #define JSON _T("\"general_require\": \"\", \"sample_list\": [{\"modify\": 2, \"modify_note\": \"11111111\", \"photo_name\": \"001\"}, {\"modify\": 2, \"modify_note\": \"222222222\", \"photo_name\": \"002\"}, {\"modify\": 2, \"modify_note\": \"33333333333\", \"photo_name\": \"003\"}, {\"modify\": 2, \"modify_note\": \"444444444444\", \"photo_name\": \"004\"}, {\"modify\": 2, \"modify_note\": \"5555555555555\", \"photo_name\": \"005\"}, {\"modify\": 2, \"modify_note\": \"66666666\", \"photo_name\": \"006\"}, {\"modify\": 1, \"modify_note\": \"\", \"photo_name\": \"007\"}, {\"modify\": 1, \"modify_note\": \"\", \"photo_name\": \"008\"}, {\"modify\": 1, \"modify_note\": \"\", \"photo_name\": \"009\"}, {\"modify\": 1, \"modify_note\": \"\", \"photo_name\": \"010\"}, {\"modify\": 1, \"modify_note\": \"\", \"photo_name\": \"011\"}, {\"modify\": 1, \"modify_note\": \"\", \"photo_name\": \"012\"}, {\"modify\": 1, \"modify_note\": \"\", \"photo_name\": \"013\"}, {\"modify\": 1, \"modify_note\": \"\", \"photo_name\": \"014\"}, {\"modify\": 1, \"modify_note\": \"\", \"photo_name\": \"015\"}, {\"modify\": 1, \"modify_note\": \"\", \"photo_name\": \"016\"}, {\"modify\": 1, \"modify_note\": \"\", \"photo_name\": \"017\"}, {\"modify\": 1, \"modify_note\": \"\", \"photo_name\": \"018\"}, {\"modify\": 1, \"modify_note\": \"\", \"photo_name\": \"019\"}, {\"modify\": 1, \"modify_note\": \"\", \"photo_name\": \"020\"}, {\"modify\": 1, \"modify_note\": \"\", \"photo_name\": \"021\"}, {\"modify\": 1, \"modify_note\": \"\", \"photo_name\": \"022\"}, {\"modify\": 1, \"modify_note\": \"\", \"photo_name\": \"023\"}, {\"modify\": 1, \"modify_note\": \"\", \"photo_name\": \"024\"}, {\"modify\": 1, \"modify_note\": \"\", \"photo_name\": \"025\"}, {\"modify\": 1, \"modify_note\": \"\", \"photo_name\": \"026\"}, {\"modify\": 1, \"modify_note\": \"\", \"photo_name\": \"027\"}, {\"modify\": 1, \"modify_note\": \"\", \"photo_name\": \"028\"}, {\"modify\": 1, \"modify_note\": \"\", \"photo_name\": \"029\"}, {\"modify\": 1, \"modify_note\": \"\", \"photo_name\": \"030\"}, {\"modify\": 1, \"modify_note\": \"\", \"photo_name\": \"031\"}, {\"modify\": 1, \"modify_note\": \"\", \"photo_name\": \"032\"}, {\"modify\": 1, \"modify_note\": \"\", \"photo_name\": \"033\"}, {\"modify\": 1, \"modify_note\": \"\", \"photo_name\": \"034\"}, {\"modify\": 1, \"modify_note\": \"\", \"photo_name\": \"035\"}, {\"modify\": 1, \"modify_note\": \"\", \"photo_name\": \"036\"}, {\"modify\": 1, \"modify_note\": \"\", \"photo_name\": \"037\"}, {\"modify\": 1, \"modify_note\": \"\", \"photo_name\": \"038\"}, {\"modify\": 2, \"modify_note\": \"393939393939393939\", \"photo_name\": \"039\"}]")
- void getresult()
- {
- CString strResult = _T("");
- CString strJson = JSON;
- CString strTemp = _T("");
- CString strSubJson = _T("");
- CString strMark = _T("\"general_require\": ");
- CString strMark2 = _T("");
- CString strImgName = _T(""); // 相片名;
- CString strImgctx = _T(""); // 相片修改要求;
- INT nIndex = strJson.Find(strMark);
- if ( nIndex != -1 )
- strJson = strJson.Mid(nIndex + strMark.GetLength());
- strMark = _T(", \"sample_list\": [{");
- nIndex = strJson.Find(strMark);
- if ( nIndex != -1 )
- {
- // 总的要求;
- strTemp = strJson.Left(nIndex);
- strTemp.TrimLeft(_T("\""));
- strTemp.TrimRight(_T("\""));
- if ( !strTemp.IsEmpty() )
- strResult += strTemp + _T(";");
- strJson = strJson.Mid(nIndex + strMark.GetLength());
- }
- strMark = _T("\"modify\": ");
- strJson += strMark;
- nIndex = strJson.Find(strMark) ;
- if ( nIndex != -1 )
- {
- strJson = strJson.Mid(nIndex + strMark.GetLength());
- while( strJson.Find(strMark) != -1 )
- {
- nIndex = strJson.Find(strMark);
- strSubJson = strJson.Left(nIndex);
- strJson = strJson.Mid(nIndex+ strMark.GetLength());
- if ( nIndex != -1 )
- {
- strMark2 = _T(", \"modify_note\": ");
- nIndex = strSubJson.Find(strMark2);
- if ( nIndex != -1)
- {
- // 相片选样类型 2 = 修改, 1 = 确认;
- strTemp = strSubJson.Left(nIndex);
- if ( strTemp == _T("2") )
- {
- strSubJson = strSubJson.Mid(nIndex + strMark2.GetLength() );
- strMark2 = _T("\", \"photo_name\": ");
- nIndex = strSubJson.Find(strMark2);
- if ( nIndex != -1 )
- {
- strImgctx = strSubJson.Left(nIndex);
- strImgctx.TrimLeft(_T("\""));
- strImgName = strSubJson.Mid(nIndex + strMark2.GetLength()+1);
- strImgName = strImgName.Left(strImgName.Find(_T("\"")));
- strResult += strImgName + _T(":") + strImgctx + _T(";");
- }
- }
- }
- }
- }
- }
-
- OutputDebugString(strResult + _T("\n"));
-
- }
- // CTestApp 构造
- CTestApp::CTestApp()
- {
- // TODO: 在此处添加构造代码,
- // 将所有重要的初始化放置在 InitInstance 中
-
- }
- // 唯一的一个 CTestApp 对象
- CTestApp theApp;
- CHAR* UNICODE2ASCII(IN LPWCH lpUNICODEStr)
- {
- if ( lpUNICODEStr == NULL )
- return NULL;
- // 获取多字节字符字节数;
- int cbMultiByte = WideCharToMultiByte(CP_OEMCP, 0, lpUNICODEStr, -1, NULL, 0, NULL, NULL);
- if ( cbMultiByte == 0 )
- return NULL;
- // 转换成多字节字符;
- CHAR *pMultiByteStr = new CHAR[cbMultiByte+1];
- memset(pMultiByteStr, 0, cbMultiByte + 1);
- int nWriteNum = WideCharToMultiByte(CP_OEMCP, 0, lpUNICODEStr, -1, pMultiByteStr, cbMultiByte, NULL, NULL);
- if (nWriteNum != cbMultiByte)
- {
- if (pMultiByteStr)
- delete []pMultiByteStr;
- return NULL;
- }
- return pMultiByteStr;
- }
- BOOL UNICODE2ASCII(IN LPWCH lpUNICODEStr, OUT LPCH pASCIIStr, IN CONST INT& nASCIIStrLen)
- {
- if ( lpUNICODEStr == NULL )
- return FALSE;
- // 获取多字节字符字节数;
- int cbMultiByte = WideCharToMultiByte(CP_OEMCP, 0, lpUNICODEStr, -1, NULL, 0, NULL, NULL);
- if ( cbMultiByte == 0 || cbMultiByte >= nASCIIStrLen )
- return FALSE;
- // 转换成多字节字符;
- memset((void*)pASCIIStr, 0, nASCIIStrLen);
- int nWriteNum = WideCharToMultiByte(CP_OEMCP, 0, lpUNICODEStr, -1, pASCIIStr, cbMultiByte, NULL, NULL);
- if (nWriteNum != cbMultiByte)
- {
- return FALSE;
- }
- return TRUE;
- }
- WCHAR* ASCII2UNICODE(IN LPCCH lpASCIIStr)
- {
- if ( lpASCIIStr == NULL )
- return NULL;
- // 获取宽字符字节数;
- int cchWideChar = MultiByteToWideChar(CP_ACP, 0, lpASCIIStr, -1, NULL, 0);
- if ( cchWideChar == 0)
- return NULL;
- // 转换成宽字符串;
- WCHAR *pWideChar = new WCHAR[cchWideChar + 1];
- memset(pWideChar, 0 , sizeof(WCHAR)*(cchWideChar + 1));
- int nWriteNum = MultiByteToWideChar(CP_ACP, 0, lpASCIIStr, -1, pWideChar, cchWideChar );
- if ( nWriteNum != cchWideChar)
- {
- if (pWideChar)
- delete []pWideChar;
- return NULL;
- }
- return pWideChar;
- }
- BOOL ASCII2UNICODE(IN LPCCH lpASCIIStr, OUT PWCH pUNICODEStr, IN CONST INT& nUNICODEStrLen)
- {
- if ( lpASCIIStr == NULL )
- return FALSE;
- // 获取宽字符字节数;
- int cchWideChar = MultiByteToWideChar(CP_ACP, 0, lpASCIIStr, -1, NULL, 0);
- if ( cchWideChar == 0 || cchWideChar >= nUNICODEStrLen)
- return FALSE;
- // 转换成宽字符串;
- memset(pUNICODEStr, 0 , sizeof(WCHAR)*nUNICODEStrLen);
- int nWriteNum = MultiByteToWideChar(CP_ACP, 0, lpASCIIStr, -1, pUNICODEStr, cchWideChar );
- if ( nWriteNum != cchWideChar)
- return FALSE;
- return TRUE;
- }
- // CTestApp 初始化
- char TwoHexCharToChar(char ch1,char ch2)
- {
- char Numb1;
- char Numb2;
- if (ch1 >= 'A')
- Numb1 = (toupper(ch1)-'0'-7)*16;
- else
- Numb1 = (ch1 - '0')*16;
- if (ch2 >= 'A')
- Numb2 = (toupper(ch2) - '0' - 7);
- else
- Numb2 = (ch2 - '0');
- return (Numb1 + Numb2);
- }
- void Str2HexStr(char *szHexString,CString szString,int *iHexStringLen)
- {
- int iLoop;
- int iCount;
-
- iLoop = 0;
- iCount = 0;
- szHexString[0] = '\0';
-
- while(1)
- {
- if (szString[iLoop] == '\0' || szString[iLoop + 1] == '\0')
- {
- break;
- }
-
- szHexString[iCount] = static_cast<char>(TwoHexCharToChar(szString[iLoop],szString[iLoop + 1]));
- iLoop ++;
- iLoop ++;
- iCount ++;
- }
-
- szHexString[iCount] = '\0';
-
- *iHexStringLen = iCount;
- }
- WORD AsciiToBYTE(BYTE btSrc)
- {
- WORD chDest = (WORD)btSrc;
- if ((btSrc >= 'A')&&(btSrc <= 'F'))
- {
- chDest = chDest - 'A' + 10;
- }
- else if ((btSrc >= 'a')&&(btSrc <= 'f'))
- {
- chDest = chDest - 'a' + 10;
- }
- else if ((btSrc >= '0')&&(btSrc <= '9'))
- {
- chDest -= '0';
- }
- return chDest;
- }
- CString convertString(IN LPCCH lpString)
- {
- CString str = lpString;
- CString strResult = _T("");
- INT nIndex = 0;
- CString strTemp = _T("");
- while ( str.Find("\\u") != -1)
- {
- nIndex = str.Find(_T("\\u"));
- strResult += str.Left(nIndex);
- strTemp = str.Mid(nIndex + 2, 4);
- str = str.Mid(nIndex + 2 +4);
- TCHAR szReturn[10] = {0};
- union __UNION_VAR_INT{
- BYTE ch[2];
- int value;
- }unionVarInt;
- unionVarInt.ch[0] = (AsciiToBYTE(strTemp.GetAt(2)) << 4) | (AsciiToBYTE(strTemp.GetAt(3)) & 0x00FF);
- unionVarInt.ch[1] = (AsciiToBYTE(strTemp.GetAt(0)) << 4) | (AsciiToBYTE(strTemp.GetAt(1)) & 0x00FF);
- WCHAR szWide[2] = {0};
- szWide[0] = unionVarInt.value;
- UNICODE2ASCII(szWide,szReturn,10);
- strResult += (CString)szReturn;
- }
- strResult += str;
- return strResult;
- }
- #define MAKEINT32(mark,len) ((INT32)(mark<<19 ) | (INT32)(len & 0x1FFF))
- void getXPJsonresult(IN CString strJson, IN CArray<CStringArray,CStringArray>& AryResult)
- {
- INT i = 0;
- INT nIndex = 0;
- INT nCount = 0;
- CString strTemp = _T("");
- CString strTemp2 = _T("");
- CString strMark = _T("{\"photo_list\": ");
- nCount = strJson.Replace(strMark, strMark);
- strJson += _T(", {\"photo_list\": ");
- AryResult.SetSize(nCount,1);
- strJson = strJson.Mid(strMark.GetLength());
- while ( strJson.Find(strMark) != -1 )
- {
- nIndex = strJson.Find(strMark);
- strTemp = strJson.Left(nIndex - 3);
- strJson = strJson.Mid(nIndex + strMark.GetLength());
- // 解析出Json内容;
- AryResult.ElementAt(i).RemoveAll();
- // 相片串;
- nIndex = strTemp.Find(_T(", "));
- if ( nIndex != -1)
- {
- strTemp2 = strTemp.Left(nIndex);
- strTemp2.TrimLeft(_T("\""));
- strTemp2.TrimRight(_T("\""));
- AryResult.ElementAt(i).Add(strTemp2);
- strTemp = strTemp.Mid(nIndex + 2);
- }
- // 商品数量;
- nIndex = strTemp.Find(_T("\"num\": "));
- if ( nIndex != -1)
- {
- strTemp = strTemp.Mid(nIndex + 7);
- nIndex = strTemp.Find(_T(", \"product_id\": "));
- if ( nIndex != -1)
- {
- strTemp2 = strTemp.Left(nIndex);
- AryResult.ElementAt(i).Add(strTemp2);
- strTemp = strTemp.Mid(nIndex + strlen(_T(", \"product_id\": ")));
- }
- }
- // 商品ID;
- nIndex = strTemp.Find(_T(", \"name\": "));
- if ( nIndex != -1)
- {
- strTemp2 = strTemp.Left(nIndex);
- strTemp2.TrimLeft(_T("\""));
- strTemp2.TrimRight(_T("\""));
- AryResult.ElementAt(i).Add(strTemp2);
- strTemp = strTemp.Mid(nIndex + _tcslen(_T(", \"name\": ")));
- }
- // 商品名称;
- if ( strTemp.GetLength() )
- {
- strTemp.TrimLeft(_T("\""));
- strTemp.TrimRight(_T("\""));
- AryResult.ElementAt(i).Add(strTemp);
- }
- i++;
- }
- }
- #include "Barcode.h"
- BOOL SaveBitmap(IN CDC *pDC, IN CBitmap* pBitmap, IN const INT& nWidth, IN const INT& nHeight, IN LPCTSTR lpSavepath)
- {
- DWORD dwBmpSize = ((nWidth + 31) / 32) * 4 * nHeight;
- HANDLE hFile = CreateFile(lpSavepath, GENERIC_READ | GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
- if (hFile == INVALID_HANDLE_VALUE)
- {
- //WriteLog(_T("二维码位图创建失败"));
- return FALSE;
- }
- HANDLE hFileMapping = CreateFileMapping(hFile, NULL, PAGE_READWRITE | SEC_COMMIT, 0,
- sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD) * 2 + dwBmpSize, NULL);
- LPBYTE lpbyMapView = (LPBYTE)MapViewOfFile(hFileMapping, FILE_MAP_WRITE, 0, 0, 0);
- ZeroMemory(lpbyMapView, sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD) * 2 + dwBmpSize);
- //结构体地址割付
- LPBITMAPFILEHEADER pbfh = (LPBITMAPFILEHEADER)lpbyMapView;
- LPBITMAPINFO pbmi = (LPBITMAPINFO)(lpbyMapView + sizeof(BITMAPFILEHEADER));
- LPVOID pbdt = lpbyMapView + sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD) * 2;
- // BITMAPFILEHEADER
- //pbfh->bfType = (WORD) (('M' << 8) | 'B'); // "BM"
- // BMP类型,与上面同值;
- pbfh->bfType = 0x4D42;
- pbfh->bfSize = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD) * 2 + dwBmpSize; // 文件总长;
- pbfh->bfReserved1 = 0;
- pbfh->bfReserved2 = 0;
- pbfh->bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD) * 2; // 位图数据相对于文件头的偏移量;
- // LPBITMAPINFO->BITMAPINFOHEADER
- pbmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
- pbmi->bmiHeader.biWidth = nWidth;
- pbmi->bmiHeader.biHeight = nHeight;
- pbmi->bmiHeader.biPlanes = 1;
- pbmi->bmiHeader.biBitCount = 1;
- pbmi->bmiHeader.biCompression = BI_RGB;
- pbmi->bmiHeader.biSizeImage = dwBmpSize;
- pbmi->bmiHeader.biXPelsPerMeter = 3780;
- pbmi->bmiHeader.biYPelsPerMeter = 3780;
- pbmi->bmiHeader.biClrUsed = 0;
- pbmi->bmiHeader.biClrImportant = 0;
- // 放大到指定的像素宽高;
- CDC* pWorkDC = new CDC;
- pWorkDC->CreateCompatibleDC(NULL);
- CBitmap* pWorkBitmap = new CBitmap;
- pWorkBitmap->CreateBitmap(nWidth, nHeight, 1, 1, NULL);
- CBitmap* pOldBitmap = pWorkDC->SelectObject(pWorkBitmap);
- pWorkDC->StretchBlt(0, 0, nWidth, nHeight, pDC, 0, 0, nWidth, nHeight, SRCCOPY);
- GetDIBits(pWorkDC->m_hDC, (HBITMAP)*pWorkBitmap, 0, nHeight, pbdt, pbmi, DIB_RGB_COLORS);
- pWorkDC->SelectObject(pOldBitmap);
- delete pWorkBitmap;
- delete pWorkDC;
- UnmapViewOfFile(lpbyMapView);
- CloseHandle(hFileMapping);
- CloseHandle(hFile);
- return TRUE;
- }
- void DrawString(IN CDC* pdc, IN CONST INT& nFontSize, IN LPCTSTR lpFontName, IN LPCTSTR lpString, IN OUT CRect &rcString)
- {
- if ( !pdc || !lpString )
- return;
- LOGFONT log;
- // 设置字体字号;
- log.lfHeight = -MulDiv(nFontSize ? nFontSize : 9, GetDeviceCaps(pdc->GetSafeHdc(), LOGPIXELSY), 72);
- log.lfWidth = 0;
- log.lfEscapement = 0;
- log.lfOrientation = 0;
- log.lfWeight = FW_REGULAR;
- log.lfItalic = false;
- log.lfUnderline = false;
- log.lfStrikeOut = 0;
- log.lfCharSet = ANSI_CHARSET;
- log.lfOutPrecision = OUT_DEFAULT_PRECIS;
- log.lfClipPrecision = CLIP_DEFAULT_PRECIS;
- log.lfQuality = DEFAULT_QUALITY;
- log.lfPitchAndFamily = DEFAULT_PITCH || FF_ROMAN;
- // 设置字体名称;
- strcpy(log.lfFaceName, (lpFontName && (lpFontName[0] != _T('\0'))) ? lpFontName : _T("Arial"));
- CFont cf;
- cf.CreateFontIndirect(&log);
- CFont *oldf = pdc->SelectObject(&cf);
- SIZE Size;
- GetTextExtentPoint32(pdc->GetSafeHdc(), lpString, _tcslen(lpString), &Size);
- rcString.SetRect(rcString.left, rcString.top, Size.cx, Size.cy + rcString.top);
- pdc->TextOut(rcString.left, rcString.top, lpString);
- }
- void ExportBarCodeImg(
- IN CONST INT& nBarCodeType, // 条码类型;
- IN INT nWidth, // 图片宽(最好传屏幕宽);
- IN INT nHeight, // 图片高(最好传屏幕高);
- IN CONST INT& nPenWidth, // 条码柱宽;
- IN CONST INT& nPenHeight, // 条码柱高;
- IN LPCTSTR lpBarAutoId, // 商品AutoId;
- IN LPCTSTR lpBarOrderNum, // 订单号;
- IN LPCTSTR lpBarProduct, // 商品名称;
- IN LPCTSTR lpSaveImgDirectory, // 要保存的目录;
- IN LPCTSTR lpSaveImgName // 要保存的名称(NULL则使用商品名称)
- )
- {
- Barcode128 code;
- code.Encode128B(lpBarAutoId);
- // 计算出条码宽度;
- INT nBarCodeWidth = code.GetBarCodeWidth(nPenWidth);
- if ( nBarCodeWidth > nWidth )
- nWidth = nBarCodeWidth + 10;
- // 创建位图;
- CBitmap *pBitmap = new CBitmap;
- pBitmap->CreateBitmap(nWidth,nHeight,1,1,NULL);
- // 创建DC环境;
- CDC *pBarCodeDC = new CDC;
- pBarCodeDC->CreateCompatibleDC(NULL);
- // 将位图关联DC;
- pBarCodeDC->SelectObject(pBitmap);
- pBarCodeDC->PatBlt(0, 0, nWidth, nHeight, WHITENESS);
- // 开始画条码;
- CRect rcBar(5, 5, nBarCodeWidth + 5, nPenHeight);
- COLORREF clrBar = RGB(0,0,0);
- COLORREF clrSpace = RGB(255,255,255);
- code.DrawBarcode(pBarCodeDC->m_hDC, rcBar.left, rcBar.top, nPenHeight, nPenHeight, clrBar, clrSpace, nPenWidth);
- nBarCodeWidth = max(nBarCodeWidth, rcBar.Width());
- CString strTemp;
- strTemp.Format(_T("AutoId:%s"), lpBarAutoId);
- CRect rcString(rcBar.left, rcBar.bottom + 5, rcBar.right, rcBar.bottom + 10);
- DrawString(pBarCodeDC, 9, _T("宋体"), strTemp, rcString);
- nBarCodeWidth = max(nBarCodeWidth, rcString.Width());
- strTemp.Format(_T("订单号:%s"), lpBarOrderNum);
- rcString.SetRect(rcString.left, rcString.bottom + 5, rcString.right, rcString.bottom + 10);
- DrawString(pBarCodeDC, 9, _T("宋体"), strTemp, rcString);
- nBarCodeWidth = max(nBarCodeWidth, rcString.Width());
- strTemp.Format(_T("商品名:%s"), lpBarOrderNum);
- rcString.SetRect(rcString.left, rcString.bottom + 5, rcString.right, rcString.bottom + 10);
- DrawString(pBarCodeDC, 9, _T("宋体"), strTemp, rcString);
- nBarCodeWidth = max(nBarCodeWidth, rcString.Width());
- CString strSavepath;
- strSavepath.Format(_T("%s\\%s.bmp"), lpSaveImgDirectory, (lpSaveImgName && ( lpSaveImgName[0] != _T('\0'))) ? lpSaveImgName : lpBarProduct );
- SaveBitmap(pBarCodeDC, pBitmap, nBarCodeWidth + 10, rcString.bottom + 5, strSavepath);
-
- if ( pBitmap )
- delete pBitmap;
- if ( pBarCodeDC )
- delete pBarCodeDC;
- }
- BOOL CTestApp::InitInstance()
- {
- // 如果一个运行在 Windows XP 上的应用程序清单指定要
- // 使用 ComCtl32.dll 版本 6 或更高版本来启用可视化方式,
- //则需要 InitCommonControlsEx()。否则,将无法创建窗口。
- INITCOMMONCONTROLSEX InitCtrls;
- InitCtrls.dwSize = sizeof(InitCtrls);
- // 将它设置为包括所有要在应用程序中使用的
- // 公共控件类。
- InitCtrls.dwICC = ICC_WIN95_CLASSES;
- InitCommonControlsEx(&InitCtrls);
- CWinAppEx::InitInstance();
- AfxEnableControlContainer();
- CString strMaskId = _T("18665281860_0_545");
- CString strBranchId = _T("");
- CString strStudioName = _T("");
- CString strStudioTel = _T("18665281860");
- CString strOrderNum = _T("545");
- CString strScenery = _T("内景");
- CString strCustomerName = _T("张三");
- CString strCustomerTel = _T("15089892312");
- TCHAR szReturnString[1024*100] = {0};
- if (lyfzLibrary::LoadCloudSelectionLib())
- {
- // if ( lyfzLibrary::g_uploadorder(strMaskId, 0, strStudioName, strStudioTel, strOrderNum, strScenery, strCustomerName, strCustomerTel, szReturnString, MAX_PATH) )
- // {
- // OutputDebugString(_T("dfdfdfdfdfdfdf\n"));
- // CString strJson = _T("");
- // if ( lyfzLibrary::g_uploadgoodinfo(strMaskId, strJson) )
- // {
- // }
- // }
- CStringArray ary;
- ary.Add("E:\\ImageTest\\V27B");
- // ary.Add("E:\\ImageTest\\V27B\\2.png");
- // ary.Add("E:\\ImageTest\\V27B\\3.png");
- // ary.Add("E:\\ImageTest\\V27B\\4.png");
- // ary.Add("E:\\ImageTest\\V27B\\5.png");
- // ary.Add("E:\\ImageTest\\V27B\\6.png");
- // ary.Add("E:\\ImageTest\\V27B\\7.png");
- // ary.Add("E:\\ImageTest\\V27B\\8.png");
- // ary.Add("E:\\ImageTest\\V27B\\9.png");
- // ary.Add("E:\\ImageTest\\V27B\\10.png");
- lyfzLibrary::g_uploadimg(
- 0,
- strMaskId,
- strOrderNum,
- strScenery,
- "云选片",
- 500, 600,
- ary, ary, ary);
- }
- return FALSE;
- // 标准初始化
- // 如果未使用这些功能并希望减小
- // 最终可执行文件的大小,则应移除下列
- // 不需要的特定初始化例程
- // 更改用于存储设置的注册表项
- // TODO: 应适当修改该字符串,
- // 例如修改为公司或组织名
- SetRegistryKey(_T("应用程序向导生成的本地应用程序"));
- CTestDlg dlg;
- m_pMainWnd = &dlg;
- INT_PTR nResponse = dlg.DoModal();
- if (nResponse == IDOK)
- {
- // TODO: 在此放置处理何时用
- // “确定”来关闭对话框的代码
- }
- else if (nResponse == IDCANCEL)
- {
- // TODO: 在此放置处理何时用
- // “取消”来关闭对话框的代码
- }
- // 由于对话框已关闭,所以将返回 FALSE 以便退出应用程序,
- // 而不是启动应用程序的消息泵。
- return FALSE;
- }
|