123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852 |
- // YLGL.cpp : Defines the class behaviors for the application.
- //
- #include "stdafx.h"
- #include "YLGL.h"
- #include "ChildFrm.h"
- #include "YLGLDoc.h"
- #include "YLGLView.h"
- #include "ChoosePhotoSkin.h"
- #include "DBConfig.h"
- #include "Lzari.h"
- #include "library.h"
- //#include "SQLite3Interface.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- MainFrimDlg2 *g_pMainWnd2 = NULL;
- FILE *g_pf; // add by Jeff 2014.05.24
- #define _USE_CONSOLE_FOR_DEBUG 0 // add by Jeff 2014.05.24
- BEGIN_MESSAGE_MAP(CYLGLApp, CWinApp)
- ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
- ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
- ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CYLGLApp construction
- // Jeff remark;
- DEVMODE g_dm; // 打印或显示设备的预设值和环境值;
- CYLGLApp::CYLGLApp()
- {
- // Place all significant initialization in InitInstance g_gridcol1
- g_dm.dmSize = sizeof(DEVMODE);
- EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &g_dm); // 返回显示设备的当前设置的绘图模式;
- CRect rc;
- HWND wnd = GetDesktopWindow();
- if (wnd)
- {
- ::GetWindowRect(wnd, &rc);
- g_screenwid = rc.Width();
- g_screenhei = rc.Height();
- }
- else
- {
- g_screenwid = g_dm.dmPelsWidth;
- g_screenhei = g_dm.dmPelsHeight;
- }
- g_fscalex = (float)g_screenwid / 1024.0;
- g_fscaley = (float)g_screenhei / 768.0;
- /* begin Jeff 这段代码未有使用意义 */
- wnd = ::FindWindow("Shell_TrayWnd", 0);
- ::GetWindowRect(wnd, &rc);
- int hei = rc.Height();
- rc = CRect(0, 0, g_screenwid, g_screenhei - hei);
- /* end Jeff 这段代码未有使用意义 */
- g_fscalex = (float)g_screenwid / 2000.0;
- g_fscaley = (float)(g_screenhei - hei) / 1400.0;
- }
- CYLGLApp theApp;
- class CAboutDlg : public CDialog
- {
- public:
- CAboutDlg();
- enum { IDD = IDD_ABOUTBOX };
- protected:
- virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
- protected:
- DECLARE_MESSAGE_MAP()
- };
- CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
- {
- }
- void CAboutDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- }
- BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- /////////////////////////////////////////////////////////////////////////////
- // CYLGLApp message handlers
- BOOL CYLGLApp::InitInstance()
- {
- TCHAR szDrive[_MAX_DRIVE] = { 0 };
- TCHAR szDir[_MAX_DIR] = { 0 };
- TCHAR szFna[_MAX_DIR] = { 0 };
- TCHAR szExt[_MAX_DIR] = { 0 };
- ::GetModuleFileName(NULL, g_szModuleFileName, sizeof(g_szModuleFileName) / sizeof(TCHAR));
- sprintf(g_szModulePath, _T("%s"), g_szModuleFileName);
- _tsplitpath(g_szModulePath, szDrive, szDir, szFna, szExt);
- _tcscpy(g_szModulePath, szDrive);
- _tcscat(g_szModulePath, szDir);
- /************************************************************************/
- #if _USE_CONSOLE_FOR_DEBUG // Jeff.控制台输出信息;
- AllocConsole(); // 开辟控制台
- SetConsoleTitle(_T("+lyfz:调试信息输出++++++")); // 设置控制台窗口标题
- freopen("CONOUT$","w+t",stdout); // 重定向输出
- freopen("CONIN$","r+t",stdin); // 重定向输入
- #endif
- //printf("Jeff:m_lpCmdLine = %s\n\n",m_lpCmdLine);//Jeffprintf
- // Jeff.命令行genbranchdata值,由本机服务端DBServer.exe执行输入;
- // 使用批处理可以指定这个命令行的内容
- //
- // ---------批处理---------------
- // @echo off
- // start %~dp0YLGL.exe genbranchdata
- // ---------批处理--------------
- //
- // DBServer.exe调用Shell命令传入该命令行genbranchdata值;
- if (m_lpCmdLine[0] == _T('\0')) //没有命令行参数
- {
- // return false;
- //WriteClientLog("无命令行输入");
- }
- else
- {
- CString str = m_lpCmdLine;
- if (str == "genbranchdata")
- {
- //WriteClientLog("命令行=genbranchdata");
- g_bGenBranchData = 1;
- }
- }
- if (g_bGenBranchData == 0)
- {
- HANDLE hObject = CreateMutex(NULL, FALSE, _T("CYLGLAppXiao"));
- if (GetLastError() == ERROR_ALREADY_EXISTS)
- {
- AfxMessageBox("提醒:软件已启动!", MB_ICONINFORMATION);
- }
- }
- AfxEnableControlContainer();
- g_listctrlfont.CreatePointFont(110, _T("System"));
- #ifdef _AFXDLL
- Enable3dControls(); // Call this when using MFC in a shared DLL
- #else
- Enable3dControlsStatic(); // Call this when linking to MFC statically
- #endif
- GetDebugPriv();
- // 获取升级的文件版本;
- GetFileVersion(NULL, g_arrFileVersion);
- // Jeff:dbconfig.dat里的信息,可以包含*.ly.com和计算机名称、IP地址三种;
- // 1.*.ly.com的需要解析出分店的IP地址;
- // 2.*.ly.com的解析是需要连接到公司服务器软件,然后返回ip地址,保存在ip.txt里;
- // Jeff.dbconfig.dat里保存的是*.ly.com信息,一般是用在外网访问花生壳域名的服务端软件;
- char path[MAX_PATH];
- ::GetModuleFileName(NULL, path, MAX_PATH);
- g_mainpath = path;
- g_mainpath = g_mainpath.Left(g_mainpath.ReverseFind('\\'));
- CString configpath = g_mainpath + "\\dbconfig.dat";
- // 1.初始化SOCKET
- int nResult = Transport_Init();
- if (TRANSPORT_OK != nResult)
- {
- WriteClientLog("网络初始化失败,软件退出!");
- return false;
- }
- // 2.获取服务器地址;
- if (g_bGenBranchData)
- {
- // Jeff.启动g_bGenBranchData功能,是指由服务器DBServer.exe使用Shell命令来调用YLGL.exe并传入genbranchdata命令行
- // 而此时YLGL.exe读取本机计算机名;
- char server[50];
- DWORD leng = 50;
- ::GetComputerName(server, &leng);
- g_serverbak = g_server = server;
- g_serverbak.TrimLeft();
- g_serverbak.TrimRight(".");
- g_serverbak.TrimRight();
- // Jeff. find(.ly.com)是不需要判断的一步;
- if (g_server.Find(".ly.com") == -1 && g_server.Find("192.168.") == -1)
- MyGetIPByName(g_server);
- if (g_server.Find("192.168.") != -1)
- g_serverarray.Add(g_server);
- // printf("Jeff.g_bGenBranchData=1,g_server=%s,g_serverbak=%s\n\n",g_server,g_serverbak);//Jeffprintf
- }
- else
- {
- CFile fp;
- ll: if (fp.Open(configpath, CFile::modeRead))
- {
- DBSAVE db;
- memset(&db, 0, sizeof(db));
- fp.Read(&db, sizeof(db));
- fp.Close();
- char server[50];
- char user[50];
- char psw[50];
- memset(server, 0, sizeof(char) * 50);
- memset(user, 0, sizeof(char) * 50);
- memset(psw, 0, sizeof(char) * 50);
- for (int i = 0; i < 50; i++)
- {
- if (db.server[i])
- server[i] = 500 - db.server[i];
- if (db.user[i])
- user[i] = 500 - db.user[i];
- if (db.psw[i])
- psw[i] = 500 - db.psw[i];
- }
- #ifdef TEST_LOCAL
- DWORD leng=50;
- ::GetComputerName (server, &leng);
- #endif
- g_serverbak = g_server = server;
- g_serverbak.TrimLeft();
- g_serverbak.TrimRight(".");
- g_serverbak.TrimRight();
- if (g_server.Find(".ly.com") == -1 && g_server.Find("192.168.") == -1)
- MyGetIPByName(g_server);
- if (g_server.Find("192.168.") != -1)
- g_serverarray.Add(g_server);
- if (g_server.IsEmpty())
- {
- AfxMessageBox("获取IP失败! 请确认服务器名 " + g_serverbak + " 是否正确? 或修改网络设置或与系统hosts文件!");
- // g_serverarray.Add (g_serverbak);
- // g_server=g_serverbak;
- return 0;
- }
- IsShareFolderExist(server);// add by Jeff,检测共享目录是否存在可写;
- // 10.0.0.0/8:10.0.0.0~10.255.255.255
- // 172.16.0.0/12:172.16.0.0~172.31.255.255
- // 192.168.0.0/16:192.168.0.0~192.168.255.255
- if (g_server.Find("10.") != -1 || g_server.Find("172.") != -1 || g_server.Find("192.168") != -1)
- {
- }
- else
- {
- // g_serverbak="localserver";
- }
- }
- else
- {
- AfxMessageBox("请先设置数据库服务器!", MB_ICONINFORMATION);
- DBConfig dlg;
- dlg.DoModal();
- goto ll;
- return false;
- }
- }
- #if 0 // 测试;
- //////////////////////////////////////////////////////////////////////////
- // 测试;
- TCHAR szdb[MAX_PATH] = {0};
- sprintf(szdb,_T("%s%s"),g_szModulePath,_T("remoteinfo.db"));
- CSQLite3Interface db;
- if(!PathFileExists(szdb))
- {
- nResult = db.opendb(szdb);
- if(nResult == 0)
- {
- nResult = db.creattbl(CREATE_DB_TBL_);
- if ( nResult )
- {
- AfxMessageBox(_T("创建数据库表失败!"));
- }
- else
- {
- // 创建表成功,测试添加数据到表中;
- // 初始化表数据;
- STRemoteInfo info[13] =
- {
- {1,_T("分店1"),_T("127.0.0.1"),_T("20150403120530.ly.com"),_T("lyfz1"),_T("异选原片$"),0,100 },
- {1,_T("分店2"),_T("127.0.0.1"),_T("20150403120531.ly.com"),_T("lyfz2"),_T("异选原片$"),0,100 },
- {1,_T("分店3"),_T("127.0.0.1"),_T("20150403120532.ly.com"),_T("lyfz3"),_T("异选原片$"),0,100 },
- {1,_T("分店4"),_T("127.0.0.1"),_T("20150403120533.ly.com"),_T("lyfz4"),_T("异选原片$"),0,100 },
- {1,_T("分店5"),_T("127.0.0.1"),_T("20150403120534.ly.com"),_T("lyfz5"),_T("异选原片$"),0,100 },
- {1,_T("分店6"),_T("127.0.0.1"),_T("20150403120535.ly.com"),_T("lyfz6"),_T("异选原片$"),0,100 },
- {1,_T("分店7"),_T("127.0.0.1"),_T("20150403120536.ly.com"),_T("lyfz7"),_T("异选原片$"),0,100 },
- {1,_T("分店8"),_T("127.0.0.1"),_T("20150403120537.ly.com"),_T("lyfz8"),_T("异选原片$"),0,100 },
- {1,_T("分店9"),_T("127.0.0.1"),_T("20150403120538.ly.com"),_T("lyfz9"),_T("异选原片$"),0,100 },
- {1,_T("分店A"),_T("127.0.0.1"),_T("20150403120539.ly.com"),_T("lyfzA"),_T("异选原片$"),0,100 },
- {1,_T("分店B"),_T("127.0.0.1"),_T("20150403120540.ly.com"),_T("lyfzB"),_T("异选原片$"),0,100 },
- {1,_T("分店C"),_T("127.0.0.1"),_T("20150403120541.ly.com"),_T("lyfzC"),_T("异选原片$"),0,100 },
- {1,_T("分店D"),_T("127.0.0.1"),_T("20150403120542.ly.com"),_T("lyfzD"),_T("异选原片$"),0,100 }
- };
- // 循环插入数据;
- TCHAR szInsert[MAX_PATH] = {0};
- for ( int n = 0; n < 13; n++)
- {
- sprintf(
- szInsert,
- _T("insert into remoteinfo(inuse,branch,ip,domain,host,sharedirectory,delaftertakeway,deldays) values ('%d','%s','%s','%s','%s','%s',%d,%d);"),
- info[n].bInUse,
- info[n].szBranch,
- info[n].szIP,
- info[n].szDoMain,
- info[n].szHost,
- info[n].szShareDirectory,
- info[n].bDelAfterTakeWay,
- info[n].dwDelDays);
- TRACE(szInsert);
- TRACE(_T("\n"));
- // 插入数据;
- nResult = db.isnerttbl(szInsert);
- if ( nResult != 0)
- {
- AfxMessageBox(_T("插入数据失败!"));
- }
- }
- // 查询数据;
- vector<STRemoteInfo> vtRemoteInfo;
- nResult = db.gettbl_remoteinfo(_T("select * from remoteinfo"),vtRemoteInfo);
-
- for (vector<STRemoteInfo>::iterator it = vtRemoteInfo.begin(); it != vtRemoteInfo.end(); it++)
- {
- // 打印出结果;
- TCHAR szPrintf[MAX_PATH] = {0};
- sprintf(szPrintf,_T("%d,%s,%s,%s,%s,%s,%d,%d\n"),
- it->bInUse,
- it->szBranch,
- it->szIP,
- it->szDoMain,
- it->szHost,
- it->szShareDirectory,
- it->bDelAfterTakeWay,
- it->dwDelDays);
- TRACE(szPrintf);
- TRACE(_T("\n"));
- }
- }
- }
- else
- {
- AfxMessageBox(_T("打开数据库失败!"));
- }
- }
- db.closedb();
- //////////////////////////////////////////////////////////////////////////
- #endif
- CStdioFile fp2;
- if (fp2.Open(g_mainpath + "\\title.txt", CFile::modeRead))
- {
- fp2.ReadString(g_title);
- fp2.Close();
- }
- //free((void*)m_pszAppName);
- m_pszAppName = _tcsdup(g_title + "影楼管理系统");
- g_titlefont.CreatePointFont(160, _T("宋体"));
- SetRegistryKey(_T("LYFZ-YLGL"));
- CString version = _T("Version 1.0");
- g_bRedSkin = AfxGetApp()->GetProfileInt(version, "redskin", 0);
- if (g_bRedSkin)
- {
- g_gridcol1 = RGB(241, 180, 198);
- g_gridcol2 = RGB(237, 157, 182);
- g_bkcol = RGB(235, 149, 174);
- }//184, 184
- g_editbkbrush.CreateSolidBrush(g_bkcol);
- LoadStdProfileSettings(); // Load standard INI file options (including MRU)
- GdiplusStartupInput gdiplusStartupInput;
- GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
- // Jeff.若程序没有足够的权限,则会注册失败;
- // Jeff..若文件不存在呢,注册就无意义;
- CString temp;
- temp.Format("%s\\MSCHRT20.OCX", g_mainpath);
- OFSTRUCT ofStruct;
- OpenFile(temp, &ofStruct, OF_EXIST);
- if (ERROR_FILE_NOT_FOUND != GetLastError())
- {
- RegisterOcx(temp);
- }
- // Jeff.IRStartup属于换肤库的启动函数;
- HINSTANCE hModule = GetModuleHandle(NULL);
- IRStartup(hModule, GetCurrentThreadId());
- CMultiDocTemplate* pDocTemplate;
- pDocTemplate = new CMultiDocTemplate(
- IDR_MAINFRAME,
- NULL,
- RUNTIME_CLASS(CChildFrame), // custom MDI child frame
- RUNTIME_CLASS(CYLGLView));
- AddDocTemplate(pDocTemplate);
- // create main MDI Frame window
- CMainFrame* pMainFrame = new CMainFrame;
- if (!pMainFrame->LoadFrame(IDR_MAINFRAME)) // LoadFrame调用OnCreate
- {
- return FALSE;
- }
- m_pMainWnd = pMainFrame;
- // 加载OfficeXP风格菜单
- #ifndef NEW_SKIN
- CMenu* pMenu = m_pMainWnd->GetMenu();
- if (pMenu)pMenu->DestroyMenu();
- HMENU hMenu = ((CMainFrame*) m_pMainWnd)->NewMenu();
- pMenu = CMenu::FromHandle( hMenu );
- m_pMainWnd->SetMenu(pMenu);
- ((CMainFrame*)m_pMainWnd)->m_hMenuDefault = hMenu;
- #endif
- // Parse command line for standard shell commands, DDE, file open
- ////////////////////////////////////////////////////
- // 禁止自动新建子窗口
- // CCommandLineInfo cmdInfo;
- // ParseCommandLine(cmdInfo);
- // // Dispatch commands specified on the command line
- // if (!ProcessShellCommand(cmdInfo))
- // return FALSE;
- m_pMainWnd->SetWindowText(g_title + "影楼管理系统");
- m_pMainWnd->UpdateWindow();
- SetDialogBkColor(g_bkcol, RGB(0, 0, 0));
- return TRUE;
- }
- BOOL CYLGLApp::IsShareFolderExist(char *szServerName)
- {
- char szPath1[MAX_PATH] = { 0 };
- sprintf(szPath1, "\\\\%s\\%s", szServerName, "电话录音(管理软件)$");
- IsExistFolder(szPath1);
- sprintf(szPath1, "\\\\%s\\%s", szServerName, "客户原片(管理软件)$");
- IsExistFolder(szPath1);
- sprintf(szPath1, "\\\\%s\\%s", szServerName, "精修好的片(管理软件)$");
- IsExistFolder(szPath1);
- sprintf(szPath1, "\\\\%s\\%s", szServerName, "礼服图片(管理软件)$");
- IsExistFolder(szPath1);
- sprintf(szPath1, "\\\\%s\\%s", szServerName, "设计好的片(管理软件)$");
- IsExistFolder(szPath1);
- sprintf(szPath1, "\\\\%s\\%s", szServerName, "修好的片(管理软件)$");
- IsExistFolder(szPath1);
- return TRUE;
- }
- int CYLGLApp::DoMessageBox(LPCTSTR lpszPrompt, UINT nType, UINT nIDPrompt)
- {
- return CWinApp::DoMessageBox(lpszPrompt, nType, nIDPrompt);
- }
- // App command to run the dialog
- void CYLGLApp::OnAppAbout()
- {
- CAboutDlg aboutDlg;
- aboutDlg.DoModal();
- }
- int CYLGLApp::ExitInstance()
- {
- //关闭gdiplus的环境
- GdiplusShutdown(gdiplusToken);
- for (int i = 0; i < g_pointerarray.GetSize(); i++)
- delete[](g_pointerarray.ElementAt(i));
- IRComplete();
- #if _USE_CONSOLE_FOR_DEBUG
- FreeConsole(); //释放控制台;
- #endif
- //WriteLog("退出系统");//Jeff.add
- return CWinApp::ExitInstance();
- }
- int GetPos(DWORD leng)
- {
- if (g_lengarray.GetSize() == 0)
- {
- g_sendhead.bsql = 0;
- g_sendhead.code[0] = 105; //Jeff.服务器返回10.lia文件的数据、文件大小;
- g_sendhead.tabcount = 1;
- g_pMainWnd->ProcessChatMessageRequest2(1);
- if (g_bSendOK == 0) return -1;
- DWORD leng;
- DWORD readbytes = 0;
- // Jeff.remark.2014.06.26
- // g_pData 里此时保存的是10.lia文件内容;
- // 根据10.lia的结构,解释其它内部数据;
- // 目前没有其结构文档解释,暂时未知10.lia内含什么数据种类;
- // 以下是根据代码假设的内容:
- // -------------------------------
- // 4 byte.某文件A大小,用dwLengthA表示;
- // dwLengthA byte:文件A的数据
- // 4 byte.某文件B大小,用dwLengthB表示;
- // dwLengthB byte:文件B的数据;
- // ------以下文件组C-------------
- // 4 byte.某文件组C大小,用dwLengthC表示;
- // dwLengthC:某文件组C的数据;
- // 某文件C的数据结构:RESDATA2
- // 文件组C文件个数nCount = dwLengthC/sizeof(RESDATA2);
- //---------------------------------------
- // 10.lia文件总大小:dwSum = dwLengthA+dwLengthB+dwLengthC;
- // 10.lia文件内数据结构种类有三种:A,B,C 其中C为一组同类型数据;
- // 10.lia文件内数据结构个数: 2 + nCount;
- // --------------------------------
- ENCODE_START
- memcpy(&leng, g_pData + readbytes, sizeof(DWORD));
- readbytes += sizeof(DWORD);
- {
- CMemFile memfile;
- memfile.Attach(g_pData + readbytes, leng);
- readbytes += leng;
- CArchive ar(&memfile, CArchive::load);
- g_lengarray.Serialize(ar);
- ar.Close();
- memfile.Detach();
- }
- memcpy(&leng, g_pData + readbytes, sizeof(DWORD));
- readbytes += sizeof(DWORD);
- {
- CMemFile memfile;
- memfile.Attach(g_pData + readbytes, leng);
- readbytes += leng;
- CArchive ar(&memfile, CArchive::load);
- g_btnlengarray.Serialize(ar);
- ar.Close();
- memfile.Detach();
- }
- memcpy(&leng, g_pData + readbytes, sizeof(DWORD));
- readbytes += sizeof(DWORD);
- ENCODE_END
- int count = leng / sizeof(RESDATA2);
- for (int i = 0; i < count; i++)
- {
- BYTE *pData = new BYTE[sizeof(RESDATA2)];
- memcpy(pData, g_pData + readbytes, sizeof(RESDATA2));
- readbytes += sizeof(RESDATA2);
- g_pointerarray.Add(pData);
- }
- }
- for (int i = 0; i < g_lengarray.GetSize(); i++)
- {
- if (leng == g_lengarray.ElementAt(i))
- {
- return i;
- }
- }
- return -1;
- }
- extern void SizeToContent(HWND hwnd, Image *img);
- BOOL LoadLia(CString path, BYTE **pData, BYTE **pDataBegin, Image **pBk, HWND hwnd)
- {
- try
- {
- CFile fp;
- if (!fp.Open(path, CFile::modeRead))
- {
- exit(0);
- }
- DWORD dwFileLength = fp.GetLength(); // dwFileLength文件长度;
- // 1.读取文件内容,存储在pData数组中;
- *pData = new BYTE[dwFileLength];
- fp.Read(*pData, dwFileLength);
- fp.Close();
- // 2.保存文件头指针;
- *pDataBegin = *pData;
- /////////////
- CStringArray strChildArray;
- DWORD dwChildLength;
- // 3.获取头4个字节内容,保存在dwChildLength中;
- memcpy(&dwChildLength, *pData, sizeof(DWORD));
- *pData += sizeof(DWORD);
- // 4.获取第4个字节后dwChildLength长度内容,保存在pChildData数组中;
- BYTE *pChildData = new BYTE[dwChildLength];
- memcpy(pChildData, *pData, dwChildLength);
- *pData += dwChildLength;
- // 5.将pChildData数据附加到内存文件中;
- CMemFile memfile;
- memfile.Attach(pChildData, dwChildLength);
- // 6.将内存文件memfile序列化存储到CArchive对象中;
- CArchive ar(&memfile, CArchive::load);
- // 7.CArray对象strChildArray从CArchive对象中序列化加载数据;
- strChildArray.Serialize(ar);
- // 8.strChildArray加载完成,释放内存;
- ar.Close();
- memfile.Detach();
- delete[]pChildData;
- //////////////////////
- int pos = GetPos(dwFileLength);
- if (pos == -1)
- {
- exit(0);
- }
- DWORD leng1, leng2, leng3, leng4, leng5, leng6, leng7, leng8;
- leng1 = g_btnlengarray.ElementAt(pos * 8 + 0);
- leng2 = g_btnlengarray.ElementAt(pos * 8 + 1);
- leng3 = g_btnlengarray.ElementAt(pos * 8 + 2);
- leng4 = g_btnlengarray.ElementAt(pos * 8 + 3);
- leng5 = g_btnlengarray.ElementAt(pos * 8 + 4);
- leng6 = g_btnlengarray.ElementAt(pos * 8 + 5);
- leng7 = g_btnlengarray.ElementAt(pos * 8 + 6);
- leng8 = g_btnlengarray.ElementAt(pos * 8 + 7);
- /* if( pos %4==0)
- DeCodelong1( (long&)leng1, (long&)leng2, (long&)leng3, (long&)leng4, (long&)leng5, (long&)leng6, (long&)leng7, (long&)leng8 );
- else if( pos %4==1)
- DeCodelong2( (long&)leng1, (long&)leng2, (long&)leng3, (long&)leng4, (long&)leng5, (long&)leng6, (long&)leng7, (long&)leng8 );
- else if( pos %4==2)
- DeCodelong3( (long&)leng1, (long&)leng2, (long&)leng3, (long&)leng4, (long&)leng5, (long&)leng6, (long&)leng7, (long&)leng8 );
- else
- DeCodelong4( (long&)leng1, (long&)leng2, (long&)leng3, (long&)leng4, (long&)leng5, (long&)leng6, (long&)leng7, (long&)leng8 );
- */
- CArray<DWORD, DWORD>dataarray;
- dataarray.Add(pos);
- dataarray.Add(leng1);
- dataarray.Add(leng2);
- dataarray.Add(leng3);
- dataarray.Add(leng4);
- dataarray.Add(leng5);
- dataarray.Add(leng6);
- dataarray.Add(leng7);
- dataarray.Add(leng8);
- memcpy(&g_resdata2, g_pointerarray.ElementAt(pos), sizeof(RESDATA2));
- RESDATA2 *pRes = &g_resdata2;
- /*
- 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) );
- 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) );
- 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) );
- 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) );
- */
- dataarray.Add(pRes->rect[0].right);
- dataarray.Add(pRes->rect[1].right);
- dataarray.Add(pRes->rect[2].right);
- dataarray.Add(pRes->rect[3].right);
- dataarray.Add(pRes->rect[4].right);
- dataarray.Add(pRes->rect[5].right);
- dataarray.Add(pRes->rect[6].right);
- dataarray.Add(pRes->rect[7].right);
- dataarray.Add(pRes->rect[8].right);
- dataarray.Add(pRes->rect[9].right);
- dataarray.Add(pRes->rect[10].right);
- dataarray.Add(pRes->rect[11].right);
- dataarray.Add(pRes->rect[12].right);
- dataarray.Add(pRes->rect[13].right);
- dataarray.Add(pRes->rect[14].right);
- dataarray.Add(pRes->rect[15].right);
- dataarray.Add(pRes->rect[0].left);
- dataarray.Add(pRes->rect[1].left);
- dataarray.Add(pRes->rect[2].left);
- dataarray.Add(pRes->rect[3].left);
- dataarray.Add(pRes->rect[4].left);
- dataarray.Add(pRes->rect[5].left);
- dataarray.Add(pRes->rect[6].left);
- dataarray.Add(pRes->rect[7].left);
- dataarray.Add(pRes->rect[8].left);
- dataarray.Add(pRes->rect[9].left);
- dataarray.Add(pRes->rect[10].left);
- dataarray.Add(pRes->rect[11].left);
- dataarray.Add(pRes->rect[12].left);
- dataarray.Add(pRes->rect[13].left);
- dataarray.Add(pRes->rect[14].left);
- dataarray.Add(pRes->rect[15].left);
- dataarray.Add(g_resdata2.nPicCount);
- dataarray.Add(g_resdata2.nPicCount2);
- DWORD bkleng, bkleng2;
- ::memcpy(&bkleng2, *pData, sizeof(DWORD));
- *pData += sizeof(DWORD);
- ::memcpy(&bkleng, *pData, sizeof(DWORD));
- *pData += sizeof(DWORD);
- dataarray.Add(bkleng);
- dataarray.Add(bkleng2);
- ENCODE_START
- {
- CMemFile memfile;
- CArchive ar(&memfile, CArchive::store);
- dataarray.Serialize(ar);
- ar.Close();
- int length = memfile.GetLength();
- BYTE *pMemData = memfile.Detach();
- g_nSendCode = 7;
- g_pMainWnd->ProcessChatMessageRequest2(pMemData, length);
- g_nSendCode = 0;
- delete[]pMemData;
- if (g_bSendOK == 0)
- {
- //AfxMessageBox("g_bSendOK==0");
- return 0;
- }
- }
- ENCODE_END
- // 将g_nSendCode = 7的返回值装载到CMemFile;
- {
- dataarray.RemoveAll();
- CMemFile memfile;
- memfile.Attach(g_pData, g_nLeng);
- CArchive ar(&memfile, CArchive::load);
- dataarray.Serialize(ar);
- ar.Close();
- memfile.Detach();
- ENCODE_START
- for (int i = 0; i < 8; i++)
- g_btnleng[i] = dataarray.ElementAt(i + 1);
- g_btnlengpos = 0;
- for (i = 9; i < 25; i++)
- pRes->rect[i - 9].right = dataarray.ElementAt(i);
- for (i = 25; i < 41; i++)
- pRes->rect[i - 25].left = dataarray.ElementAt(i);
- g_resdata2.nPicCount = dataarray.ElementAt(41);
- g_resdata2.nPicCount2 = dataarray.ElementAt(42);
- bkleng = dataarray.ElementAt(43);
- bkleng2 = dataarray.ElementAt(44);
- ENCODE_END
- }
- if (g_resdata2.bHasBk)
- {
- BYTE *m_pSaveBk = NULL;
- MyBmpButton2::ReadBK(pData, &m_pSaveBk, bkleng);
- LoadImageFromBuf(pBk, m_pSaveBk, bkleng);
- delete[]m_pSaveBk;
- if ((*pBk)->GetWidth() == 633 && (*pBk)->GetHeight() == 50)//picbar
- {
- }
- else if ((*pBk)->GetWidth() == 2000)
- {
- CRect rc;
- HWND wnd = ::FindWindow("Shell_TrayWnd", 0);
- ::GetWindowRect(wnd, &rc);
- int hei = rc.Height();
- rc = CRect(0, 0, g_screenwid, g_screenhei - hei);
- g_fscalex = (float)g_screenwid / 2000.0;
- g_fscaley = (float)(g_screenhei - hei) / 1400.0;
- }
- else if ((*pBk)->GetWidth() == 600 && (*pBk)->GetHeight() == 371)
- {
- g_fscalex = (float)g_screenwid / 1024.0;
- g_fscaley = (float)g_screenhei / 768.0;
- }
- else //if((*pBk)->GetWidth()==1024 )
- {
- g_fscalex = (float)g_screenwid / 1024.0;
- g_fscaley = (float)g_screenhei / 768.0;
- }
- SizeToContent(hwnd, *pBk);
- if ((*pBk)->GetWidth() == 1024 && (*pBk)->GetHeight() == 768)
- ::SetWindowPos(hwnd, HWND_TOP, 0, 0, g_screenwid, g_screenhei, SWP_SHOWWINDOW);
- if ((*pBk)->GetWidth() == 2000 && (*pBk)->GetHeight() == 1399)
- ::SetWindowPos(hwnd, HWND_TOP, 0, 0, g_screenwid, g_screenhei, SWP_SHOWWINDOW);
- }
- // DeCodePicCount((long&)g_resdata2.nPicCount, (long&)g_resdata2.nPicCount2);
- return 1;
- }
- catch (...)
- {
- return 0;
- }
- }
- CString GetModifyTime(CString path)
- {
- HANDLE hFile;
- WIN32_FIND_DATA wfd;
- // SYSTEMTIME systime;
- FILETIME localtime;
- CString stime; //输出时间
- memset(&wfd, 0, sizeof(wfd));
- if ((hFile = FindFirstFile(path, &wfd)) == INVALID_HANDLE_VALUE)
- return "";
- //ok,转换时间
- FileTimeToLocalFileTime(&wfd.ftLastWriteTime, &localtime);
- stime.Format("%16d%16d", localtime.dwHighDateTime, localtime.dwLowDateTime);
- return stime;
- }
- BOOL CheckBadWords2(CString str, BOOL bMsg)
- {
- return 1;
- }
|