123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261 |
- // UPhoneBox.cpp : Defines the class behaviors for the application.
- //
- #include "stdafx.h"
- #include "UPhoneBox.h"
- #include "UPhoneBoxDlg.h"
- #include "DBConfig.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- //*****全局变量*******//
- CString g_headerpath;
- CString g_server2;
- CString g_ip;
- BOOL g_bSendOK = 0;
- SENDHEAD g_sendhead;
- COLORREF g_gridcol1 = RGB(204, 204, 204);
- COLORREF g_gridcol2 = RGB(190, 190, 190);
- int clr3DHilight = RGB(220, 220, 220);
- int clr3DShadow = RGB(70, 70, 70);
- int clr3DFace = RGB(128, 128, 128);
- CString g_mainpath; // 程序所在目录;
- /////////////////////////////////////////////////////////////////////////////
- // CUPhoneBoxApp
- BEGIN_MESSAGE_MAP(CUPhoneBoxApp, CWinApp)
- //{{AFX_MSG_MAP(CUPhoneBoxApp)
- // NOTE - the ClassWizard will add and remove mapping macros here.
- // DO NOT EDIT what you see in these blocks of generated code!
- //}}AFX_MSG
- ON_COMMAND(ID_HELP, CWinApp::OnHelp)
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CUPhoneBoxApp construction
- BOOL isInnerIP(DWORD a_ip)
- {
- BOOL bValid = 0;
- if ((a_ip >> 24 == 0xa) || (a_ip >> 16 == 0xc0a8) || (a_ip >> 22 == 0x2b0))
- {
- bValid = 1;
- }
- return bValid;
- }
- void MyGetIPByName(CString &name)
- {
- CStringArray g_serverarray;
- CString strIP = name;
- name.Empty();
- DWORD dwServerIP = 0;
- HOSTENT *host = gethostbyname(strIP);
- struct in_addr addr;
- if (host != NULL)
- {
- for (int i = 0; host->h_addr_list[i] != NULL; i++)
- {
- memset(&addr, 0, sizeof(addr));
- memcpy(&addr.S_un.S_addr, host->h_addr_list[i], host->h_length);
- dwServerIP = ntohl(addr.S_un.S_addr);
- BYTE* pIP = (BYTE*)&dwServerIP;
- name.Format(_T("%d.%d.%d.%d"), pIP[3], pIP[2], pIP[1], pIP[0]);
- g_serverarray.Add(name);
- }
- }
- while (g_serverarray.GetSize() > 1)
- {
- CString name;
- BOOL bFind = 0;
- for (int i = 0; i < g_serverarray.GetSize(); i++)
- {
- DWORD dwServerIP = inet_addr(g_serverarray.ElementAt(i));
- dwServerIP = htonl(dwServerIP);//加了才正确
- if (isInnerIP(dwServerIP) == 0)
- {
- // AfxMessageBox("外部IP");
- g_serverarray.RemoveAt(i);
- bFind = 1;
- break;
- }
- // else
- // AfxMessageBox("内部IP");
- }
- if (bFind == 0)
- {
- break;
- }
- }
- name = "";
- if (g_serverarray.GetSize())name = g_serverarray.ElementAt(0);
- }
- CUPhoneBoxApp::CUPhoneBoxApp()
- {
- // TODO: add construction code here,
- // Place all significant initialization in InitInstance
- }
- /////////////////////////////////////////////////////////////////////////////
- // The one and only CUPhoneBoxApp object
- CUPhoneBoxApp theApp;
- /////////////////////////////////////////////////////////////////////////////
- // CUPhoneBoxApp initialization
- BOOL CUPhoneBoxApp::InitInstance()
- {
- HANDLE hObject = CreateMutex(NULL, FALSE, _T("CUPhoneBoxAppXiao"));
- if (GetLastError() == ERROR_ALREADY_EXISTS)
- {
- return false;
- }
- AfxEnableControlContainer();
- // Standard initialization
- // If you are not using these features and wish to reduce the size
- // of your final executable, you should remove from the following
- // the specific initialization routines you do not need.
- 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";
- int nResult = Transport_Init();
- if (TRANSPORT_OK != nResult)
- {
- WriteLogin("初始化网络环境失败!");
- return false;
- }
- GetSysIniInfo();
- 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];
- }
- g_server2 = server;
- g_headerpath = "\\\\" + g_server2 + "\\客户原片(管理软件)$";
- g_headerpath += "\\客人头像\\";
- g_ip = g_server2;
- MyGetIPByName(g_ip);
- }
- else
- {
- AfxMessageBox("请先设置数据库服务器!", MB_ICONINFORMATION);
- DBConfig dlg;
- dlg.DoModal();
- goto ll;
- return false;
- }
- WriteLogin("启动");
- //ShellExecute(NULL, _T("open"), g_mainpath + "\\AutoRunUPhoneBox.exe", NULL, NULL, SW_SHOWNORMAL);
- #ifdef _AFXDLL
- Enable3dControls(); // Call this when using MFC in a shared DLL
- #else
- Enable3dControlsStatic(); // Call this when linking to MFC statically
- #endif
- SetDialogBkColor(RGB(204, 204, 204), RGB(0, 0, 0));
- SetRegistryKey(_T("LYFZ-UPhoneBox"));
- ULONG_PTR gdiplusToken;
- GdiplusStartupInput gdiplusStartupInput;
- GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
- CUPhoneBoxDlg dlg;
- m_pMainWnd = &dlg;
- int nResponse = dlg.DoModal();
- if (nResponse == IDOK)
- {
- // TODO: Place code here to handle when the dialog is
- // dismissed with OK
- }
- else if (nResponse == IDCANCEL)
- {
- // TODO: Place code here to handle when the dialog is
- // dismissed with Cancel
- }
- GdiplusShutdown(gdiplusToken);
- // Since the dialog has been closed, return FALSE so that we exit the
- // application, rather than start the application's message pump.
- return FALSE;
- }
- void WriteLogin(CString str)
- {
- CStdioFile fp;
- CString path = g_mainpath + "\\来电精灵日志.txt";
- if (::PathFileExists(path))
- {
- fp.Open(path, CFile::modeWrite);
- int length = fp.GetLength();
- if (length > 5 * 1024 * 1024)
- {
- fp.Close();
- ::DeleteFile(path);
- return;
- }
- fp.SeekToEnd();
- }
- else
- fp.Open(path, CFile::modeCreate | CFile::modeWrite);
- fp.WriteString(CTime::GetCurrentTime().Format("%Y-%m-%d %H:%M:%S") + " " + str + "\r\n");
- fp.Close();
- }
- int GetLengthEx(CString str)
- {
- int leng = 0;
- TBYTE ucHigh, ucLow;
- for (int i = 0; i < str.GetLength(); i++)
- {
- if ((TBYTE)str[i] < 0x80)
- {
- leng++;
- continue;
- }
- ucHigh = (TBYTE)str[i];
- if (i + 1 == str.GetLength())
- {
- leng++;
- break;
- }
- ucLow = (TBYTE)str[i + 1];
- if (ucHigh < 0xa1 || ucLow < 0xa1)
- {
- leng++;
- continue;
- }
- leng++;
- i++;
- }
- return leng;
- }
|