YLGL.cpp 24 KB

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