YLGL.cpp 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852
  1. // YLGL.cpp : Defines the class behaviors for the application.
  2. //
  3. #include "stdafx.h"
  4. #include "YLGL.h"
  5. #include "ChildFrm.h"
  6. #include "YLGLDoc.h"
  7. #include "YLGLView.h"
  8. #include "ChoosePhotoSkin.h"
  9. #include "DBConfig.h"
  10. #include "Lzari.h"
  11. #include "library.h"
  12. //#include "SQLite3Interface.h"
  13. #ifdef _DEBUG
  14. #define new DEBUG_NEW
  15. #undef THIS_FILE
  16. static char THIS_FILE[] = __FILE__;
  17. #endif
  18. MainFrimDlg2 *g_pMainWnd2 = NULL;
  19. FILE *g_pf; // add by Jeff 2014.05.24
  20. #define _USE_CONSOLE_FOR_DEBUG 0 // add by Jeff 2014.05.24
  21. BEGIN_MESSAGE_MAP(CYLGLApp, CWinApp)
  22. ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
  23. ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
  24. ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
  25. END_MESSAGE_MAP()
  26. /////////////////////////////////////////////////////////////////////////////
  27. // CYLGLApp construction
  28. // Jeff remark;
  29. DEVMODE g_dm; // 打印或显示设备的预设值和环境值;
  30. CYLGLApp::CYLGLApp()
  31. {
  32. // Place all significant initialization in InitInstance g_gridcol1
  33. g_dm.dmSize = sizeof(DEVMODE);
  34. EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &g_dm); // 返回显示设备的当前设置的绘图模式;
  35. CRect rc;
  36. HWND wnd = GetDesktopWindow();
  37. if (wnd)
  38. {
  39. ::GetWindowRect(wnd, &rc);
  40. g_screenwid = rc.Width();
  41. g_screenhei = rc.Height();
  42. }
  43. else
  44. {
  45. g_screenwid = g_dm.dmPelsWidth;
  46. g_screenhei = g_dm.dmPelsHeight;
  47. }
  48. g_fscalex = (float)g_screenwid / 1024.0;
  49. g_fscaley = (float)g_screenhei / 768.0;
  50. /* begin Jeff 这段代码未有使用意义 */
  51. wnd = ::FindWindow("Shell_TrayWnd", 0);
  52. ::GetWindowRect(wnd, &rc);
  53. int hei = rc.Height();
  54. rc = CRect(0, 0, g_screenwid, g_screenhei - hei);
  55. /* end Jeff 这段代码未有使用意义 */
  56. g_fscalex = (float)g_screenwid / 2000.0;
  57. g_fscaley = (float)(g_screenhei - hei) / 1400.0;
  58. }
  59. CYLGLApp theApp;
  60. class CAboutDlg : public CDialog
  61. {
  62. public:
  63. CAboutDlg();
  64. enum { IDD = IDD_ABOUTBOX };
  65. protected:
  66. virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
  67. protected:
  68. DECLARE_MESSAGE_MAP()
  69. };
  70. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  71. {
  72. }
  73. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  74. {
  75. CDialog::DoDataExchange(pDX);
  76. }
  77. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  78. END_MESSAGE_MAP()
  79. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  80. /////////////////////////////////////////////////////////////////////////////
  81. // CYLGLApp message handlers
  82. BOOL CYLGLApp::InitInstance()
  83. {
  84. TCHAR szDrive[_MAX_DRIVE] = { 0 };
  85. TCHAR szDir[_MAX_DIR] = { 0 };
  86. TCHAR szFna[_MAX_DIR] = { 0 };
  87. TCHAR szExt[_MAX_DIR] = { 0 };
  88. ::GetModuleFileName(NULL, g_szModuleFileName, sizeof(g_szModuleFileName) / sizeof(TCHAR));
  89. sprintf(g_szModulePath, _T("%s"), g_szModuleFileName);
  90. _tsplitpath(g_szModulePath, szDrive, szDir, szFna, szExt);
  91. _tcscpy(g_szModulePath, szDrive);
  92. _tcscat(g_szModulePath, szDir);
  93. /************************************************************************/
  94. #if _USE_CONSOLE_FOR_DEBUG // Jeff.控制台输出信息;
  95. AllocConsole(); // 开辟控制台
  96. SetConsoleTitle(_T("+lyfz:调试信息输出++++++")); // 设置控制台窗口标题
  97. freopen("CONOUT$","w+t",stdout); // 重定向输出
  98. freopen("CONIN$","r+t",stdin); // 重定向输入
  99. #endif
  100. //printf("Jeff:m_lpCmdLine = %s\n\n",m_lpCmdLine);//Jeffprintf
  101. // Jeff.命令行genbranchdata值,由本机服务端DBServer.exe执行输入;
  102. // 使用批处理可以指定这个命令行的内容
  103. //
  104. // ---------批处理---------------
  105. // @echo off
  106. // start %~dp0YLGL.exe genbranchdata
  107. // ---------批处理--------------
  108. //
  109. // DBServer.exe调用Shell命令传入该命令行genbranchdata值;
  110. if (m_lpCmdLine[0] == _T('\0')) //没有命令行参数
  111. {
  112. // return false;
  113. //WriteClientLog("无命令行输入");
  114. }
  115. else
  116. {
  117. CString str = m_lpCmdLine;
  118. if (str == "genbranchdata")
  119. {
  120. //WriteClientLog("命令行=genbranchdata");
  121. g_bGenBranchData = 1;
  122. }
  123. }
  124. if (g_bGenBranchData == 0)
  125. {
  126. HANDLE hObject = CreateMutex(NULL, FALSE, _T("CYLGLAppXiao"));
  127. if (GetLastError() == ERROR_ALREADY_EXISTS)
  128. {
  129. AfxMessageBox("提醒:软件已启动!", MB_ICONINFORMATION);
  130. }
  131. }
  132. AfxEnableControlContainer();
  133. g_listctrlfont.CreatePointFont(110, _T("System"));
  134. #ifdef _AFXDLL
  135. Enable3dControls(); // Call this when using MFC in a shared DLL
  136. #else
  137. Enable3dControlsStatic(); // Call this when linking to MFC statically
  138. #endif
  139. GetDebugPriv();
  140. // 获取升级的文件版本;
  141. GetFileVersion(NULL, g_arrFileVersion);
  142. // Jeff:dbconfig.dat里的信息,可以包含*.ly.com和计算机名称、IP地址三种;
  143. // 1.*.ly.com的需要解析出分店的IP地址;
  144. // 2.*.ly.com的解析是需要连接到公司服务器软件,然后返回ip地址,保存在ip.txt里;
  145. // Jeff.dbconfig.dat里保存的是*.ly.com信息,一般是用在外网访问花生壳域名的服务端软件;
  146. char path[MAX_PATH];
  147. ::GetModuleFileName(NULL, path, MAX_PATH);
  148. g_mainpath = path;
  149. g_mainpath = g_mainpath.Left(g_mainpath.ReverseFind('\\'));
  150. CString configpath = g_mainpath + "\\dbconfig.dat";
  151. // 1.初始化SOCKET
  152. int nResult = Transport_Init();
  153. if (TRANSPORT_OK != nResult)
  154. {
  155. WriteClientLog("网络初始化失败,软件退出!");
  156. return false;
  157. }
  158. // 2.获取服务器地址;
  159. if (g_bGenBranchData)
  160. {
  161. // Jeff.启动g_bGenBranchData功能,是指由服务器DBServer.exe使用Shell命令来调用YLGL.exe并传入genbranchdata命令行
  162. // 而此时YLGL.exe读取本机计算机名;
  163. char server[50];
  164. DWORD leng = 50;
  165. ::GetComputerName(server, &leng);
  166. g_serverbak = g_server = server;
  167. g_serverbak.TrimLeft();
  168. g_serverbak.TrimRight(".");
  169. g_serverbak.TrimRight();
  170. // Jeff. find(.ly.com)是不需要判断的一步;
  171. if (g_server.Find(".ly.com") == -1 && g_server.Find("192.168.") == -1)
  172. MyGetIPByName(g_server);
  173. if (g_server.Find("192.168.") != -1)
  174. g_serverarray.Add(g_server);
  175. // printf("Jeff.g_bGenBranchData=1,g_server=%s,g_serverbak=%s\n\n",g_server,g_serverbak);//Jeffprintf
  176. }
  177. else
  178. {
  179. CFile fp;
  180. ll: if (fp.Open(configpath, CFile::modeRead))
  181. {
  182. DBSAVE db;
  183. memset(&db, 0, sizeof(db));
  184. fp.Read(&db, sizeof(db));
  185. fp.Close();
  186. char server[50];
  187. char user[50];
  188. char psw[50];
  189. memset(server, 0, sizeof(char) * 50);
  190. memset(user, 0, sizeof(char) * 50);
  191. memset(psw, 0, sizeof(char) * 50);
  192. for (int i = 0; i < 50; i++)
  193. {
  194. if (db.server[i])
  195. server[i] = 500 - db.server[i];
  196. if (db.user[i])
  197. user[i] = 500 - db.user[i];
  198. if (db.psw[i])
  199. psw[i] = 500 - db.psw[i];
  200. }
  201. #ifdef TEST_LOCAL
  202. DWORD leng=50;
  203. ::GetComputerName (server, &leng);
  204. #endif
  205. g_serverbak = g_server = server;
  206. g_serverbak.TrimLeft();
  207. g_serverbak.TrimRight(".");
  208. g_serverbak.TrimRight();
  209. if (g_server.Find(".ly.com") == -1 && g_server.Find("192.168.") == -1)
  210. MyGetIPByName(g_server);
  211. if (g_server.Find("192.168.") != -1)
  212. g_serverarray.Add(g_server);
  213. if (g_server.IsEmpty())
  214. {
  215. AfxMessageBox("获取IP失败! 请确认服务器名 " + g_serverbak + " 是否正确? 或修改网络设置或与系统hosts文件!");
  216. // g_serverarray.Add (g_serverbak);
  217. // g_server=g_serverbak;
  218. return 0;
  219. }
  220. IsShareFolderExist(server);// add by Jeff,检测共享目录是否存在可写;
  221. // 10.0.0.0/8:10.0.0.0~10.255.255.255
  222. // 172.16.0.0/12:172.16.0.0~172.31.255.255
  223. // 192.168.0.0/16:192.168.0.0~192.168.255.255
  224. if (g_server.Find("10.") != -1 || g_server.Find("172.") != -1 || g_server.Find("192.168") != -1)
  225. {
  226. }
  227. else
  228. {
  229. // g_serverbak="localserver";
  230. }
  231. }
  232. else
  233. {
  234. AfxMessageBox("请先设置数据库服务器!", MB_ICONINFORMATION);
  235. DBConfig dlg;
  236. dlg.DoModal();
  237. goto ll;
  238. return false;
  239. }
  240. }
  241. #if 0 // 测试;
  242. //////////////////////////////////////////////////////////////////////////
  243. // 测试;
  244. TCHAR szdb[MAX_PATH] = {0};
  245. sprintf(szdb,_T("%s%s"),g_szModulePath,_T("remoteinfo.db"));
  246. CSQLite3Interface db;
  247. if(!PathFileExists(szdb))
  248. {
  249. nResult = db.opendb(szdb);
  250. if(nResult == 0)
  251. {
  252. nResult = db.creattbl(CREATE_DB_TBL_);
  253. if ( nResult )
  254. {
  255. AfxMessageBox(_T("创建数据库表失败!"));
  256. }
  257. else
  258. {
  259. // 创建表成功,测试添加数据到表中;
  260. // 初始化表数据;
  261. STRemoteInfo info[13] =
  262. {
  263. {1,_T("分店1"),_T("127.0.0.1"),_T("20150403120530.ly.com"),_T("lyfz1"),_T("异选原片$"),0,100 },
  264. {1,_T("分店2"),_T("127.0.0.1"),_T("20150403120531.ly.com"),_T("lyfz2"),_T("异选原片$"),0,100 },
  265. {1,_T("分店3"),_T("127.0.0.1"),_T("20150403120532.ly.com"),_T("lyfz3"),_T("异选原片$"),0,100 },
  266. {1,_T("分店4"),_T("127.0.0.1"),_T("20150403120533.ly.com"),_T("lyfz4"),_T("异选原片$"),0,100 },
  267. {1,_T("分店5"),_T("127.0.0.1"),_T("20150403120534.ly.com"),_T("lyfz5"),_T("异选原片$"),0,100 },
  268. {1,_T("分店6"),_T("127.0.0.1"),_T("20150403120535.ly.com"),_T("lyfz6"),_T("异选原片$"),0,100 },
  269. {1,_T("分店7"),_T("127.0.0.1"),_T("20150403120536.ly.com"),_T("lyfz7"),_T("异选原片$"),0,100 },
  270. {1,_T("分店8"),_T("127.0.0.1"),_T("20150403120537.ly.com"),_T("lyfz8"),_T("异选原片$"),0,100 },
  271. {1,_T("分店9"),_T("127.0.0.1"),_T("20150403120538.ly.com"),_T("lyfz9"),_T("异选原片$"),0,100 },
  272. {1,_T("分店A"),_T("127.0.0.1"),_T("20150403120539.ly.com"),_T("lyfzA"),_T("异选原片$"),0,100 },
  273. {1,_T("分店B"),_T("127.0.0.1"),_T("20150403120540.ly.com"),_T("lyfzB"),_T("异选原片$"),0,100 },
  274. {1,_T("分店C"),_T("127.0.0.1"),_T("20150403120541.ly.com"),_T("lyfzC"),_T("异选原片$"),0,100 },
  275. {1,_T("分店D"),_T("127.0.0.1"),_T("20150403120542.ly.com"),_T("lyfzD"),_T("异选原片$"),0,100 }
  276. };
  277. // 循环插入数据;
  278. TCHAR szInsert[MAX_PATH] = {0};
  279. for ( int n = 0; n < 13; n++)
  280. {
  281. sprintf(
  282. szInsert,
  283. _T("insert into remoteinfo(inuse,branch,ip,domain,host,sharedirectory,delaftertakeway,deldays) values ('%d','%s','%s','%s','%s','%s',%d,%d);"),
  284. info[n].bInUse,
  285. info[n].szBranch,
  286. info[n].szIP,
  287. info[n].szDoMain,
  288. info[n].szHost,
  289. info[n].szShareDirectory,
  290. info[n].bDelAfterTakeWay,
  291. info[n].dwDelDays);
  292. TRACE(szInsert);
  293. TRACE(_T("\n"));
  294. // 插入数据;
  295. nResult = db.isnerttbl(szInsert);
  296. if ( nResult != 0)
  297. {
  298. AfxMessageBox(_T("插入数据失败!"));
  299. }
  300. }
  301. // 查询数据;
  302. vector<STRemoteInfo> vtRemoteInfo;
  303. nResult = db.gettbl_remoteinfo(_T("select * from remoteinfo"),vtRemoteInfo);
  304. for (vector<STRemoteInfo>::iterator it = vtRemoteInfo.begin(); it != vtRemoteInfo.end(); it++)
  305. {
  306. // 打印出结果;
  307. TCHAR szPrintf[MAX_PATH] = {0};
  308. sprintf(szPrintf,_T("%d,%s,%s,%s,%s,%s,%d,%d\n"),
  309. it->bInUse,
  310. it->szBranch,
  311. it->szIP,
  312. it->szDoMain,
  313. it->szHost,
  314. it->szShareDirectory,
  315. it->bDelAfterTakeWay,
  316. it->dwDelDays);
  317. TRACE(szPrintf);
  318. TRACE(_T("\n"));
  319. }
  320. }
  321. }
  322. else
  323. {
  324. AfxMessageBox(_T("打开数据库失败!"));
  325. }
  326. }
  327. db.closedb();
  328. //////////////////////////////////////////////////////////////////////////
  329. #endif
  330. CStdioFile fp2;
  331. if (fp2.Open(g_mainpath + "\\title.txt", CFile::modeRead))
  332. {
  333. fp2.ReadString(g_title);
  334. fp2.Close();
  335. }
  336. //free((void*)m_pszAppName);
  337. m_pszAppName = _tcsdup(g_title + "影楼管理系统");
  338. g_titlefont.CreatePointFont(160, _T("宋体"));
  339. SetRegistryKey(_T("LYFZ-YLGL"));
  340. CString version = _T("Version 1.0");
  341. g_bRedSkin = AfxGetApp()->GetProfileInt(version, "redskin", 0);
  342. if (g_bRedSkin)
  343. {
  344. g_gridcol1 = RGB(241, 180, 198);
  345. g_gridcol2 = RGB(237, 157, 182);
  346. g_bkcol = RGB(235, 149, 174);
  347. }//184, 184
  348. g_editbkbrush.CreateSolidBrush(g_bkcol);
  349. LoadStdProfileSettings(); // Load standard INI file options (including MRU)
  350. GdiplusStartupInput gdiplusStartupInput;
  351. GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
  352. // Jeff.若程序没有足够的权限,则会注册失败;
  353. // Jeff..若文件不存在呢,注册就无意义;
  354. CString temp;
  355. temp.Format("%s\\MSCHRT20.OCX", g_mainpath);
  356. OFSTRUCT ofStruct;
  357. OpenFile(temp, &ofStruct, OF_EXIST);
  358. if (ERROR_FILE_NOT_FOUND != GetLastError())
  359. {
  360. RegisterOcx(temp);
  361. }
  362. // Jeff.IRStartup属于换肤库的启动函数;
  363. HINSTANCE hModule = GetModuleHandle(NULL);
  364. IRStartup(hModule, GetCurrentThreadId());
  365. CMultiDocTemplate* pDocTemplate;
  366. pDocTemplate = new CMultiDocTemplate(
  367. IDR_MAINFRAME,
  368. NULL,
  369. RUNTIME_CLASS(CChildFrame), // custom MDI child frame
  370. RUNTIME_CLASS(CYLGLView));
  371. AddDocTemplate(pDocTemplate);
  372. // create main MDI Frame window
  373. CMainFrame* pMainFrame = new CMainFrame;
  374. if (!pMainFrame->LoadFrame(IDR_MAINFRAME)) // LoadFrame调用OnCreate
  375. {
  376. return FALSE;
  377. }
  378. m_pMainWnd = pMainFrame;
  379. // 加载OfficeXP风格菜单
  380. #ifndef NEW_SKIN
  381. CMenu* pMenu = m_pMainWnd->GetMenu();
  382. if (pMenu)pMenu->DestroyMenu();
  383. HMENU hMenu = ((CMainFrame*) m_pMainWnd)->NewMenu();
  384. pMenu = CMenu::FromHandle( hMenu );
  385. m_pMainWnd->SetMenu(pMenu);
  386. ((CMainFrame*)m_pMainWnd)->m_hMenuDefault = hMenu;
  387. #endif
  388. // Parse command line for standard shell commands, DDE, file open
  389. ////////////////////////////////////////////////////
  390. // 禁止自动新建子窗口
  391. // CCommandLineInfo cmdInfo;
  392. // ParseCommandLine(cmdInfo);
  393. // // Dispatch commands specified on the command line
  394. // if (!ProcessShellCommand(cmdInfo))
  395. // return FALSE;
  396. m_pMainWnd->SetWindowText(g_title + "影楼管理系统");
  397. m_pMainWnd->UpdateWindow();
  398. SetDialogBkColor(g_bkcol, RGB(0, 0, 0));
  399. return TRUE;
  400. }
  401. BOOL CYLGLApp::IsShareFolderExist(char *szServerName)
  402. {
  403. char szPath1[MAX_PATH] = { 0 };
  404. sprintf(szPath1, "\\\\%s\\%s", szServerName, "电话录音(管理软件)$");
  405. IsExistFolder(szPath1);
  406. sprintf(szPath1, "\\\\%s\\%s", szServerName, "客户原片(管理软件)$");
  407. IsExistFolder(szPath1);
  408. sprintf(szPath1, "\\\\%s\\%s", szServerName, "精修好的片(管理软件)$");
  409. IsExistFolder(szPath1);
  410. sprintf(szPath1, "\\\\%s\\%s", szServerName, "礼服图片(管理软件)$");
  411. IsExistFolder(szPath1);
  412. sprintf(szPath1, "\\\\%s\\%s", szServerName, "设计好的片(管理软件)$");
  413. IsExistFolder(szPath1);
  414. sprintf(szPath1, "\\\\%s\\%s", szServerName, "修好的片(管理软件)$");
  415. IsExistFolder(szPath1);
  416. return TRUE;
  417. }
  418. int CYLGLApp::DoMessageBox(LPCTSTR lpszPrompt, UINT nType, UINT nIDPrompt)
  419. {
  420. return CWinApp::DoMessageBox(lpszPrompt, nType, nIDPrompt);
  421. }
  422. // App command to run the dialog
  423. void CYLGLApp::OnAppAbout()
  424. {
  425. CAboutDlg aboutDlg;
  426. aboutDlg.DoModal();
  427. }
  428. int CYLGLApp::ExitInstance()
  429. {
  430. //关闭gdiplus的环境
  431. GdiplusShutdown(gdiplusToken);
  432. for (int i = 0; i < g_pointerarray.GetSize(); i++)
  433. delete[](g_pointerarray.ElementAt(i));
  434. IRComplete();
  435. #if _USE_CONSOLE_FOR_DEBUG
  436. FreeConsole(); //释放控制台;
  437. #endif
  438. //WriteLog("退出系统");//Jeff.add
  439. return CWinApp::ExitInstance();
  440. }
  441. int GetPos(DWORD leng)
  442. {
  443. if (g_lengarray.GetSize() == 0)
  444. {
  445. g_sendhead.bsql = 0;
  446. g_sendhead.code[0] = 105; //Jeff.服务器返回10.lia文件的数据、文件大小;
  447. g_sendhead.tabcount = 1;
  448. g_pMainWnd->ProcessChatMessageRequest2(1);
  449. if (g_bSendOK == 0) return -1;
  450. DWORD leng;
  451. DWORD readbytes = 0;
  452. // Jeff.remark.2014.06.26
  453. // g_pData 里此时保存的是10.lia文件内容;
  454. // 根据10.lia的结构,解释其它内部数据;
  455. // 目前没有其结构文档解释,暂时未知10.lia内含什么数据种类;
  456. // 以下是根据代码假设的内容:
  457. // -------------------------------
  458. // 4 byte.某文件A大小,用dwLengthA表示;
  459. // dwLengthA byte:文件A的数据
  460. // 4 byte.某文件B大小,用dwLengthB表示;
  461. // dwLengthB byte:文件B的数据;
  462. // ------以下文件组C-------------
  463. // 4 byte.某文件组C大小,用dwLengthC表示;
  464. // dwLengthC:某文件组C的数据;
  465. // 某文件C的数据结构:RESDATA2
  466. // 文件组C文件个数nCount = dwLengthC/sizeof(RESDATA2);
  467. //---------------------------------------
  468. // 10.lia文件总大小:dwSum = dwLengthA+dwLengthB+dwLengthC;
  469. // 10.lia文件内数据结构种类有三种:A,B,C 其中C为一组同类型数据;
  470. // 10.lia文件内数据结构个数: 2 + nCount;
  471. // --------------------------------
  472. ENCODE_START
  473. memcpy(&leng, g_pData + readbytes, sizeof(DWORD));
  474. readbytes += sizeof(DWORD);
  475. {
  476. CMemFile memfile;
  477. memfile.Attach(g_pData + readbytes, leng);
  478. readbytes += leng;
  479. CArchive ar(&memfile, CArchive::load);
  480. g_lengarray.Serialize(ar);
  481. ar.Close();
  482. memfile.Detach();
  483. }
  484. memcpy(&leng, g_pData + readbytes, sizeof(DWORD));
  485. readbytes += sizeof(DWORD);
  486. {
  487. CMemFile memfile;
  488. memfile.Attach(g_pData + readbytes, leng);
  489. readbytes += leng;
  490. CArchive ar(&memfile, CArchive::load);
  491. g_btnlengarray.Serialize(ar);
  492. ar.Close();
  493. memfile.Detach();
  494. }
  495. memcpy(&leng, g_pData + readbytes, sizeof(DWORD));
  496. readbytes += sizeof(DWORD);
  497. ENCODE_END
  498. int count = leng / sizeof(RESDATA2);
  499. for (int i = 0; i < count; i++)
  500. {
  501. BYTE *pData = new BYTE[sizeof(RESDATA2)];
  502. memcpy(pData, g_pData + readbytes, sizeof(RESDATA2));
  503. readbytes += sizeof(RESDATA2);
  504. g_pointerarray.Add(pData);
  505. }
  506. }
  507. for (int i = 0; i < g_lengarray.GetSize(); i++)
  508. {
  509. if (leng == g_lengarray.ElementAt(i))
  510. {
  511. return i;
  512. }
  513. }
  514. return -1;
  515. }
  516. extern void SizeToContent(HWND hwnd, Image *img);
  517. BOOL LoadLia(CString path, BYTE **pData, BYTE **pDataBegin, Image **pBk, HWND hwnd)
  518. {
  519. try
  520. {
  521. CFile fp;
  522. if (!fp.Open(path, CFile::modeRead))
  523. {
  524. exit(0);
  525. }
  526. DWORD dwFileLength = fp.GetLength(); // dwFileLength文件长度;
  527. // 1.读取文件内容,存储在pData数组中;
  528. *pData = new BYTE[dwFileLength];
  529. fp.Read(*pData, dwFileLength);
  530. fp.Close();
  531. // 2.保存文件头指针;
  532. *pDataBegin = *pData;
  533. /////////////
  534. CStringArray strChildArray;
  535. DWORD dwChildLength;
  536. // 3.获取头4个字节内容,保存在dwChildLength中;
  537. memcpy(&dwChildLength, *pData, sizeof(DWORD));
  538. *pData += sizeof(DWORD);
  539. // 4.获取第4个字节后dwChildLength长度内容,保存在pChildData数组中;
  540. BYTE *pChildData = new BYTE[dwChildLength];
  541. memcpy(pChildData, *pData, dwChildLength);
  542. *pData += dwChildLength;
  543. // 5.将pChildData数据附加到内存文件中;
  544. CMemFile memfile;
  545. memfile.Attach(pChildData, dwChildLength);
  546. // 6.将内存文件memfile序列化存储到CArchive对象中;
  547. CArchive ar(&memfile, CArchive::load);
  548. // 7.CArray对象strChildArray从CArchive对象中序列化加载数据;
  549. strChildArray.Serialize(ar);
  550. // 8.strChildArray加载完成,释放内存;
  551. ar.Close();
  552. memfile.Detach();
  553. delete[]pChildData;
  554. //////////////////////
  555. int pos = GetPos(dwFileLength);
  556. if (pos == -1)
  557. {
  558. exit(0);
  559. }
  560. DWORD leng1, leng2, leng3, leng4, leng5, leng6, leng7, leng8;
  561. leng1 = g_btnlengarray.ElementAt(pos * 8 + 0);
  562. leng2 = g_btnlengarray.ElementAt(pos * 8 + 1);
  563. leng3 = g_btnlengarray.ElementAt(pos * 8 + 2);
  564. leng4 = g_btnlengarray.ElementAt(pos * 8 + 3);
  565. leng5 = g_btnlengarray.ElementAt(pos * 8 + 4);
  566. leng6 = g_btnlengarray.ElementAt(pos * 8 + 5);
  567. leng7 = g_btnlengarray.ElementAt(pos * 8 + 6);
  568. leng8 = g_btnlengarray.ElementAt(pos * 8 + 7);
  569. /* if( pos %4==0)
  570. DeCodelong1( (long&)leng1, (long&)leng2, (long&)leng3, (long&)leng4, (long&)leng5, (long&)leng6, (long&)leng7, (long&)leng8 );
  571. else if( pos %4==1)
  572. DeCodelong2( (long&)leng1, (long&)leng2, (long&)leng3, (long&)leng4, (long&)leng5, (long&)leng6, (long&)leng7, (long&)leng8 );
  573. else if( pos %4==2)
  574. DeCodelong3( (long&)leng1, (long&)leng2, (long&)leng3, (long&)leng4, (long&)leng5, (long&)leng6, (long&)leng7, (long&)leng8 );
  575. else
  576. DeCodelong4( (long&)leng1, (long&)leng2, (long&)leng3, (long&)leng4, (long&)leng5, (long&)leng6, (long&)leng7, (long&)leng8 );
  577. */
  578. CArray<DWORD, DWORD>dataarray;
  579. dataarray.Add(pos);
  580. dataarray.Add(leng1);
  581. dataarray.Add(leng2);
  582. dataarray.Add(leng3);
  583. dataarray.Add(leng4);
  584. dataarray.Add(leng5);
  585. dataarray.Add(leng6);
  586. dataarray.Add(leng7);
  587. dataarray.Add(leng8);
  588. memcpy(&g_resdata2, g_pointerarray.ElementAt(pos), sizeof(RESDATA2));
  589. RESDATA2 *pRes = &g_resdata2;
  590. /*
  591. DeCodelong1( (long&)(pRes->rect[0].right), (long&)(pRes->rect[1].right), (long&)(pRes->rect[2].right), (long&)(pRes->rect[3].right), (long&)(pRes->rect[4].right), (long&)(pRes->rect[5].right), (long&)(pRes->rect[6].right), (long&)(pRes->rect[7].right) );
  592. DeCodelong2( (long&)(pRes->rect[8].right), (long&)(pRes->rect[9].right), (long&)(pRes->rect[10].right), (long&)(pRes->rect[11].right), (long&)(pRes->rect[12].right), (long&)(pRes->rect[13].right), (long&)(pRes->rect[14].right), (long&)(pRes->rect[15].right) );
  593. DeCodelong3( (long&)(pRes->rect[0].left), (long&)(pRes->rect[1].left), (long&)(pRes->rect[2].left), (long&)(pRes->rect[3].left), (long&)(pRes->rect[4].left), (long&)(pRes->rect[5].left), (long&)(pRes->rect[6].left), (long&)(pRes->rect[7].left) );
  594. DeCodelong4( (long&)(pRes->rect[8].left), (long&)(pRes->rect[9].left), (long&)(pRes->rect[10].left), (long&)(pRes->rect[11].left), (long&)(pRes->rect[12].left), (long&)(pRes->rect[13].left), (long&)(pRes->rect[14].left), (long&)(pRes->rect[15].left) );
  595. */
  596. dataarray.Add(pRes->rect[0].right);
  597. dataarray.Add(pRes->rect[1].right);
  598. dataarray.Add(pRes->rect[2].right);
  599. dataarray.Add(pRes->rect[3].right);
  600. dataarray.Add(pRes->rect[4].right);
  601. dataarray.Add(pRes->rect[5].right);
  602. dataarray.Add(pRes->rect[6].right);
  603. dataarray.Add(pRes->rect[7].right);
  604. dataarray.Add(pRes->rect[8].right);
  605. dataarray.Add(pRes->rect[9].right);
  606. dataarray.Add(pRes->rect[10].right);
  607. dataarray.Add(pRes->rect[11].right);
  608. dataarray.Add(pRes->rect[12].right);
  609. dataarray.Add(pRes->rect[13].right);
  610. dataarray.Add(pRes->rect[14].right);
  611. dataarray.Add(pRes->rect[15].right);
  612. dataarray.Add(pRes->rect[0].left);
  613. dataarray.Add(pRes->rect[1].left);
  614. dataarray.Add(pRes->rect[2].left);
  615. dataarray.Add(pRes->rect[3].left);
  616. dataarray.Add(pRes->rect[4].left);
  617. dataarray.Add(pRes->rect[5].left);
  618. dataarray.Add(pRes->rect[6].left);
  619. dataarray.Add(pRes->rect[7].left);
  620. dataarray.Add(pRes->rect[8].left);
  621. dataarray.Add(pRes->rect[9].left);
  622. dataarray.Add(pRes->rect[10].left);
  623. dataarray.Add(pRes->rect[11].left);
  624. dataarray.Add(pRes->rect[12].left);
  625. dataarray.Add(pRes->rect[13].left);
  626. dataarray.Add(pRes->rect[14].left);
  627. dataarray.Add(pRes->rect[15].left);
  628. dataarray.Add(g_resdata2.nPicCount);
  629. dataarray.Add(g_resdata2.nPicCount2);
  630. DWORD bkleng, bkleng2;
  631. ::memcpy(&bkleng2, *pData, sizeof(DWORD));
  632. *pData += sizeof(DWORD);
  633. ::memcpy(&bkleng, *pData, sizeof(DWORD));
  634. *pData += sizeof(DWORD);
  635. dataarray.Add(bkleng);
  636. dataarray.Add(bkleng2);
  637. ENCODE_START
  638. {
  639. CMemFile memfile;
  640. CArchive ar(&memfile, CArchive::store);
  641. dataarray.Serialize(ar);
  642. ar.Close();
  643. int length = memfile.GetLength();
  644. BYTE *pMemData = memfile.Detach();
  645. g_nSendCode = 7;
  646. g_pMainWnd->ProcessChatMessageRequest2(pMemData, length);
  647. g_nSendCode = 0;
  648. delete[]pMemData;
  649. if (g_bSendOK == 0)
  650. {
  651. //AfxMessageBox("g_bSendOK==0");
  652. return 0;
  653. }
  654. }
  655. ENCODE_END
  656. // 将g_nSendCode = 7的返回值装载到CMemFile;
  657. {
  658. dataarray.RemoveAll();
  659. CMemFile memfile;
  660. memfile.Attach(g_pData, g_nLeng);
  661. CArchive ar(&memfile, CArchive::load);
  662. dataarray.Serialize(ar);
  663. ar.Close();
  664. memfile.Detach();
  665. ENCODE_START
  666. for (int i = 0; i < 8; i++)
  667. g_btnleng[i] = dataarray.ElementAt(i + 1);
  668. g_btnlengpos = 0;
  669. for (i = 9; i < 25; i++)
  670. pRes->rect[i - 9].right = dataarray.ElementAt(i);
  671. for (i = 25; i < 41; i++)
  672. pRes->rect[i - 25].left = dataarray.ElementAt(i);
  673. g_resdata2.nPicCount = dataarray.ElementAt(41);
  674. g_resdata2.nPicCount2 = dataarray.ElementAt(42);
  675. bkleng = dataarray.ElementAt(43);
  676. bkleng2 = dataarray.ElementAt(44);
  677. ENCODE_END
  678. }
  679. if (g_resdata2.bHasBk)
  680. {
  681. BYTE *m_pSaveBk = NULL;
  682. MyBmpButton2::ReadBK(pData, &m_pSaveBk, bkleng);
  683. LoadImageFromBuf(pBk, m_pSaveBk, bkleng);
  684. delete[]m_pSaveBk;
  685. if ((*pBk)->GetWidth() == 633 && (*pBk)->GetHeight() == 50)//picbar
  686. {
  687. }
  688. else if ((*pBk)->GetWidth() == 2000)
  689. {
  690. CRect rc;
  691. HWND wnd = ::FindWindow("Shell_TrayWnd", 0);
  692. ::GetWindowRect(wnd, &rc);
  693. int hei = rc.Height();
  694. rc = CRect(0, 0, g_screenwid, g_screenhei - hei);
  695. g_fscalex = (float)g_screenwid / 2000.0;
  696. g_fscaley = (float)(g_screenhei - hei) / 1400.0;
  697. }
  698. else if ((*pBk)->GetWidth() == 600 && (*pBk)->GetHeight() == 371)
  699. {
  700. g_fscalex = (float)g_screenwid / 1024.0;
  701. g_fscaley = (float)g_screenhei / 768.0;
  702. }
  703. else //if((*pBk)->GetWidth()==1024 )
  704. {
  705. g_fscalex = (float)g_screenwid / 1024.0;
  706. g_fscaley = (float)g_screenhei / 768.0;
  707. }
  708. SizeToContent(hwnd, *pBk);
  709. if ((*pBk)->GetWidth() == 1024 && (*pBk)->GetHeight() == 768)
  710. ::SetWindowPos(hwnd, HWND_TOP, 0, 0, g_screenwid, g_screenhei, SWP_SHOWWINDOW);
  711. if ((*pBk)->GetWidth() == 2000 && (*pBk)->GetHeight() == 1399)
  712. ::SetWindowPos(hwnd, HWND_TOP, 0, 0, g_screenwid, g_screenhei, SWP_SHOWWINDOW);
  713. }
  714. // DeCodePicCount((long&)g_resdata2.nPicCount, (long&)g_resdata2.nPicCount2);
  715. return 1;
  716. }
  717. catch (...)
  718. {
  719. return 0;
  720. }
  721. }
  722. CString GetModifyTime(CString path)
  723. {
  724. HANDLE hFile;
  725. WIN32_FIND_DATA wfd;
  726. // SYSTEMTIME systime;
  727. FILETIME localtime;
  728. CString stime; //输出时间
  729. memset(&wfd, 0, sizeof(wfd));
  730. if ((hFile = FindFirstFile(path, &wfd)) == INVALID_HANDLE_VALUE)
  731. return "";
  732. //ok,转换时间
  733. FileTimeToLocalFileTime(&wfd.ftLastWriteTime, &localtime);
  734. stime.Format("%16d%16d", localtime.dwHighDateTime, localtime.dwLowDateTime);
  735. return stime;
  736. }
  737. BOOL CheckBadWords2(CString str, BOOL bMsg)
  738. {
  739. return 1;
  740. }