www.pudn.com > CirMMI.rar > CirMMI.cpp


// CirMMI.cpp : Defines the class behaviors for the application. 
// 
 
#include "stdafx.h" 
#include "CirMMI.h" 
#include "CirMMIDlg.h" 
#include "common.h" 
 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
 
///////////////////////////////////////////////////////////////////////////// 
// CCirMMIApp 
 
BEGIN_MESSAGE_MAP(CCirMMIApp, CWinApp) 
	//{{AFX_MSG_MAP(CCirMMIApp) 
		// NOTE - the ClassWizard will add and remove mapping macros here. 
		//    DO NOT EDIT what you see in these blocks of generated code! 
	//}}AFX_MSG 
END_MESSAGE_MAP() 
 
///////////////////////////////////////////////////////////////////////////// 
// CCirMMIApp construction 
 
CCirMMIApp::CCirMMIApp() 
	: CWinApp() 
{ 
	// TODO: add construction code here, 
	// Place all significant initialization in InitInstance 
} 
 
///////////////////////////////////////////////////////////////////////////// 
// The one and only CCirMMIApp object 
 
CCirMMIApp theApp; 
 
CSocket g_MyDebug; 
INT DebugOut(const void *pV,INT isize,INT iType) 
{ 
	static BYTE buf[2048]; 
	INT sends=0; 
	if(g_MyDebug.m_hSocket!=INVALID_SOCKET && isize>0 ) 
	{ 
		BYTE *p=buf;		 
		p[0]=(BYTE)iType; 
		*((SHORT*)&p[1])=isize; 
		memcpy(p+3,pV,min(isize,2040)); 
		sends=g_MyDebug.SendTo(p,isize+3,g_CommonSet.nRemotePort,g_CommonSet.strRemoteIP);		 
 
		if(FALSE)//temp 
		{ 
			MEMORYSTATUS ms; 
			ms.dwLength=sizeof ms; 
			GlobalMemoryStatus(&ms); 
			sprintf((char*)buf+3,\ 
				"MEMORYSTATUS{MemoryLoad=%d,TotalPhys=%d,AailPhys=%d,TotalPageFile=%d,AvailPageFile=%d,TotalVirTual=%d,AvaidVirtual=%d}",\ 
				ms.dwMemoryLoad,ms.dwTotalPhys,ms.dwAvailPhys,ms.dwTotalPageFile,ms.dwAvailPageFile,ms.dwTotalVirtual,ms.dwAvailVirtual); 
 
			isize=strlen((char*)buf+3); 
			buf[0]=TEXT_TYPE; 
			*((SHORT*)&buf[1])=isize; 
			g_MyDebug.SendTo(buf,isize+3,g_CommonSet.nRemotePort,g_CommonSet.strRemoteIP);		 
 
		} 
	} 
	return sends; 
 
} 
 
 
 
