AutoRun2Dlg.cpp 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281
  1. // AutoRun2Dlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "AutoRun2.h"
  5. #include "AutoRun2Dlg.h"
  6. #include "AutoRun2Dlg2.h"
  7. #include <afxsock.h>//<Winsock2.h>
  8. #include "ConnectDlg.h"
  9. #include "SendDataDlg.h"
  10. #include "AddContact.h"
  11. #include "SendReg.h"
  12. #include <Mmsystem.h>
  13. #include <tlhelp32.h>
  14. #include <afxinet.h>
  15. #include <afxext.h>
  16. #ifdef _DEBUG
  17. #define new DEBUG_NEW
  18. #undef THIS_FILE
  19. static char THIS_FILE[] = __FILE__;
  20. #endif
  21. #pragma comment(lib, "Winmm.lib")
  22. #define IPC_CUSTOM_MSG2 _T("{a4Fa76E2-w78F-2aD5-q98A-Y0B0D078u2}")
  23. UINT g_wmClose = RegisterWindowMessage(IPC_CUSTOM_MSG2);
  24. CString g_mainpath;
  25. CString g_mainpath2;
  26. CString g_mainpath3;
  27. BOOL g_bAutoRun=0;
  28. #define WM_ICON_NOTIFY WM_USER+12
  29. DWORD g_nSendCode=0; //insert
  30. /////////////////////////////////////////////////////////////////////////////
  31. DWORD g_ncount2=0;
  32. HWND g_hSendWnd;
  33. extern HWND g_hConnectWnd;
  34. extern void DataToArray(CArray<CStringArray, CStringArray>*List1array);
  35. extern void DataToArray(CArray<CStringArray, CStringArray>*List1array, CArray<CStringArray, CStringArray>*List2array);
  36. #define DISCONNECT_TIMER (WM_USER + 101)
  37. #define LOGINFAILED_TIMER (WM_USER + 102)
  38. extern void MyGetIPByName(CString &name);
  39. BOOL g_bReturned=0;
  40. BOOL g_bReturned2=0;
  41. int GetCount(CString content)
  42. {
  43. int count=0;
  44. int leng=g_pMainWnd->GetLengthEx(content);
  45. {
  46. count+=1*(leng/70);
  47. if(leng%70)
  48. count+=1;
  49. }
  50. return count;
  51. }
  52. DWORD FindAppProcessID(CString path)
  53. {
  54. try
  55. {
  56. HANDLE handle=::CreateToolhelp32Snapshot(TH32CS_SNAPALL,0);
  57. PROCESSENTRY32 Info;
  58. Info.dwSize = sizeof(PROCESSENTRY32);
  59. path.MakeLower ();
  60. if(::Process32First(handle,&Info))
  61. {
  62. do
  63. {
  64. CString ss=Info.szExeFile;
  65. ss.MakeLower ();
  66. if(ss.Find (path)!=-1 || (!ss.CompareNoCase(path)) )
  67. {
  68. ::CloseHandle(handle);
  69. return Info.th32ProcessID;
  70. }
  71. }
  72. while(::Process32Next(handle,&Info));
  73. ::CloseHandle(handle);
  74. }
  75. return -1;
  76. }
  77. catch(...)
  78. {
  79. }
  80. }
  81. void WriteLogin(CString str)
  82. {
  83. try
  84. {
  85. DWORD ticks=::GetTickCount ();
  86. CString path=g_mainpath2+"\\autorun.txt";
  87. {
  88. CFile fp;
  89. if(fp.Open (path, CFile::modeRead))
  90. {
  91. if(fp.GetLength ()/(1024*1024)>1)
  92. {
  93. fp.Close ();
  94. ::DeleteFile (path);
  95. }
  96. else
  97. fp.Close ();
  98. }
  99. }
  100. CStdioFile fp;
  101. if(::PathFileExists (path))
  102. {
  103. fp.Open (path, CFile::modeWrite);
  104. fp.SeekToEnd ();
  105. }
  106. else
  107. fp.Open (path, CFile::modeCreate|CFile::modeWrite);
  108. CString temp;
  109. temp.Format (" %dss ", ::GetTickCount ()-ticks);
  110. fp.WriteString (CTime::GetCurrentTime ().Format ("%Y-%m-%d %H:%M:%S")+temp+str+"\r\n" );
  111. fp.Close ();
  112. }
  113. catch(...)
  114. {
  115. }
  116. }
  117. void MyExitWindows()
  118. {
  119. try
  120. {
  121. UINT t=EWX_REBOOT|EWX_FORCE;
  122. OSVERSIONINFO osv; //定义一个操作系统信息的结构体
  123. osv.dwOSVersionInfoSize=sizeof OSVERSIONINFO;
  124. GetVersionEx(&osv); //查询当前操作系统
  125. if(osv.dwPlatformId==VER_PLATFORM_WIN32_NT) //判断是否是2000/NT
  126. {
  127. //下面为向操作系统获取权限操作
  128. HANDLE hProcess,hToken;
  129. TOKEN_PRIVILEGES Privileges;
  130. LUID luid;
  131. hProcess=GetCurrentProcess();
  132. //下面为打开当前进程对话
  133. OpenProcessToken(hProcess,TOKEN_ADJUST_PRIVILEGES,&hToken);
  134. Privileges.PrivilegeCount=1;
  135. LookupPrivilegeValue(NULL,SE_SHUTDOWN_NAME,&luid);
  136. Privileges.Privileges[0].Luid=luid;
  137. Privileges.Privileges[0].Attributes=SE_PRIVILEGE_ENABLED;
  138. AdjustTokenPrivileges(hToken,FALSE,&Privileges,NULL,NULL,NULL);
  139. ExitWindowsEx(t,0);
  140. }
  141. else
  142. {
  143. ExitWindowsEx(t,0);//调用ExitWindowsEx关闭机器。
  144. PostQuitMessage(0);
  145. }
  146. }
  147. catch(...)
  148. {
  149. }
  150. }
  151. /////////////////////////////////////////////////////////////////////////////
  152. static void HandleClientNetEvent(IN SOCKET hSocket, IN ETransportEvent eEvent,
  153. IN void *pDataBuf, IN unsigned long nDataLen,
  154. IN int nError, IN void *pContext)
  155. {
  156. if( nError != TRANSPORT_OK ) return;
  157. CAutoRun2Dlg *pDlg = (CAutoRun2Dlg *)pContext;
  158. if( NULL == pDlg ) return;
  159. pDlg->ProcessNetEvent(eEvent, pDataBuf, nDataLen);
  160. }
  161. CAutoRun2Dlg::CAutoRun2Dlg(CWnd* pParent /*=NULL*/)
  162. : CDialog(CAutoRun2Dlg::IDD, pParent)
  163. {
  164. //{{AFX_DATA_INIT(CAutoRun2Dlg)
  165. m_strSendSms = _T("");
  166. m_strLoginID = _T("");
  167. m_strLoginPwd = _T("");
  168. m_strRecvMobi = _T("");
  169. m_strNewPwd = _T("");
  170. m_mobicount = 0;
  171. m_check1 = FALSE;
  172. m_count = 0;
  173. //}}AFX_DATA_INIT
  174. // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
  175. m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  176. m_nMobile=0;
  177. m_nPhone=0;
  178. CString version = _T ("Version 1.0");
  179. g_bAutoRun=AfxGetApp()->GetProfileInt (version, "brun", 0);
  180. }
  181. void CAutoRun2Dlg::DoDataExchange(CDataExchange* pDX)
  182. {
  183. CDialog::DoDataExchange(pDX);
  184. //{{AFX_DATA_MAP(CAutoRun2Dlg)
  185. DDX_Control(pDX, IDC_LIST2, m_List1);
  186. DDX_Control(pDX, IDC_BTN_SEND, m_btnSend);
  187. DDX_Control(pDX, IDC_LST_SMS, m_listCtrl);
  188. DDX_Text(pDX, IDC_EDT_SMS, m_strSendSms);
  189. DDV_MaxChars(pDX, m_strSendSms, 2000);
  190. DDX_Text(pDX, IDC_EDT_LOGIN_ID, m_strLoginID);
  191. DDV_MaxChars(pDX, m_strLoginID, 11);
  192. DDX_Text(pDX, IDC_EDT_LOGIN_PWD, m_strLoginPwd);
  193. DDX_Text(pDX, IDC_EDT_RECV_MOBI, m_strRecvMobi);
  194. DDX_Text(pDX, IDC_EDT_NEW_PWD, m_strNewPwd);
  195. DDX_Text(pDX, IDC_EDT_NUM, m_mobicount);
  196. DDX_Check(pDX, IDC_CHECK1, m_check1);
  197. //}}AFX_DATA_MAP
  198. }
  199. BEGIN_MESSAGE_MAP(CAutoRun2Dlg, CDialog)
  200. //{{AFX_MSG_MAP(CAutoRun2Dlg)
  201. ON_WM_PAINT()
  202. ON_WM_QUERYDRAGICON()
  203. ON_WM_DESTROY()
  204. ON_BN_CLICKED(IDC_BTN_SEND, OnBtnSend)
  205. ON_BN_CLICKED(IDC_BTN_QUERY, OnBtnQuery)
  206. ON_BN_CLICKED(IDC_BTN_Query2, OnBTNQuery2)
  207. ON_BN_CLICKED(IDC_BTN_CHANGE_PWD, OnBtnChangePwd)
  208. ON_BN_CLICKED(IDC_BTN_GET_STATUS, OnBtnGetStatus)
  209. ON_WM_TIMER()
  210. ON_BN_CLICKED(IDC_BUTadd, OnBUTadd)
  211. ON_BN_CLICKED(IDC_BUTdel, OnBUTdel)
  212. ON_LBN_SELCHANGE(IDC_LIST2, OnSelchangeList2)
  213. ON_EN_CHANGE(IDC_EDT_SMS, OnChangeEdtSms)
  214. ON_EN_CHANGE(IDC_EDT_RECV_MOBI, OnChangeEdtRecvMobi)
  215. ON_BN_CLICKED(IDC_CHECK1, OnCheck1)
  216. ON_BN_CLICKED(IDC_BTN_REG, OnBtnReg)
  217. ON_COMMAND(IDM_CLOSE, OnClose)
  218. ON_COMMAND(IDM_AUTORUN, OnAutorun)
  219. //}}AFX_MSG_MAP
  220. ON_MESSAGE(WM_ICON_NOTIFY, OnTrayNotification)
  221. ON_REGISTERED_MESSAGE(g_wmClose, OnAbortClose)
  222. END_MESSAGE_MAP()
  223. /////////////////////////////////////////////////////////////////////////////
  224. LRESULT CAutoRun2Dlg::OnTrayNotification(WPARAM wParam,LPARAM lParam)
  225. {
  226. return m_TrayIcon.OnTrayNotification(wParam,lParam);
  227. }
  228. LRESULT CAutoRun2Dlg::OnAbortClose(WPARAM wParam, LPARAM lParam)
  229. {
  230. KillTimer(5);
  231. return 1;
  232. }
  233. BOOL CAutoRun2Dlg::OnInitDialog()
  234. {
  235. SetWindowPos(&wndNoTopMost,0,0,0,0,SWP_HIDEWINDOW);
  236. ModifyStyleEx(WS_EX_APPWINDOW,WS_EX_TOOLWINDOW);
  237. CDialog::OnInitDialog();
  238. // Set the icon for this dialog. The framework does this automatically
  239. // when the application's main window is not a dialog
  240. SetIcon(m_hIcon, TRUE); // Set big icon
  241. SetIcon(m_hIcon, FALSE); // Set small icon
  242. g_pMainWnd=this;
  243. char path[MAX_PATH];
  244. ::GetModuleFileName (NULL, path, MAX_PATH);
  245. g_mainpath=path;
  246. g_mainpath=g_mainpath.Left (g_mainpath.ReverseFind ('\\'));
  247. g_mainpath3=g_mainpath2=g_mainpath;
  248. g_mainpath+="\\LYFZMsgManage.exe";
  249. g_mainpath3+="\\LYFZIPManage.exe";
  250. ShellExecute(NULL, _T("open"), g_mainpath, "0", NULL, SW_SHOWNORMAL);
  251. ShellExecute(NULL, _T("open"), g_mainpath3, "0", NULL, SW_SHOWNORMAL);
  252. ShellExecute(NULL, _T("open"), g_mainpath2+"\\AutoRun3.exe", "0", NULL, SW_SHOWNORMAL);
  253. ShellExecute(NULL, _T("open"), g_mainpath2+"\\LYFZReceiveMsg.exe", "0", NULL, SW_SHOWNORMAL);
  254. ShellExecute(NULL, _T("open"), g_mainpath2+"\\LYFZReceiveMsg.exe", "1", NULL, SW_SHOWNORMAL);
  255. ShellExecute(NULL, _T("open"), g_mainpath2+"\\LYFZReceiveMsg.exe", "2", NULL, SW_SHOWNORMAL);
  256. ShellExecute(NULL, _T("open"), g_mainpath2+"\\LYFZReceiveMsg.exe", "3", NULL, SW_SHOWNORMAL);
  257. ShellExecute(NULL, _T("open"), g_mainpath2+"\\LYFZReceiveMsg.exe", "4", NULL, SW_SHOWNORMAL);
  258. ShellExecute(NULL, _T("open"), g_mainpath2+"\\LYFZReceiveMsg.exe", "5", NULL, SW_SHOWNORMAL);
  259. ShellExecute(NULL, _T("open"), g_mainpath2+"\\LYFZReceiveMsg.exe", "6", NULL, SW_SHOWNORMAL);
  260. ShellExecute(NULL, _T("open"), g_mainpath2+"\\LYFZReceiveMsg.exe", "20", NULL, SW_SHOWNORMAL);
  261. ShellExecute(NULL, _T("open"), g_mainpath2+"\\LYFZSendMsg.exe", NULL, NULL, SW_SHOWNORMAL);
  262. ShellExecute(NULL, _T("open"), g_mainpath2+"\\LYFZIPReceive.exe", "0", NULL, SW_SHOWNORMAL);
  263. ShellExecute(NULL, _T("open"), g_mainpath2+"\\LYFZIPReceive.exe", "1", NULL, SW_SHOWNORMAL);
  264. ShellExecute(NULL, _T("open"), g_mainpath2+"\\LYFZIPReceive.exe", "2", NULL, SW_SHOWNORMAL);
  265. ShellExecute(NULL, _T("open"), g_mainpath2+"\\LYFZIPReceive.exe", "3", NULL, SW_SHOWNORMAL);
  266. ShellExecute(NULL, _T("open"), g_mainpath2+"\\LYFZIPReceive.exe", "4", NULL, SW_SHOWNORMAL);
  267. ShellExecute(NULL, _T("open"), g_mainpath2+"\\LYFZIPReceive.exe", "5", NULL, SW_SHOWNORMAL);
  268. ShellExecute(NULL, _T("open"), g_mainpath2+"\\LYFZIPReceive.exe", "6", NULL, SW_SHOWNORMAL);
  269. UpdateMyIP();
  270. SetTimer(5, 10*60*1000, NULL);
  271. // SetTimer (6, 60*60*1000, NULL);
  272. /////////////////////////////////
  273. // TODO: Add extra initialization here
  274. return TRUE; // return TRUE unless you set the focus to a control
  275. }
  276. // If you add a minimize button to your dialog, you will need the code below
  277. // to draw the icon. For MFC applications using the document/view model,
  278. // this is automatically done for you by the framework.
  279. void CAutoRun2Dlg::OnPaint()
  280. {
  281. if (IsIconic())
  282. {
  283. CPaintDC dc(this); // device context for painting
  284. SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  285. // Center icon in client rectangle
  286. int cxIcon = GetSystemMetrics(SM_CXICON);
  287. int cyIcon = GetSystemMetrics(SM_CYICON);
  288. CRect rect;
  289. GetClientRect(&rect);
  290. int x = (rect.Width() - cxIcon + 1) / 2;
  291. int y = (rect.Height() - cyIcon + 1) / 2;
  292. // Draw the icon
  293. dc.DrawIcon(x, y, m_hIcon);
  294. }
  295. else
  296. {
  297. CDialog::OnPaint();
  298. }
  299. }
  300. // The system calls this to obtain the cursor to display while the user drags
  301. // the minimized window.
  302. HCURSOR CAutoRun2Dlg::OnQueryDragIcon()
  303. {
  304. return (HCURSOR) m_hIcon;
  305. }
  306. DWORD CAutoRun2Dlg::GetConnectionID()
  307. {
  308. return m_dwConnectionID;
  309. }
  310. void CAutoRun2Dlg::SetConnectionID(DWORD dwConnection)
  311. {
  312. m_dwConnectionID = dwConnection;
  313. }
  314. void CAutoRun2Dlg::ProcessChatMessageRequest2(CString sql)
  315. {
  316. const char *szDataBuf = sql.GetBuffer(0);
  317. sql.ReleaseBuffer();
  318. ProcessChatMessageRequest((void*)szDataBuf, strlen(szDataBuf) + 1);
  319. }
  320. void CAutoRun2Dlg::ProcessChatMessageRequest2(BYTE *pData, int length)
  321. {
  322. ProcessChatMessageRequest((void*)pData, length);
  323. }
  324. BOOL CAutoRun2Dlg::ProcessChatMessageRequest(void *szDataBuf, int nDataLen)
  325. {
  326. g_bReturned=0;
  327. DWORD dwFromUserID = GetConnectionID();
  328. WORD wMessageId = MSG_CHATMESSAGE_REQ;
  329. DWORD dwDataLen = sizeof(TCHAT_MESSAGE_STRU) + nDataLen;
  330. BYTE *pSendData = new BYTE[dwDataLen];
  331. TCHAT_MESSAGE_STRU *pChatMessage=(TCHAT_MESSAGE_STRU*)pSendData;
  332. memset(pChatMessage, 0x00, dwDataLen);
  333. g_sendhead.length[98]=987123768;
  334. memcpy(pSendData, &g_sendhead, sizeof(g_sendhead));
  335. pChatMessage->tCommonMsg.dwConnectionID = GetConnectionID();
  336. pChatMessage->tCommonMsg.wMessageId = wMessageId;
  337. pChatMessage->dwFromUserID = dwFromUserID;
  338. pChatMessage->dwToUserID = g_nSendCode;
  339. pChatMessage->wMessageLen = nDataLen;
  340. memcpy(pChatMessage->byFileContent, szDataBuf, nDataLen);
  341. TMessageHeader tHeader = {0};
  342. tHeader.wMessageId = wMessageId;
  343. tHeader.dwDataLen = dwDataLen;
  344. BOOL bRet=0;
  345. unsigned long ulSendLen = m_tClientTunnel.net_Send(&tHeader, (void *)pChatMessage, dwDataLen);
  346. if( ulSendLen != SOCKET_ERROR )
  347. {
  348. bRet=1;
  349. }
  350. delete [] pSendData;
  351. return bRet;
  352. }
  353. BOOL CAutoRun2Dlg::OnConnect()
  354. {
  355. g_server="lijiafz.vicp.net" ;
  356. MyGetIPByName(g_server);
  357. if(g_server.IsEmpty ())return OnConnect2();
  358. CString strServerAddress = g_server;
  359. char *szServerAddress = strServerAddress.GetBuffer(0);
  360. strServerAddress.ReleaseBuffer();
  361. /*for Client, IP and Port can be 0,
  362. and for Server, IP is LocalIP, and Port is Listening Port*/
  363. int nResult = m_tClientTunnel.net_OpenSocket(Transport_Client,
  364. 0,
  365. HandleClientNetEvent,
  366. this);
  367. if( TRANSPORT_OK != nResult )
  368. {
  369. return 0;
  370. }
  371. DWORD dwRemoteIPValue = inet_addr(szServerAddress);
  372. WORD wPort = SERVER_PORT;
  373. nResult = m_tClientTunnel.net_Connect(dwRemoteIPValue, wPort);
  374. if( TRANSPORT_OK != nResult )
  375. {
  376. m_tClientTunnel.net_CloseSocket();
  377. return OnConnect2();
  378. }
  379. return ProcessLoginRequest();
  380. }
  381. BOOL CAutoRun2Dlg::OnConnect2()
  382. {
  383. CString server="http://www.lyfz.net/download/ip.txt";
  384. char buf[MAX_PATH];
  385. ::GetTempPath(sizeof(buf),buf);
  386. CString m_strTempDir=buf;
  387. DWORD m_dwHttpRequestFlags=HSR_DOWNLOAD | INTERNET_FLAG_EXISTING_CONNECT | INTERNET_FLAG_NO_AUTO_REDIRECT;
  388. INTERNET_PORT m_dwPort;
  389. DWORD dwType;
  390. CInternetSession m_cis;
  391. CHttpConnection *m_pHttp;
  392. CString m_strServer;
  393. CString m_strIniPath;
  394. AfxParseURL(server,dwType,m_strServer,m_strIniPath,m_dwPort);
  395. if(dwType!=AFX_INET_SERVICE_HTTP)
  396. {
  397. return OnConnect3();
  398. }
  399. m_cis.SetOption(INTERNET_OPTION_CONNECT_TIMEOUT,5);
  400. m_pHttp=m_cis.GetHttpConnection(m_strServer,m_dwPort);
  401. try
  402. {
  403. m_pHttp=m_cis.GetHttpConnection(m_strServer,m_dwPort);
  404. }
  405. catch(CInternetException* pEx)
  406. {
  407. return OnConnect3();
  408. }
  409. CHttpFile *pFile = m_pHttp->OpenRequest(CHttpConnection::HTTP_VERB_GET,
  410. m_strIniPath, NULL, 1, NULL, NULL, m_dwHttpRequestFlags);
  411. try
  412. {
  413. pFile->SendRequest();
  414. }
  415. catch(CInternetException* pEx)
  416. {
  417. pFile->Close();
  418. return OnConnect3();
  419. }
  420. if(pFile)
  421. {
  422. CStdioFile csf;
  423. csf.Open(m_strTempDir+"\\ip.txt",CFile::modeCreate|CFile::modeWrite|CFile::typeBinary);
  424. char buf[2048];
  425. int n;
  426. while((n=pFile->Read(buf,2048))>0)
  427. csf.Write(buf,n);
  428. csf.Close();
  429. pFile->Close();
  430. }
  431. CStdioFile fp;
  432. fp.Open (m_strTempDir+"\\ip.txt", CFile::modeRead);
  433. fp.ReadString (g_server);
  434. fp.Close ();
  435. CString strServerAddress = g_server;
  436. char *szServerAddress = strServerAddress.GetBuffer(0);
  437. strServerAddress.ReleaseBuffer();
  438. /*for Client, IP and Port can be 0,
  439. and for Server, IP is LocalIP, and Port is Listening Port*/
  440. int nResult = m_tClientTunnel.net_OpenSocket(Transport_Client,
  441. 0,
  442. HandleClientNetEvent,
  443. this);
  444. if( TRANSPORT_OK != nResult )
  445. {
  446. return 0;
  447. }
  448. DWORD dwRemoteIPValue = inet_addr(szServerAddress);
  449. WORD wPort = SERVER_PORT;
  450. nResult = m_tClientTunnel.net_Connect(dwRemoteIPValue, wPort);
  451. if( TRANSPORT_OK != nResult )
  452. {
  453. m_tClientTunnel.net_CloseSocket();
  454. return OnConnect3();
  455. }
  456. return ProcessLoginRequest();
  457. }
  458. BOOL CAutoRun2Dlg::OnConnect3()
  459. {
  460. CString server="http://photo.bjlyfz.com/download/ip.txt";
  461. char buf[MAX_PATH];
  462. ::GetTempPath(sizeof(buf),buf);
  463. CString m_strTempDir=buf;
  464. DWORD m_dwHttpRequestFlags=HSR_DOWNLOAD | INTERNET_FLAG_EXISTING_CONNECT | INTERNET_FLAG_NO_AUTO_REDIRECT;
  465. INTERNET_PORT m_dwPort;
  466. DWORD dwType;
  467. CInternetSession m_cis;
  468. CHttpConnection *m_pHttp;
  469. CString m_strServer;
  470. CString m_strIniPath;
  471. AfxParseURL(server,dwType,m_strServer,m_strIniPath,m_dwPort);
  472. if(dwType!=AFX_INET_SERVICE_HTTP)
  473. {
  474. return FALSE;
  475. }
  476. m_cis.SetOption(INTERNET_OPTION_CONNECT_TIMEOUT,5);
  477. m_pHttp=m_cis.GetHttpConnection(m_strServer,m_dwPort);
  478. try
  479. {
  480. m_pHttp=m_cis.GetHttpConnection(m_strServer,m_dwPort);
  481. }
  482. catch(CInternetException* pEx)
  483. {
  484. return false;
  485. }
  486. CHttpFile *pFile = m_pHttp->OpenRequest(CHttpConnection::HTTP_VERB_GET,
  487. m_strIniPath, NULL, 1, NULL, NULL, m_dwHttpRequestFlags);
  488. try
  489. {
  490. pFile->SendRequest();
  491. }
  492. catch(CInternetException* pEx)
  493. {
  494. pFile->Close();
  495. return false;
  496. }
  497. if(pFile)
  498. {
  499. CStdioFile csf;
  500. csf.Open(m_strTempDir+"\\ip.txt",CFile::modeCreate|CFile::modeWrite|CFile::typeBinary);
  501. char buf[2048];
  502. int n;
  503. while((n=pFile->Read(buf,2048))>0)
  504. csf.Write(buf,n);
  505. csf.Close();
  506. pFile->Close();
  507. }
  508. CStdioFile fp;
  509. fp.Open (m_strTempDir+"\\ip.txt", CFile::modeRead);
  510. fp.ReadString (g_server);
  511. fp.Close ();
  512. CString strServerAddress = g_server;
  513. char *szServerAddress = strServerAddress.GetBuffer(0);
  514. strServerAddress.ReleaseBuffer();
  515. /*for Client, IP and Port can be 0,
  516. and for Server, IP is LocalIP, and Port is Listening Port*/
  517. int nResult = m_tClientTunnel.net_OpenSocket(Transport_Client,
  518. 0,
  519. HandleClientNetEvent,
  520. this);
  521. if( TRANSPORT_OK != nResult )
  522. {
  523. return 0;
  524. }
  525. DWORD dwRemoteIPValue = inet_addr(szServerAddress);
  526. WORD wPort = SERVER_PORT;
  527. nResult = m_tClientTunnel.net_Connect(dwRemoteIPValue, wPort);
  528. if( TRANSPORT_OK != nResult )
  529. {
  530. m_tClientTunnel.net_CloseSocket();
  531. return 0;
  532. }
  533. return ProcessLoginRequest();
  534. }
  535. void CAutoRun2Dlg::ProcessNetEvent(int nEventType, void *pRecvMsg, DWORD dwDataLen)
  536. {
  537. if( Transport_ReadEv == nEventType )
  538. {
  539. if( NULL == pRecvMsg ) return;
  540. TMessageHeader* pHeader = (TMessageHeader *)pRecvMsg;
  541. char *pDataBuf = (char *)pRecvMsg + MESSAGE_HEADER_LEN;
  542. WORD dwMessageID = pHeader->wMessageId;
  543. switch(dwMessageID)
  544. {
  545. case MSG_LOGIN_RESP:
  546. {
  547. LOGIN_RESULT_STRU tLoginResult = {0};
  548. memcpy(&tLoginResult, pDataBuf, sizeof(LOGIN_RESULT_STRU));
  549. ProcessLoginResponse(&tLoginResult);
  550. break;
  551. }
  552. case MSG_USERINFO_RESP:
  553. {
  554. TUSERLIST_INFO_STRU tUserListInfo = {0};
  555. memcpy(&tUserListInfo, pDataBuf, sizeof(TUSERLIST_INFO_STRU));
  556. // ProcessUserListInfoResponse(&tUserListInfo);
  557. break;
  558. }
  559. case MSG_LOGOUT_RESP:
  560. {
  561. TUSERLIST_INFO_STRU tUserListInfo = {0};
  562. memcpy(&tUserListInfo, pDataBuf, sizeof(TUSERLIST_INFO_STRU));
  563. // ProcessLogoutResponse(&tUserListInfo);
  564. break;
  565. }
  566. case MSG_CHATMESSAGE_RESP:
  567. {
  568. TCHAT_MESSAGE_STRU *pChatMessage = (TCHAT_MESSAGE_STRU *)pDataBuf;
  569. ProcessChatMessageResponse((void *)pChatMessage);
  570. break;
  571. }
  572. default:
  573. {
  574. break;
  575. }
  576. }
  577. }
  578. else if( Transport_CloseEv == nEventType )
  579. {
  580. SetTimer(DISCONNECT_TIMER, 0, NULL);
  581. }
  582. ///////
  583. }
  584. void CAutoRun2Dlg::OnDisconnect()
  585. {
  586. m_tClientTunnel.net_CloseSocket();
  587. SetConnectionID(INVALID_SOCKET);
  588. }
  589. void CAutoRun2Dlg::ProcessLoginResponse(void *pLoginResult)
  590. {
  591. if( NULL == pLoginResult ) return;
  592. LOGIN_RESULT_STRU *ptLoginResult = (LOGIN_RESULT_STRU *)pLoginResult;
  593. DWORD dwConnectionID = ptLoginResult->tCommonMsg.dwConnectionID;
  594. SetConnectionID(dwConnectionID);
  595. BYTE byResult = ptLoginResult->byResult;
  596. if(LOGIN_RESULT_SUC == byResult)
  597. {
  598. }
  599. else
  600. {
  601. SetTimer(LOGINFAILED_TIMER, 0, NULL);
  602. }
  603. CString strCommentInfo("");
  604. strCommentInfo.Format("%s. 用户代号: %ld",
  605. ((LOGIN_RESULT_SUC == byResult) ? "登录成功" :
  606. (LOGIN_RESULT_MULTI == byResult) ? "重复登录" :
  607. (LOGIN_RESULT_NAMERROR == byResult) ? "名字不存在" :
  608. (LOGIN_RESULT_PWERROR == byResult) ? "密码错误" : "登录失败"),
  609. dwConnectionID);
  610. // MessageBox((CString)strCommentInfo);
  611. }
  612. CString newGUID()
  613. {
  614. CString str;
  615. GUID guid;
  616. CoInitialize(NULL);
  617. if (S_OK == ::CoCreateGuid(&guid))
  618. {
  619. str.Format (
  620. "{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
  621. guid.Data1,
  622. guid.Data2,
  623. guid.Data3,
  624. guid.Data4[0], guid.Data4[1],
  625. guid.Data4[2], guid.Data4[3],
  626. guid.Data4[4], guid.Data4[5],
  627. guid.Data4[6], guid.Data4[7]);
  628. }
  629. CoUninitialize();
  630. return str.Left (28);
  631. }
  632. BOOL CAutoRun2Dlg::ProcessLoginRequest()
  633. {
  634. WORD wMessageId = MSG_LOGIN_REQ;
  635. TLOGIN_STRU tLogonInfo = {0};
  636. tLogonInfo.tCommonMsg.dwConnectionID = GetConnectionID();
  637. tLogonInfo.tCommonMsg.wMessageId = wMessageId;
  638. CString strUserName = newGUID();
  639. strUserName.TrimLeft();
  640. strUserName.TrimRight();
  641. strcpy(tLogonInfo.tUserInfo.szUserName, strUserName);
  642. DWORD dwDataLen = sizeof(TLOGIN_STRU);
  643. TMessageHeader tHeader = {0};
  644. tHeader.wMessageId = wMessageId;
  645. tHeader.dwDataLen = dwDataLen;
  646. unsigned long ulSendLen = m_tClientTunnel.net_Send(&tHeader, (void *)&tLogonInfo, dwDataLen);
  647. if( ulSendLen == SOCKET_ERROR )
  648. {
  649. return 0;
  650. }
  651. return 1;
  652. }
  653. //---------------------------------------------------------------------------
  654. void CAutoRun2Dlg::OnDestroy()
  655. {
  656. CDialog::OnDestroy();
  657. OnDisconnect();
  658. Transport_UnInit();
  659. m_TrayIcon.RemoveIcon();
  660. }
  661. int GetAppProcessCount(CString path)
  662. {
  663. int count=0;
  664. HANDLE handle=::CreateToolhelp32Snapshot(TH32CS_SNAPALL,0);
  665. PROCESSENTRY32 Info;
  666. Info.dwSize = sizeof(PROCESSENTRY32);
  667. path.MakeLower ();
  668. if(::Process32First(handle,&Info))
  669. {
  670. do
  671. {
  672. CString ss=Info.szExeFile;
  673. ss.MakeLower ();
  674. if(ss.Find (path)!=-1 || (!ss.CompareNoCase(path)) )
  675. {
  676. count++;
  677. }
  678. }
  679. while(::Process32Next(handle,&Info));
  680. ::CloseHandle(handle);
  681. }
  682. return count;
  683. }
  684. void CAutoRun2Dlg::OnTimer(UINT nIDEvent)
  685. {
  686. // TODO: Add your message handler code here and/or call default
  687. if( 2 == nIDEvent )
  688. {
  689. UpdateMyIP();
  690. }
  691. else if(nIDEvent==5)
  692. {
  693. ShellExecute(NULL, _T("open"), g_mainpath2+"\\LYFZReceiveMsg.exe", "0", NULL, SW_SHOWNORMAL);
  694. ShellExecute(NULL, _T("open"), g_mainpath2+"\\LYFZReceiveMsg.exe", "1", NULL, SW_SHOWNORMAL);
  695. ShellExecute(NULL, _T("open"), g_mainpath2+"\\LYFZReceiveMsg.exe", "2", NULL, SW_SHOWNORMAL);
  696. ShellExecute(NULL, _T("open"), g_mainpath2+"\\LYFZReceiveMsg.exe", "3", NULL, SW_SHOWNORMAL);
  697. ShellExecute(NULL, _T("open"), g_mainpath2+"\\LYFZReceiveMsg.exe", "4", NULL, SW_SHOWNORMAL);
  698. ShellExecute(NULL, _T("open"), g_mainpath2+"\\LYFZReceiveMsg.exe", "5", NULL, SW_SHOWNORMAL);
  699. ShellExecute(NULL, _T("open"), g_mainpath2+"\\LYFZReceiveMsg.exe", "6", NULL, SW_SHOWNORMAL);
  700. ShellExecute(NULL, _T("open"), g_mainpath2+"\\LYFZReceiveMsg.exe", "20", NULL, SW_SHOWNORMAL);
  701. ShellExecute(NULL, _T("open"), g_mainpath2+"\\LYFZSendMsg.exe", NULL, NULL, SW_SHOWNORMAL);
  702. ShellExecute(NULL, _T("open"), g_mainpath2+"\\LYFZIPReceive.exe", "0", NULL, SW_SHOWNORMAL);
  703. ShellExecute(NULL, _T("open"), g_mainpath2+"\\LYFZIPReceive.exe", "1", NULL, SW_SHOWNORMAL);
  704. ShellExecute(NULL, _T("open"), g_mainpath2+"\\LYFZIPReceive.exe", "2", NULL, SW_SHOWNORMAL);
  705. ShellExecute(NULL, _T("open"), g_mainpath2+"\\LYFZIPReceive.exe", "3", NULL, SW_SHOWNORMAL);
  706. ShellExecute(NULL, _T("open"), g_mainpath2+"\\LYFZIPReceive.exe", "4", NULL, SW_SHOWNORMAL);
  707. ShellExecute(NULL, _T("open"), g_mainpath2+"\\LYFZIPReceive.exe", "5", NULL, SW_SHOWNORMAL);
  708. ShellExecute(NULL, _T("open"), g_mainpath2+"\\LYFZIPReceive.exe", "6", NULL, SW_SHOWNORMAL);
  709. ShellExecute(NULL, _T("open"), g_mainpath2+"\\RefIP.exe", NULL, NULL, SW_SHOWNORMAL);
  710. }
  711. else if(nIDEvent==6)
  712. {
  713. // MyExitWindows();
  714. }
  715. }
  716. void CAutoRun2Dlg::OnBUTadd()
  717. {
  718. // TODO: Add your control notification handler code here
  719. AddContact dlg;
  720. if(dlg.DoModal ()!=IDOK)return;
  721. CString str;
  722. int pos;
  723. for(int i=0; i<m_List1.GetCount (); i++)
  724. {
  725. m_List1.GetText (i, str);
  726. pos=str.Find ("\r\n");
  727. if(dlg.m_phone==str.Right (str.GetLength ()-pos-2))
  728. {
  729. AfxMessageBox("已有此电话的记录!");
  730. return;
  731. }
  732. }
  733. CString sql;
  734. sql= "insert into contact([name],[phone]) values(\
  735. '"+dlg.m_name+"',\
  736. '"+dlg.m_phone+"')";
  737. g_db.ExecuteSQL (sql);
  738. if(m_List1.GetCount()%2)
  739. m_List1.AddEntry( dlg.m_name+"\r\n"+dlg.m_phone , RGB(240,247,255), m_List1.GetCount());
  740. else
  741. m_List1.AddEntry( dlg.m_name+"\r\n"+dlg.m_phone , RGB(255,248,240), m_List1.GetCount());
  742. }
  743. void CAutoRun2Dlg::OnBUTdel()
  744. {
  745. // TODO: Add your control notification handler code here
  746. int listpos=m_List1.GetCurSel ();
  747. if(listpos==-1)
  748. {
  749. AfxMessageBox("请先选中您要删除的联系人!");
  750. return;
  751. }
  752. if(AfxMessageBox("警告:删除后将不可恢复, 继续吗?", MB_YESNO|MB_ICONSTOP)!=IDYES)return;
  753. CString str;
  754. m_List1.GetText (listpos, str);
  755. int pos=str.Find ("\r\n");
  756. CString name=str.Left (pos);
  757. CString phone=str.Right (str.GetLength ()-pos-2);
  758. CString sql;
  759. sql= "delete from contact where [name]='"+name+"' and [phone]='"+phone+"'";
  760. g_db.ExecuteSQL (sql);
  761. m_List1.DeleteString(listpos);
  762. }
  763. void CAutoRun2Dlg::OnSelchangeList2()
  764. {
  765. // TODO: Add your control notification handler code here
  766. UpdateData();
  767. int count= m_List1.GetSelCount() ;
  768. if(count==0)return;
  769. int *pIndex=new int[count];
  770. m_List1.GetSelItems(count, pIndex);
  771. m_strRecvMobi = _T("");
  772. m_mobicount = 0;
  773. CString str;
  774. int pos;
  775. m_nMobile=0;
  776. m_nPhone=0;
  777. for(int i=0; i<count; i++)
  778. {
  779. m_List1.GetText (pIndex[i], str);
  780. pos=str.Find ("\r\n");
  781. if(CheckPhoneType(str.Right (str.GetLength ()-pos-2))==0)
  782. m_nMobile++;
  783. else if(CheckPhoneType(str.Right (str.GetLength ()-pos-2))==1)
  784. m_nPhone++;
  785. else
  786. {
  787. AfxMessageBox("号码"+str.Right (str.GetLength ()-pos-2)+"不是正确的电话号码!", MB_ICONSTOP);
  788. continue;
  789. }
  790. m_strRecvMobi+=str.Right (str.GetLength ()-pos-2);
  791. m_strRecvMobi+=",";
  792. m_mobicount++;
  793. }
  794. m_strRecvMobi.TrimRight (",");
  795. UpdateData(false);
  796. delete []pIndex;
  797. OnChangeEdtSms();
  798. }
  799. int CAutoRun2Dlg::CheckPhoneType(CString phoneno)
  800. {
  801. if(phoneno.IsEmpty())return -1;
  802. for(int i=0; i<phoneno.GetLength (); i++)
  803. {
  804. if(phoneno.GetAt (i)<'0'||phoneno.GetAt (i)>'9')return -1;
  805. }
  806. if(phoneno.GetAt (0)=='1')
  807. {
  808. if(phoneno.GetLength ()!=11)
  809. return -1;
  810. int mobile[]={139,138,137,136,135,134,159,158,152,151,150,157,188,187,144};
  811. int unicom[]={130,131,132,155,156,186,185};
  812. int telecom[]={133,153,189,180,181};
  813. BOOL bFind=0;
  814. for(i=0; i<sizeof(mobile)/sizeof(int); i++)
  815. {
  816. if(mobile[i]==atoi(phoneno.Left (3)))
  817. {
  818. bFind=1;
  819. break;
  820. }
  821. }
  822. for(i=0; i<sizeof(unicom)/sizeof(int); i++)
  823. {
  824. if(unicom[i]==atoi(phoneno.Left (3)))
  825. {
  826. bFind=1;
  827. break;
  828. }
  829. }
  830. for(i=0; i<sizeof(telecom)/sizeof(int); i++)
  831. {
  832. if(telecom[i]==atoi(phoneno.Left (3)))
  833. {
  834. bFind=1;
  835. break;
  836. }
  837. }
  838. if(!bFind)
  839. return -1;
  840. else
  841. {
  842. // m_nMobile++;
  843. return 0;
  844. }
  845. }
  846. return -1;
  847. }
  848. /*
  849. 移动:
  850. 139,138,137,136,135,134,159,158,152,151,150,157,188,187,144
  851. 联通:
  852. 130,131,132,155,156,186,185
  853. 电信:
  854. 133,153,189,180
  855. */
  856. void CAutoRun2Dlg::OnChangeEdtRecvMobi()
  857. {
  858. // TODO: If this is a RICHEDIT control, the control will not
  859. // send this notification unless you override the CDialog::OnInitDialog()
  860. // function and call CRichEditCtrl().SetEventMask()
  861. // with the ENM_CHANGE flag ORed into the mask.
  862. // TODO: Add your control notification handler code here
  863. }
  864. void CAutoRun2Dlg::OnChangeEdtSms()
  865. {
  866. // TODO: If this is a RICHEDIT control, the control will not
  867. // send this notification unless you override the CDialog::OnInitDialog()
  868. // function and call CRichEditCtrl().SetEventMask()
  869. // with the ENM_CHANGE flag ORed into the mask.
  870. UpdateData();
  871. m_strSendSms.Replace ("'", "'");
  872. m_strSendSms.Replace ("(", "(");
  873. m_strSendSms.Replace (")", ")");
  874. SetDlgItemText(IDC_EDT_SMS, m_strSendSms);
  875. ((CEdit*)GetDlgItem(IDC_EDT_SMS))->SetSel(m_strSendSms.GetLength (),m_strSendSms.GetLength ());
  876. CString str;
  877. int count=0;
  878. int leng=GetLengthEx(m_strSendSms);
  879. if(m_nMobile)
  880. {
  881. count+=m_nMobile*(leng/70);
  882. if(leng%70)
  883. count+=m_nMobile;
  884. }
  885. if(m_nPhone)
  886. {
  887. count+=m_nPhone*(leng/56);
  888. if(leng%56)
  889. count+=m_nPhone;
  890. }
  891. m_count=count;
  892. str.Format ("短信内容(手机70字/条,小灵通56字/条)(现%d字,共%d条短信)", leng,count);
  893. GetDlgItem(IDC_STATIC1)->SetWindowText(str);
  894. // TODO: Add your control notification handler code here
  895. }
  896. int CAutoRun2Dlg::GetLengthEx(CString str)
  897. {
  898. int leng=0;
  899. TBYTE ucHigh, ucLow;
  900. for (int i=0; i<str.GetLength(); i++)
  901. {
  902. if ( (TBYTE)str[i] < 0x80 )
  903. {
  904. leng++;
  905. continue;
  906. }
  907. ucHigh = (TBYTE)str[i];
  908. ucLow = (TBYTE)str[i+1];
  909. if ( ucHigh < 0xa1 || ucLow < 0xa1)
  910. {
  911. leng++;
  912. continue;
  913. }
  914. leng++;
  915. i++;
  916. }
  917. return leng;
  918. }
  919. //---------------------------------------------------------------------------
  920. void CAutoRun2Dlg::OnBtnSend()
  921. {
  922. }
  923. void CAutoRun2Dlg::OnCheck1()
  924. {
  925. // TODO: Add your control notification handler code here
  926. UpdateData();
  927. }
  928. //---------------------------------------------------------------------------
  929. void CAutoRun2Dlg::OnBtnQuery() //查询余额
  930. {
  931. }
  932. //---------------------------------------------------------------------------
  933. void CAutoRun2Dlg::OnBTNQuery2()//查询使用
  934. {
  935. }
  936. void CAutoRun2Dlg::OnBtnChangePwd()
  937. {
  938. }
  939. void CAutoRun2Dlg::OnBtnGetStatus()
  940. {
  941. }
  942. BOOL CAutoRun2Dlg::MyExecuteSQL(CDatabase *pdb, CString sql)
  943. {
  944. try
  945. {
  946. pdb->ExecuteSQL (sql);
  947. }
  948. catch(...)
  949. {
  950. return 0;
  951. }
  952. return 1;
  953. }
  954. BOOL CAutoRun2Dlg::CheckExist(CString content, CString phones)
  955. {
  956. CRecordset myset(&g_db);
  957. CString sql="select count(*) as cot from sendreg where [content]='"+content+"' and [phones]='"+phones+"'";
  958. myset.Open (CRecordset::forwardOnly, sql);
  959. if(!myset.IsEOF())
  960. {
  961. myset.GetFieldValue ("cot", sql);
  962. if(atoi(sql))
  963. return 1;
  964. else
  965. return 0;
  966. }
  967. else
  968. return 0;
  969. }
  970. void CAutoRun2Dlg::OnBtnReg()
  971. {
  972. // TODO: Add your control notification handler code here
  973. UpdateData();
  974. SendReg dlg;
  975. dlg.m_strLoginID=m_strLoginID;
  976. dlg.m_strLoginPwd=m_strLoginPwd;
  977. dlg.DoModal ();
  978. }
  979. void CAutoRun2Dlg::OnClose()
  980. {
  981. // TODO: Add your command handler code here
  982. TerminateThread();
  983. CDialog::OnCancel ();
  984. }
  985. BOOL CAutoRun2Dlg::TerminateThread()
  986. {
  987. try
  988. {
  989. if ( !m_bRunning )
  990. return TRUE;
  991. m_bTerminate=true;
  992. for( ; ; )
  993. {
  994. if ( ::WaitForSingleObject(m_hThread, 0) == WAIT_OBJECT_0 )
  995. break;
  996. MSG msg;
  997. while (::PeekMessage(&msg,NULL,0,0,PM_NOREMOVE))
  998. {
  999. if (!AfxGetApp()->PumpMessage())
  1000. break;
  1001. }
  1002. }
  1003. ::CloseHandle(m_hThread);
  1004. m_bRunning=false;
  1005. return TRUE;
  1006. }
  1007. catch(...)
  1008. {
  1009. }
  1010. }
  1011. CArray<CStringArray, CStringArray>g_List1array;
  1012. DWORD g_nLeng=0;
  1013. BYTE *g_pData=NULL;
  1014. CString g_str="";
  1015. void CAutoRun2Dlg::ProcessChatMessageResponse(void *pResponse)
  1016. {
  1017. if( NULL == pResponse ) return;
  1018. g_str="";
  1019. TCHAT_MESSAGE_STRU *pChatMessage = (TCHAT_MESSAGE_STRU *)pResponse;
  1020. int nMessageLen = pChatMessage->wMessageLen;
  1021. DWORD dwToUserID = pChatMessage->dwToUserID;
  1022. char *pStr=new char[nMessageLen+1];
  1023. memset(pStr, 0, nMessageLen+1);
  1024. memcpy(pStr, pChatMessage->byFileContent, nMessageLen);
  1025. CString str=pStr;
  1026. delete []pStr;
  1027. if(str=="账户或密码错误!")
  1028. {
  1029. g_bSendOK=0;
  1030. }
  1031. else
  1032. {
  1033. if(dwToUserID==0 && str!="发送信息成功!")
  1034. g_bSendOK=0;
  1035. else
  1036. g_bSendOK=1;
  1037. }
  1038. g_str=str;
  1039. g_bReturned=1;
  1040. }
  1041. void CAutoRun2Dlg::OnAutorun()
  1042. {
  1043. // TODO: Add your command handler code here
  1044. g_bAutoRun=!g_bAutoRun;
  1045. CString version = _T ("Version 1.0");
  1046. AfxGetApp()->WriteProfileInt (version, "brun", g_bAutoRun);
  1047. TCHAR szKey[MAX_PATH];
  1048. HKEY hKey=0;
  1049. DWORD disp=0;
  1050. lstrcpy(szKey,"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run");
  1051. if(g_bAutoRun)
  1052. {
  1053. int lResult=RegCreateKeyEx(HKEY_LOCAL_MACHINE,szKey,0,NULL,REG_OPTION_VOLATILE, KEY_ALL_ACCESS,NULL,&hKey,&disp);
  1054. if(lResult==ERROR_SUCCESS)
  1055. {
  1056. TCHAR szDir[MAX_PATH];
  1057. ::GetModuleFileName (NULL, szDir, MAX_PATH);
  1058. lResult=RegSetValueEx(hKey,"YLGLAutoRun2",0,REG_SZ,(const unsigned char*)szDir,lstrlen(szDir));
  1059. RegCloseKey(hKey);
  1060. }
  1061. }
  1062. else
  1063. {
  1064. int lResult=RegCreateKeyEx(HKEY_LOCAL_MACHINE,szKey,0,NULL,REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS,NULL,&hKey,&disp);
  1065. if(lResult==ERROR_SUCCESS)
  1066. {
  1067. RegDeleteValue(hKey,"YLGLAutoRun2");
  1068. RegDeleteKey (hKey,"YLGLAutoRun2");
  1069. RegCloseKey(hKey);
  1070. }
  1071. }
  1072. }
  1073. CString g_ip="";
  1074. void CAutoRun2Dlg::UpdateMyIP()
  1075. {
  1076. try
  1077. {
  1078. KillTimer(2);
  1079. URLDownloadToFile(NULL,"http://www.ip38.com/","ip.txt",0,NULL);
  1080. CString str,sip;
  1081. CStdioFile fp;
  1082. int pos;
  1083. if(fp.Open ("ip.txt", CFile::modeRead))
  1084. {
  1085. CString findstr="&nbsp;&nbsp;来自";
  1086. while(!feof(fp.m_pStream))
  1087. {
  1088. fp.ReadString (str);
  1089. pos=str.Find (findstr);
  1090. if(pos!=-1)
  1091. {
  1092. str=str.Left (pos);
  1093. str.TrimLeft ();
  1094. str.TrimRight ();
  1095. sip=str;
  1096. break;
  1097. }
  1098. }
  1099. fp.Close ();
  1100. }
  1101. if(sip.IsEmpty ())
  1102. {
  1103. SetTimer(2, 5*60*1000, NULL);
  1104. return;
  1105. }
  1106. if(sip==g_ip)return;
  1107. {
  1108. fp.Open (g_mainpath2+"\\ip.txt", CFile::modeCreate|CFile::modeWrite);
  1109. fp.WriteString (sip);
  1110. fp.Close ();
  1111. }
  1112. /////////////////////////
  1113. CString szAppName=AfxGetAppName();
  1114. // CString szFtpName="125.65.112.80";
  1115. CString szFtpName="124.172.244.12";
  1116. int nPort=21;
  1117. // CString szFtpUser="lyfzyl";
  1118. // CString szFtpPassword="gXDYFUgI";
  1119. CString szFtpUser="webmaster@lyfz.net";
  1120. CString szFtpPassword="c65fbac2";
  1121. char szFtpDirectory[MAX_PATH];
  1122. strcpy(szFtpDirectory, "htdocs/download/");
  1123. char szLocDirectory[MAX_PATH];
  1124. CString szFile;
  1125. HINTERNET hInetSession=InternetOpen(szAppName,INTERNET_OPEN_TYPE_PRECONFIG,NULL,NULL,0);
  1126. HINTERNET hFtpConn=InternetConnect(hInetSession,szFtpName,nPort,
  1127. szFtpUser,szFtpPassword,INTERNET_SERVICE_FTP,INTERNET_FLAG_PASSIVE,0);
  1128. if(!hFtpConn)
  1129. {
  1130. InternetCloseHandle(hInetSession);
  1131. SetTimer(2, 5*60*1000, NULL);
  1132. return;
  1133. }
  1134. DWORD dwLength=MAX_PATH;
  1135. if(FtpSetCurrentDirectory(hFtpConn,szFtpDirectory)==0)
  1136. {
  1137. InternetCloseHandle(hFtpConn);
  1138. InternetCloseHandle(hInetSession);
  1139. SetTimer(2, 5*60*1000, NULL);
  1140. return;
  1141. }
  1142. if(FtpPutFile(hFtpConn,g_mainpath2+"\\ip.txt","ip.txt",INTERNET_FLAG_TRANSFER_BINARY ,0))
  1143. {
  1144. InternetCloseHandle(hFtpConn);
  1145. InternetCloseHandle(hInetSession);g_ip=sip;
  1146. SetTimer(2, 30*60*1000, NULL);
  1147. }
  1148. else
  1149. {
  1150. InternetCloseHandle(hFtpConn);
  1151. InternetCloseHandle(hInetSession);
  1152. SetTimer(2, 5*60*1000, NULL);
  1153. }
  1154. }
  1155. catch(...)
  1156. {
  1157. }
  1158. }