YLGL.cpp 22 KB

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