///////////////////////////////////////////////////////////////////////////// 
// CCirMMIApp initialization 
// 
BOOL CCirMMIApp::InitInstance() 
{ 
	extern CString g_strWavePath; 
	CString strCurPath; 
	HANDLE  hOnlyInstance; 
	if ((hOnlyInstance=CreateMutex( NULL,false,_T("_CIRMMI_")) )==NULL) 
		return -1; 
	else if (GetLastError()==ERROR_ALREADY_EXISTS) 
	{ 
		//::MessageBox(NULL,L"Mutex (CIRMMI) 已经存在",L"提示",IDOK); 
		return FALSE; 
	} 
 
	if (!AfxSocketInit()) 
	{ 
		AfxMessageBox(IDP_SOCKETS_INIT_FAILED); 
		return FALSE; 
	} 
 
	#define RESET_REG	 0x01 
	#define UNLOAD_REG		0x02 
	#define WAVEPATH	0x04 
	#define START_SVR	0x08 
 
	DWORD dwCmdFlag=0; 
 
	//* 分析命令参数 
 
	int     iArgCount           = wce_GetArgCount( m_lpCmdLine ); 
	TCHAR   szTmp[MAX_PATH*2]   = _T(""); 
	TCHAR*  pszArgList          = m_lpCmdLine; 
	 
	for (int i = 0; i < iArgCount; i++) 
	{ 
		pszArgList = wce_GetNextArg( pszArgList, szTmp ); 
		LPCTSTR pszParam = &szTmp[0]; 
		ASSERT(pszParam); 
		BOOL bFlag = FALSE; 
		BOOL bLast = ((i + 1) == iArgCount); 
		if (pszParam[0] == '-' || pszParam[0] == '/') 
		{ 
			// remove flag specifier 
			bFlag = TRUE; 
			++pszParam; 
				if(lstrcmp(pszParam,_T("R")) == 0 || lstrcmp(pszParam,_T("r"))==0 ) 
			{ 
				dwCmdFlag|=RESET_REG; 
			}else if(lstrcmp(pszParam,_T("U")) == 0 || lstrcmp(pszParam,_T("u"))==0) 
			{ 
				dwCmdFlag|=UNLOAD_REG; 
				 
			}else if(pszParam[0]=='W' || pszParam[0]=='w') 
			{	 
				++pszParam; 
				if(pszParam[0]=='=') 
				{ 
					++pszParam; 
					strCurPath=pszParam;				 
					dwCmdFlag|=WAVEPATH; 
					 
				} 
			}else if(pszParam[0]=='S' || pszParam[0]=='s') 
			{ 
				++pszParam; 
				if(pszParam[0]=='=') 
				{ 
					pszParam++; 
					 
					STARTUPINFO siStartInfo; 
					PROCESS_INFORMATION ProcInfo; 
					ZeroMemory(&siStartInfo,sizeof(siStartInfo)); 
					ZeroMemory(&ProcInfo,sizeof(ProcInfo)); 
					siStartInfo.cb=sizeof siStartInfo;					 
					CreateProcess(pszParam,NULL,0,0,0,0,0,0,&siStartInfo,&ProcInfo);				 
					CloseHandle(ProcInfo.hProcess); 
					dwCmdFlag|=START_SVR; 
				} 
 
			} 
		} 
	} 
 
	//*/	 
 
 
 	if(!(WAVEPATH & dwCmdFlag)) 
	{ 
		CString strExeName=this->m_pszExeName; 
		strCurPath=this->m_pszHelpFilePath; 
		strCurPath.TrimRight(strExeName+_T(".HTP")); 
	} 
	 
 
	//CCommandLineInfo rCmdInfo; 
	//this->ParseCommandLine(rCmdInfo); 
	 
 
	// 配置信息 
	//SetRegistryKey(_T("TCB_MOBILE")); 
	 
	//初始化全局公共变量 
	InitGlobalSet(); 
 
	if(dwCmdFlag & RESET_REG) 
	{		 
 
		HKEY hKey=NULL;	 
		if(ERROR_SUCCESS==::RegOpenKeyEx(HKEY_LOCAL_MACHINE,_T("software"),0,KEY_ALL_ACCESS,&hKey)) 
		{			 
			//DelRegTree(hKey,_T("gsmr-mmi"));	 
			RegDeleteKey(hKey,_T("tcb-mobile")); 
			RegCloseKey(hKey); 
		} 
	} 
		 
	if(!(dwCmdFlag & UNLOAD_REG)) 
		LoadSetting(); 
	 
	//设置ftp 
	void SetFTPKey(); 
	SetFTPKey(); 
	 
	if(strCurPath.Left(1)!=_T("\\")) 
		strCurPath.Insert(0,'\\'); 
	 
	if(strCurPath.Right(1)!=_T("\\")) 
	{ 
		strCurPath+=_T("\\"); 
	} 
	 
	g_strWavePath=strCurPath+_T("wavedir\\"); 
//	g_strWavePath=strCurPath+_T("harddisk\\wavedir\\"); 
	STARTUPINFO siStartInfo; 
	PROCESS_INFORMATION ProcInfo; 
	ZeroMemory(&siStartInfo,sizeof(siStartInfo)); 
	ZeroMemory(&ProcInfo,sizeof(ProcInfo)); 
	if(g_CommonSet.strSvrName.GetLength()>0) //mmi-svr.exe 启动路径位于当前程序同一目录 
	{		 
				 
		siStartInfo.cb=sizeof siStartInfo;					 
		CreateProcess(strCurPath+g_CommonSet.strSvrName,NULL,0,0,0,0,0,0,&siStartInfo,&ProcInfo);										 
		//CloseHandle(ProcInfo.hProcess); 
			 
	} 
	 
 
 
	// 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. 
 
	if(!g_MyDebug.Create(0,SOCK_DGRAM)) 
		ASSERT(g_MyDebug.m_hSocket==INVALID_SOCKET); 
 
 
	SetDialogBkColor(g_CommonSet.crMainBk,g_CommonSet.crMainText); 
	CCirMMIDlg 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 
	} 
 
	// Since the dialog has been closed, return FALSE so that we exit the 
	//  application, rather than start the application's message pump. 
	ReleaseMutex(hOnlyInstance); 
	if(ProcInfo.hProcess) 
	{ 
		DWORD ExitCode=0; 
		GetExitCodeProcess(ProcInfo.hProcess,&ExitCode); 
		if(STILL_ACTIVE == ExitCode) 
		{ 
			TerminateProcess(ProcInfo.hProcess,-1); 
			ExitCode=GetLastError(); 
			 
		} 
	} 
	return FALSE; 
} 
 
BOOL CCirMMIApp::PreTranslateMessage(MSG* pMsg)  
{ 
	// TODO: Add your specialized code here and/or call the base class 
	if(pMsg->message == WM_KEYDOWN ) 
	{ 
		if (pMsg->wParam==VK_ESCAPE) 
		{ 
			::PostQuitMessage(0); 
			//return FALSE; 
		}		 
	}	 
	return CWinApp::PreTranslateMessage(pMsg); 
} 
 
int CCirMMIApp::ExitInstance()  
{ 
	 
	return CWinApp::ExitInstance(); 
} 
 
void CCirMMIApp::SetDialogBkColor(COLORREF clrCtlBk, COLORREF clrCtlText) 
{ 
	CWinApp::SetDialogBkColor(clrCtlBk,clrCtlText); 
 
}