YLGL.cpp 22 KB

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