Test.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636
  1. // Test.cpp : 定义应用程序的类行为。
  2. //
  3. #include "stdafx.h"
  4. #include "Test.h"
  5. #include "TestDlg.h"
  6. #ifdef _DEBUG
  7. #define new DEBUG_NEW
  8. #endif
  9. #if 0
  10. #define MAKEWORD(a, b) ((WORD)(((BYTE)(((DWORD_PTR)(a)) & 0xff)) | ((WORD)((BYTE)(((DWORD_PTR)(b)) & 0xff))) << 8))
  11. #define MAKELONG(a, b) ((LONG)(((WORD)(((DWORD_PTR)(a)) & 0xffff)) | ((DWORD)((WORD)(((DWORD_PTR)(b)) & 0xffff))) << 16))
  12. #define LOWORD(l) ((WORD)(((DWORD_PTR)(l)) & 0xffff))
  13. #define HIWORD(l) ((WORD)((((DWORD_PTR)(l)) >> 16) & 0xffff))
  14. #define LOBYTE(w) ((BYTE)(((DWORD_PTR)(w)) & 0xff))
  15. #define HIBYTE(w) ((BYTE)((((DWORD_PTR)(w)) >> 8) & 0xff))
  16. //#define MAKEINT32(mark,len) ((INT32)(mark<<19 & 0x7FFF) | (INT32)(len & 0x1FFF))
  17. #endif
  18. // CTestApp
  19. BEGIN_MESSAGE_MAP(CTestApp, CWinAppEx)
  20. ON_COMMAND(ID_HELP, &CWinApp::OnHelp)
  21. END_MESSAGE_MAP()
  22. #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\"}]")
  23. void getresult()
  24. {
  25. CString strResult = _T("");
  26. CString strJson = JSON;
  27. CString strTemp = _T("");
  28. CString strSubJson = _T("");
  29. CString strMark = _T("\"general_require\": ");
  30. CString strMark2 = _T("");
  31. CString strImgName = _T(""); // 相片名;
  32. CString strImgctx = _T(""); // 相片修改要求;
  33. INT nIndex = strJson.Find(strMark);
  34. if ( nIndex != -1 )
  35. strJson = strJson.Mid(nIndex + strMark.GetLength());
  36. strMark = _T(", \"sample_list\": [{");
  37. nIndex = strJson.Find(strMark);
  38. if ( nIndex != -1 )
  39. {
  40. // 总的要求;
  41. strTemp = strJson.Left(nIndex);
  42. strTemp.TrimLeft(_T("\""));
  43. strTemp.TrimRight(_T("\""));
  44. if ( !strTemp.IsEmpty() )
  45. strResult += strTemp + _T(";");
  46. strJson = strJson.Mid(nIndex + strMark.GetLength());
  47. }
  48. strMark = _T("\"modify\": ");
  49. strJson += strMark;
  50. nIndex = strJson.Find(strMark) ;
  51. if ( nIndex != -1 )
  52. {
  53. strJson = strJson.Mid(nIndex + strMark.GetLength());
  54. while( strJson.Find(strMark) != -1 )
  55. {
  56. nIndex = strJson.Find(strMark);
  57. strSubJson = strJson.Left(nIndex);
  58. strJson = strJson.Mid(nIndex+ strMark.GetLength());
  59. if ( nIndex != -1 )
  60. {
  61. strMark2 = _T(", \"modify_note\": ");
  62. nIndex = strSubJson.Find(strMark2);
  63. if ( nIndex != -1)
  64. {
  65. // 相片选样类型 2 = 修改, 1 = 确认;
  66. strTemp = strSubJson.Left(nIndex);
  67. if ( strTemp == _T("2") )
  68. {
  69. strSubJson = strSubJson.Mid(nIndex + strMark2.GetLength() );
  70. strMark2 = _T("\", \"photo_name\": ");
  71. nIndex = strSubJson.Find(strMark2);
  72. if ( nIndex != -1 )
  73. {
  74. strImgctx = strSubJson.Left(nIndex);
  75. strImgctx.TrimLeft(_T("\""));
  76. strImgName = strSubJson.Mid(nIndex + strMark2.GetLength()+1);
  77. strImgName = strImgName.Left(strImgName.Find(_T("\"")));
  78. strResult += strImgName + _T(":") + strImgctx + _T(";");
  79. }
  80. }
  81. }
  82. }
  83. }
  84. }
  85. OutputDebugString(strResult + _T("\n"));
  86. }
  87. // CTestApp 构造
  88. CTestApp::CTestApp()
  89. {
  90. // TODO: 在此处添加构造代码,
  91. // 将所有重要的初始化放置在 InitInstance 中
  92. }
  93. // 唯一的一个 CTestApp 对象
  94. CTestApp theApp;
  95. CHAR* UNICODE2ASCII(IN LPWCH lpUNICODEStr)
  96. {
  97. if ( lpUNICODEStr == NULL )
  98. return NULL;
  99. // 获取多字节字符字节数;
  100. int cbMultiByte = WideCharToMultiByte(CP_OEMCP, 0, lpUNICODEStr, -1, NULL, 0, NULL, NULL);
  101. if ( cbMultiByte == 0 )
  102. return NULL;
  103. // 转换成多字节字符;
  104. CHAR *pMultiByteStr = new CHAR[cbMultiByte+1];
  105. memset(pMultiByteStr, 0, cbMultiByte + 1);
  106. int nWriteNum = WideCharToMultiByte(CP_OEMCP, 0, lpUNICODEStr, -1, pMultiByteStr, cbMultiByte, NULL, NULL);
  107. if (nWriteNum != cbMultiByte)
  108. {
  109. if (pMultiByteStr)
  110. delete []pMultiByteStr;
  111. return NULL;
  112. }
  113. return pMultiByteStr;
  114. }
  115. BOOL UNICODE2ASCII(IN LPWCH lpUNICODEStr, OUT LPCH pASCIIStr, IN CONST INT& nASCIIStrLen)
  116. {
  117. if ( lpUNICODEStr == NULL )
  118. return FALSE;
  119. // 获取多字节字符字节数;
  120. int cbMultiByte = WideCharToMultiByte(CP_OEMCP, 0, lpUNICODEStr, -1, NULL, 0, NULL, NULL);
  121. if ( cbMultiByte == 0 || cbMultiByte >= nASCIIStrLen )
  122. return FALSE;
  123. // 转换成多字节字符;
  124. memset((void*)pASCIIStr, 0, nASCIIStrLen);
  125. int nWriteNum = WideCharToMultiByte(CP_OEMCP, 0, lpUNICODEStr, -1, pASCIIStr, cbMultiByte, NULL, NULL);
  126. if (nWriteNum != cbMultiByte)
  127. {
  128. return FALSE;
  129. }
  130. return TRUE;
  131. }
  132. WCHAR* ASCII2UNICODE(IN LPCCH lpASCIIStr)
  133. {
  134. if ( lpASCIIStr == NULL )
  135. return NULL;
  136. // 获取宽字符字节数;
  137. int cchWideChar = MultiByteToWideChar(CP_ACP, 0, lpASCIIStr, -1, NULL, 0);
  138. if ( cchWideChar == 0)
  139. return NULL;
  140. // 转换成宽字符串;
  141. WCHAR *pWideChar = new WCHAR[cchWideChar + 1];
  142. memset(pWideChar, 0 , sizeof(WCHAR)*(cchWideChar + 1));
  143. int nWriteNum = MultiByteToWideChar(CP_ACP, 0, lpASCIIStr, -1, pWideChar, cchWideChar );
  144. if ( nWriteNum != cchWideChar)
  145. {
  146. if (pWideChar)
  147. delete []pWideChar;
  148. return NULL;
  149. }
  150. return pWideChar;
  151. }
  152. BOOL ASCII2UNICODE(IN LPCCH lpASCIIStr, OUT PWCH pUNICODEStr, IN CONST INT& nUNICODEStrLen)
  153. {
  154. if ( lpASCIIStr == NULL )
  155. return FALSE;
  156. // 获取宽字符字节数;
  157. int cchWideChar = MultiByteToWideChar(CP_ACP, 0, lpASCIIStr, -1, NULL, 0);
  158. if ( cchWideChar == 0 || cchWideChar >= nUNICODEStrLen)
  159. return FALSE;
  160. // 转换成宽字符串;
  161. memset(pUNICODEStr, 0 , sizeof(WCHAR)*nUNICODEStrLen);
  162. int nWriteNum = MultiByteToWideChar(CP_ACP, 0, lpASCIIStr, -1, pUNICODEStr, cchWideChar );
  163. if ( nWriteNum != cchWideChar)
  164. return FALSE;
  165. return TRUE;
  166. }
  167. // CTestApp 初始化
  168. char TwoHexCharToChar(char ch1,char ch2)
  169. {
  170. char Numb1;
  171. char Numb2;
  172. if (ch1 >= 'A')
  173. Numb1 = (toupper(ch1)-'0'-7)*16;
  174. else
  175. Numb1 = (ch1 - '0')*16;
  176. if (ch2 >= 'A')
  177. Numb2 = (toupper(ch2) - '0' - 7);
  178. else
  179. Numb2 = (ch2 - '0');
  180. return (Numb1 + Numb2);
  181. }
  182. void Str2HexStr(char *szHexString,CString szString,int *iHexStringLen)
  183. {
  184. int iLoop;
  185. int iCount;
  186. iLoop = 0;
  187. iCount = 0;
  188. szHexString[0] = '\0';
  189. while(1)
  190. {
  191. if (szString[iLoop] == '\0' || szString[iLoop + 1] == '\0')
  192. {
  193. break;
  194. }
  195. szHexString[iCount] = static_cast<char>(TwoHexCharToChar(szString[iLoop],szString[iLoop + 1]));
  196. iLoop ++;
  197. iLoop ++;
  198. iCount ++;
  199. }
  200. szHexString[iCount] = '\0';
  201. *iHexStringLen = iCount;
  202. }
  203. WORD AsciiToBYTE(BYTE btSrc)
  204. {
  205. WORD chDest = (WORD)btSrc;
  206. if ((btSrc >= 'A')&&(btSrc <= 'F'))
  207. {
  208. chDest = chDest - 'A' + 10;
  209. }
  210. else if ((btSrc >= 'a')&&(btSrc <= 'f'))
  211. {
  212. chDest = chDest - 'a' + 10;
  213. }
  214. else if ((btSrc >= '0')&&(btSrc <= '9'))
  215. {
  216. chDest -= '0';
  217. }
  218. return chDest;
  219. }
  220. CString convertString(IN LPCCH lpString)
  221. {
  222. CString str = lpString;
  223. CString strResult = _T("");
  224. INT nIndex = 0;
  225. CString strTemp = _T("");
  226. while ( str.Find("\\u") != -1)
  227. {
  228. nIndex = str.Find(_T("\\u"));
  229. strResult += str.Left(nIndex);
  230. strTemp = str.Mid(nIndex + 2, 4);
  231. str = str.Mid(nIndex + 2 +4);
  232. TCHAR szReturn[10] = {0};
  233. union __UNION_VAR_INT{
  234. BYTE ch[2];
  235. int value;
  236. }unionVarInt;
  237. unionVarInt.ch[0] = (AsciiToBYTE(strTemp.GetAt(2)) << 4) | (AsciiToBYTE(strTemp.GetAt(3)) & 0x00FF);
  238. unionVarInt.ch[1] = (AsciiToBYTE(strTemp.GetAt(0)) << 4) | (AsciiToBYTE(strTemp.GetAt(1)) & 0x00FF);
  239. WCHAR szWide[2] = {0};
  240. szWide[0] = unionVarInt.value;
  241. UNICODE2ASCII(szWide,szReturn,10);
  242. strResult += (CString)szReturn;
  243. }
  244. strResult += str;
  245. return strResult;
  246. }
  247. #define MAKEINT32(mark,len) ((INT32)(mark<<19 ) | (INT32)(len & 0x1FFF))
  248. void getXPJsonresult(IN CString strJson, IN CArray<CStringArray,CStringArray>& AryResult)
  249. {
  250. INT i = 0;
  251. INT nIndex = 0;
  252. INT nCount = 0;
  253. CString strTemp = _T("");
  254. CString strTemp2 = _T("");
  255. CString strMark = _T("{\"photo_list\": ");
  256. nCount = strJson.Replace(strMark, strMark);
  257. strJson += _T(", {\"photo_list\": ");
  258. AryResult.SetSize(nCount,1);
  259. strJson = strJson.Mid(strMark.GetLength());
  260. while ( strJson.Find(strMark) != -1 )
  261. {
  262. nIndex = strJson.Find(strMark);
  263. strTemp = strJson.Left(nIndex - 3);
  264. strJson = strJson.Mid(nIndex + strMark.GetLength());
  265. // 解析出Json内容;
  266. AryResult.ElementAt(i).RemoveAll();
  267. // 相片串;
  268. nIndex = strTemp.Find(_T(", "));
  269. if ( nIndex != -1)
  270. {
  271. strTemp2 = strTemp.Left(nIndex);
  272. strTemp2.TrimLeft(_T("\""));
  273. strTemp2.TrimRight(_T("\""));
  274. AryResult.ElementAt(i).Add(strTemp2);
  275. strTemp = strTemp.Mid(nIndex + 2);
  276. }
  277. // 商品数量;
  278. nIndex = strTemp.Find(_T("\"num\": "));
  279. if ( nIndex != -1)
  280. {
  281. strTemp = strTemp.Mid(nIndex + 7);
  282. nIndex = strTemp.Find(_T(", \"product_id\": "));
  283. if ( nIndex != -1)
  284. {
  285. strTemp2 = strTemp.Left(nIndex);
  286. AryResult.ElementAt(i).Add(strTemp2);
  287. strTemp = strTemp.Mid(nIndex + strlen(_T(", \"product_id\": ")));
  288. }
  289. }
  290. // 商品ID;
  291. nIndex = strTemp.Find(_T(", \"name\": "));
  292. if ( nIndex != -1)
  293. {
  294. strTemp2 = strTemp.Left(nIndex);
  295. strTemp2.TrimLeft(_T("\""));
  296. strTemp2.TrimRight(_T("\""));
  297. AryResult.ElementAt(i).Add(strTemp2);
  298. strTemp = strTemp.Mid(nIndex + _tcslen(_T(", \"name\": ")));
  299. }
  300. // 商品名称;
  301. if ( strTemp.GetLength() )
  302. {
  303. strTemp.TrimLeft(_T("\""));
  304. strTemp.TrimRight(_T("\""));
  305. AryResult.ElementAt(i).Add(strTemp);
  306. }
  307. i++;
  308. }
  309. }
  310. #include "Barcode.h"
  311. BOOL SaveBitmap(IN CDC *pDC, IN CBitmap* pBitmap, IN const INT& nWidth, IN const INT& nHeight, IN LPCTSTR lpSavepath)
  312. {
  313. DWORD dwBmpSize = ((nWidth + 31) / 32) * 4 * nHeight;
  314. HANDLE hFile = CreateFile(lpSavepath, GENERIC_READ | GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
  315. if (hFile == INVALID_HANDLE_VALUE)
  316. {
  317. //WriteLog(_T("二维码位图创建失败"));
  318. return FALSE;
  319. }
  320. HANDLE hFileMapping = CreateFileMapping(hFile, NULL, PAGE_READWRITE | SEC_COMMIT, 0,
  321. sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD) * 2 + dwBmpSize, NULL);
  322. LPBYTE lpbyMapView = (LPBYTE)MapViewOfFile(hFileMapping, FILE_MAP_WRITE, 0, 0, 0);
  323. ZeroMemory(lpbyMapView, sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD) * 2 + dwBmpSize);
  324. //结构体地址割付
  325. LPBITMAPFILEHEADER pbfh = (LPBITMAPFILEHEADER)lpbyMapView;
  326. LPBITMAPINFO pbmi = (LPBITMAPINFO)(lpbyMapView + sizeof(BITMAPFILEHEADER));
  327. LPVOID pbdt = lpbyMapView + sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD) * 2;
  328. // BITMAPFILEHEADER
  329. //pbfh->bfType = (WORD) (('M' << 8) | 'B'); // "BM"
  330. // BMP类型,与上面同值;
  331. pbfh->bfType = 0x4D42;
  332. pbfh->bfSize = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD) * 2 + dwBmpSize; // 文件总长;
  333. pbfh->bfReserved1 = 0;
  334. pbfh->bfReserved2 = 0;
  335. pbfh->bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD) * 2; // 位图数据相对于文件头的偏移量;
  336. // LPBITMAPINFO->BITMAPINFOHEADER
  337. pbmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
  338. pbmi->bmiHeader.biWidth = nWidth;
  339. pbmi->bmiHeader.biHeight = nHeight;
  340. pbmi->bmiHeader.biPlanes = 1;
  341. pbmi->bmiHeader.biBitCount = 1;
  342. pbmi->bmiHeader.biCompression = BI_RGB;
  343. pbmi->bmiHeader.biSizeImage = dwBmpSize;
  344. pbmi->bmiHeader.biXPelsPerMeter = 3780;
  345. pbmi->bmiHeader.biYPelsPerMeter = 3780;
  346. pbmi->bmiHeader.biClrUsed = 0;
  347. pbmi->bmiHeader.biClrImportant = 0;
  348. // 放大到指定的像素宽高;
  349. CDC* pWorkDC = new CDC;
  350. pWorkDC->CreateCompatibleDC(NULL);
  351. CBitmap* pWorkBitmap = new CBitmap;
  352. pWorkBitmap->CreateBitmap(nWidth, nHeight, 1, 1, NULL);
  353. CBitmap* pOldBitmap = pWorkDC->SelectObject(pWorkBitmap);
  354. pWorkDC->StretchBlt(0, 0, nWidth, nHeight, pDC, 0, 0, nWidth, nHeight, SRCCOPY);
  355. GetDIBits(pWorkDC->m_hDC, (HBITMAP)*pWorkBitmap, 0, nHeight, pbdt, pbmi, DIB_RGB_COLORS);
  356. pWorkDC->SelectObject(pOldBitmap);
  357. delete pWorkBitmap;
  358. delete pWorkDC;
  359. UnmapViewOfFile(lpbyMapView);
  360. CloseHandle(hFileMapping);
  361. CloseHandle(hFile);
  362. return TRUE;
  363. }
  364. void DrawString(IN CDC* pdc, IN CONST INT& nFontSize, IN LPCTSTR lpFontName, IN LPCTSTR lpString, IN OUT CRect &rcString)
  365. {
  366. if ( !pdc || !lpString )
  367. return;
  368. LOGFONT log;
  369. // 设置字体字号;
  370. log.lfHeight = -MulDiv(nFontSize ? nFontSize : 9, GetDeviceCaps(pdc->GetSafeHdc(), LOGPIXELSY), 72);
  371. log.lfWidth = 0;
  372. log.lfEscapement = 0;
  373. log.lfOrientation = 0;
  374. log.lfWeight = FW_REGULAR;
  375. log.lfItalic = false;
  376. log.lfUnderline = false;
  377. log.lfStrikeOut = 0;
  378. log.lfCharSet = ANSI_CHARSET;
  379. log.lfOutPrecision = OUT_DEFAULT_PRECIS;
  380. log.lfClipPrecision = CLIP_DEFAULT_PRECIS;
  381. log.lfQuality = DEFAULT_QUALITY;
  382. log.lfPitchAndFamily = DEFAULT_PITCH || FF_ROMAN;
  383. // 设置字体名称;
  384. strcpy(log.lfFaceName, (lpFontName && (lpFontName[0] != _T('\0'))) ? lpFontName : _T("Arial"));
  385. CFont cf;
  386. cf.CreateFontIndirect(&log);
  387. CFont *oldf = pdc->SelectObject(&cf);
  388. SIZE Size;
  389. GetTextExtentPoint32(pdc->GetSafeHdc(), lpString, _tcslen(lpString), &Size);
  390. rcString.SetRect(rcString.left, rcString.top, Size.cx, Size.cy + rcString.top);
  391. pdc->TextOut(rcString.left, rcString.top, lpString);
  392. }
  393. void ExportBarCodeImg(
  394. IN CONST INT& nBarCodeType, // 条码类型;
  395. IN INT nWidth, // 图片宽(最好传屏幕宽);
  396. IN INT nHeight, // 图片高(最好传屏幕高);
  397. IN CONST INT& nPenWidth, // 条码柱宽;
  398. IN CONST INT& nPenHeight, // 条码柱高;
  399. IN LPCTSTR lpBarAutoId, // 商品AutoId;
  400. IN LPCTSTR lpBarOrderNum, // 订单号;
  401. IN LPCTSTR lpBarProduct, // 商品名称;
  402. IN LPCTSTR lpSaveImgDirectory, // 要保存的目录;
  403. IN LPCTSTR lpSaveImgName // 要保存的名称(NULL则使用商品名称)
  404. )
  405. {
  406. Barcode128 code;
  407. code.Encode128B(lpBarAutoId);
  408. // 计算出条码宽度;
  409. INT nBarCodeWidth = code.GetBarCodeWidth(nPenWidth);
  410. if ( nBarCodeWidth > nWidth )
  411. nWidth = nBarCodeWidth + 10;
  412. // 创建位图;
  413. CBitmap *pBitmap = new CBitmap;
  414. pBitmap->CreateBitmap(nWidth,nHeight,1,1,NULL);
  415. // 创建DC环境;
  416. CDC *pBarCodeDC = new CDC;
  417. pBarCodeDC->CreateCompatibleDC(NULL);
  418. // 将位图关联DC;
  419. pBarCodeDC->SelectObject(pBitmap);
  420. pBarCodeDC->PatBlt(0, 0, nWidth, nHeight, WHITENESS);
  421. // 开始画条码;
  422. CRect rcBar(5, 5, nBarCodeWidth + 5, nPenHeight);
  423. COLORREF clrBar = RGB(0,0,0);
  424. COLORREF clrSpace = RGB(255,255,255);
  425. code.DrawBarcode(pBarCodeDC->m_hDC, rcBar.left, rcBar.top, nPenHeight, nPenHeight, clrBar, clrSpace, nPenWidth);
  426. nBarCodeWidth = max(nBarCodeWidth, rcBar.Width());
  427. CString strTemp;
  428. strTemp.Format(_T("AutoId:%s"), lpBarAutoId);
  429. CRect rcString(rcBar.left, rcBar.bottom + 5, rcBar.right, rcBar.bottom + 10);
  430. DrawString(pBarCodeDC, 9, _T("宋体"), strTemp, rcString);
  431. nBarCodeWidth = max(nBarCodeWidth, rcString.Width());
  432. strTemp.Format(_T("订单号:%s"), lpBarOrderNum);
  433. rcString.SetRect(rcString.left, rcString.bottom + 5, rcString.right, rcString.bottom + 10);
  434. DrawString(pBarCodeDC, 9, _T("宋体"), strTemp, rcString);
  435. nBarCodeWidth = max(nBarCodeWidth, rcString.Width());
  436. strTemp.Format(_T("商品名:%s"), lpBarOrderNum);
  437. rcString.SetRect(rcString.left, rcString.bottom + 5, rcString.right, rcString.bottom + 10);
  438. DrawString(pBarCodeDC, 9, _T("宋体"), strTemp, rcString);
  439. nBarCodeWidth = max(nBarCodeWidth, rcString.Width());
  440. CString strSavepath;
  441. strSavepath.Format(_T("%s\\%s.bmp"), lpSaveImgDirectory, (lpSaveImgName && ( lpSaveImgName[0] != _T('\0'))) ? lpSaveImgName : lpBarProduct );
  442. SaveBitmap(pBarCodeDC, pBitmap, nBarCodeWidth + 10, rcString.bottom + 5, strSavepath);
  443. if ( pBitmap )
  444. delete pBitmap;
  445. if ( pBarCodeDC )
  446. delete pBarCodeDC;
  447. }
  448. BOOL CTestApp::InitInstance()
  449. {
  450. // 如果一个运行在 Windows XP 上的应用程序清单指定要
  451. // 使用 ComCtl32.dll 版本 6 或更高版本来启用可视化方式,
  452. //则需要 InitCommonControlsEx()。否则,将无法创建窗口。
  453. INITCOMMONCONTROLSEX InitCtrls;
  454. InitCtrls.dwSize = sizeof(InitCtrls);
  455. // 将它设置为包括所有要在应用程序中使用的
  456. // 公共控件类。
  457. InitCtrls.dwICC = ICC_WIN95_CLASSES;
  458. InitCommonControlsEx(&InitCtrls);
  459. CWinAppEx::InitInstance();
  460. AfxEnableControlContainer();
  461. CString strMaskId = _T("18665281860_0_545");
  462. CString strBranchId = _T("");
  463. CString strStudioName = _T("");
  464. CString strStudioTel = _T("18665281860");
  465. CString strOrderNum = _T("545");
  466. CString strScenery = _T("内景");
  467. CString strCustomerName = _T("张三");
  468. CString strCustomerTel = _T("15089892312");
  469. TCHAR szReturnString[1024*100] = {0};
  470. if (lyfzLibrary::LoadCloudSelectionLib())
  471. {
  472. // if ( lyfzLibrary::g_uploadorder(strMaskId, 0, strStudioName, strStudioTel, strOrderNum, strScenery, strCustomerName, strCustomerTel, szReturnString, MAX_PATH) )
  473. // {
  474. // OutputDebugString(_T("dfdfdfdfdfdfdf\n"));
  475. // CString strJson = _T("");
  476. // if ( lyfzLibrary::g_uploadgoodinfo(strMaskId, strJson) )
  477. // {
  478. // }
  479. // }
  480. CStringArray ary;
  481. ary.Add("E:\\ImageTest\\V27B");
  482. // ary.Add("E:\\ImageTest\\V27B\\2.png");
  483. // ary.Add("E:\\ImageTest\\V27B\\3.png");
  484. // ary.Add("E:\\ImageTest\\V27B\\4.png");
  485. // ary.Add("E:\\ImageTest\\V27B\\5.png");
  486. // ary.Add("E:\\ImageTest\\V27B\\6.png");
  487. // ary.Add("E:\\ImageTest\\V27B\\7.png");
  488. // ary.Add("E:\\ImageTest\\V27B\\8.png");
  489. // ary.Add("E:\\ImageTest\\V27B\\9.png");
  490. // ary.Add("E:\\ImageTest\\V27B\\10.png");
  491. lyfzLibrary::g_uploadimg(
  492. 0,
  493. strMaskId,
  494. strOrderNum,
  495. strScenery,
  496. "云选片",
  497. 500, 600,
  498. ary, ary, ary);
  499. }
  500. return FALSE;
  501. // 标准初始化
  502. // 如果未使用这些功能并希望减小
  503. // 最终可执行文件的大小,则应移除下列
  504. // 不需要的特定初始化例程
  505. // 更改用于存储设置的注册表项
  506. // TODO: 应适当修改该字符串,
  507. // 例如修改为公司或组织名
  508. SetRegistryKey(_T("应用程序向导生成的本地应用程序"));
  509. CTestDlg dlg;
  510. m_pMainWnd = &dlg;
  511. INT_PTR nResponse = dlg.DoModal();
  512. if (nResponse == IDOK)
  513. {
  514. // TODO: 在此放置处理何时用
  515. // “确定”来关闭对话框的代码
  516. }
  517. else if (nResponse == IDCANCEL)
  518. {
  519. // TODO: 在此放置处理何时用
  520. // “取消”来关闭对话框的代码
  521. }
  522. // 由于对话框已关闭,所以将返回 FALSE 以便退出应用程序,
  523. // 而不是启动应用程序的消息泵。
  524. return FALSE;
  525. }