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


#include "stdafx.h" 
#include "common.h" 
#include ".\share\gpsheader.h" 
 
 
//定义全局公共变量 
Global_Common_Variable g_CommonSet; 
 
//综合信息 
INTEGRATION_INFO g_IntegrationInfo; 
 
//gps info 
GPSLOADINFO g_GpsInfo; 
CallKeyItem g_CallKeyItem[9]; 
 
 
CPtrList g_PhoneBookList; //电话本 
CPtrList g_RoadBookList;	//线路信息 
 
//设置选项 
INT g_WhoSetting; 
Setting_Color g_SettingColor; 
 
 
mutecontrol  g_waveC; 
 
void InitGlobalSet() 
{ 
 
	//memset(&g_CommonSet,0,sizeof(g_CommonSet)); 
 
	if(g_CommonSet.pBrButtonBrightBk) 
		delete g_CommonSet.pBrButtonBrightBk; 
	g_CommonSet.pBrButtonBrightBk=new CBrush(g_CommonSet.crButtonBrightBk); 
 
	if(g_CommonSet.pBrButtonDarkBk) 
		delete g_CommonSet.pBrButtonDarkBk; 
	g_CommonSet.pBrButtonDarkBk=new CBrush(g_CommonSet.crButtonDarkBk); 
 
	if(g_CommonSet.pBrListBox) 
		delete g_CommonSet.pBrListBox; 
	g_CommonSet.pBrListBox=new CBrush(g_CommonSet.crMainBk); 
	 
	if(g_CommonSet.pBrFrameBorder) 
		delete g_CommonSet.pBrFrameBorder; 
	g_CommonSet.pBrFrameBorder=new CBrush(RGB(200,200,0)); 
 
	if(g_CommonSet.pPenButtonBrightText) 
		delete g_CommonSet.pPenButtonBrightText; 
	g_CommonSet.pPenButtonBrightText=new CPen(PS_SOLID,1,g_CommonSet.crButtonBrightText); 
 
	if(	g_CommonSet.pPenButtonDardText) 
		delete 	g_CommonSet.pPenButtonDardText; 
	g_CommonSet.pPenButtonDardText=new CPen(PS_SOLID,1,g_CommonSet.crButtonDarkText); 
 
 
	if(g_CommonSet.pFontItalicTitle) 
		delete g_CommonSet.pFontItalicTitle; 
	 
	g_CommonSet.pFontItalicTitle=new CFont(); 
	g_CommonSet.pFontItalicTitle->CreateFont 
		(-20,0, 
		0, 
		0, 
		600, 
		1, 
		0, 
		0, 
		DEFAULT_CHARSET, 
		2, 
		3, 
		DEFAULT_QUALITY, 
		49, 
		_T("宋体") 
		); 
 
	 
	if(g_CommonSet.pFontTitle) 
		delete g_CommonSet.pFontTitle; 
	 
	LOGFONT lf; 
	g_CommonSet.pFontTitle=new CFont; 
	g_CommonSet.pFontItalicTitle->GetLogFont(&lf); 
	lf.lfItalic=0; 
	lf.lfHeight=-18; 
	lf.lfWeight=600; 
	g_CommonSet.pFontTitle->CreateFontIndirect(&lf); 
 
 
	if(g_CommonSet.pFontButton) 
		delete g_CommonSet.pFontButton; 
 
	g_CommonSet.pFontButton=new CFont; 
	g_CommonSet.pFontButton->CreateFont 
		( 
		12,0, 
		0, 
		0, 
		500, 
		0, 
		0, 
		0, 
		DEFAULT_CHARSET, 
		2, 
		3, 
		DEFAULT_QUALITY, 
		49, 
		_T("宋体") 
		); 
 
	if(g_CommonSet.pFontTrainTail) 
		delete g_CommonSet.pFontTrainTail; 
	 
	g_CommonSet.pFontTrainTail=new CFont; 
	g_CommonSet.pFontTrainTail->CreateFont( 
		14,0, 
		0, 
		0, 
		400, 
		0, 
		0, 
		0, 
		DEFAULT_CHARSET, 
		2, 
		3, 
		DEFAULT_QUALITY, 
		49, 
		_T("宋体")); 
 
	if(g_CommonSet.pFontList) 
		delete g_CommonSet.pFontList; 
	 
	g_CommonSet.pFontList=new CFont; 
	g_CommonSet.pFontList->CreateFont(	 
		-16, 
		0, 
		0, 
		0, 
		550, 
		0, 
		0, 
		0, 
		DEFAULT_CHARSET, 
		2, 
		3, 
		DEFAULT_QUALITY, 
		49, 
		_T("宋体")); 
 
	if(g_CommonSet.pFontRunning) 
		delete g_CommonSet.pFontRunning; 
	 
	g_CommonSet.pFontRunning=new CFont; 
	g_CommonSet.pFontRunning->CreateFont( 
		-14, 
		0, 
		0, 
		0, 
		500, 
		0, 
		0, 
		0, 
		DEFAULT_CHARSET, 
		2, 
		3, 
		DEFAULT_QUALITY, 
		49, 
		_T("宋体")); 
 
	if(g_CommonSet.pFontPoint) 
		delete g_CommonSet.pFontPoint; 
	g_CommonSet.pFontPoint=new CFont;  //用于指示 
	g_CommonSet.pFontPoint->CreateFont( 
		-15, 
		0, 
		0, 
		0, 
		500, 
		0, 
		0, 
		0, 
		DEFAULT_CHARSET, 
		2, 
		3, 
		DEFAULT_QUALITY, 
		49, 
		_T("宋体")); 
 
 
	g_CallKeyItem[0].strName=L"前方调度"; 
	g_CallKeyItem[0].cbtype=1; 
	g_CallKeyItem[0].strNum=L"71613002"; 
 
	g_CallKeyItem[1].strName=L"调度"; 
	g_CallKeyItem[1].cbtype=1; 
	g_CallKeyItem[1].strNum=L"1200"; 
 
	g_CallKeyItem[2].strName=L"前站"; 
	g_CallKeyItem[2].cbtype=1; 
	g_CallKeyItem[2].strNum=L"70012002"; 
	 
	g_CallKeyItem[3].strName=L"本站"; 
	g_CallKeyItem[3].cbtype=1; 
	g_CallKeyItem[3].strNum=L"1300"; 
	 
	g_CallKeyItem[4].strName=L"后站"; 
	g_CallKeyItem[4].cbtype=1; 
	g_CallKeyItem[4].strNum=L"70013002"; 
	 
	g_CallKeyItem[5].strName=L"车长"; 
	g_CallKeyItem[5].cbtype=3; 
	g_CallKeyItem[5].strNum=L""; 
 
	g_CallKeyItem[6].strName=L"邻站组呼"; 
	g_CallKeyItem[6].cbtype=2; 
	g_CallKeyItem[6].cbPri='2'; 
	g_CallKeyItem[6].strNum=L"211"; 
	 
	g_CallKeyItem[7].strName=L"站内组呼"; 
	g_CallKeyItem[7].cbtype=2; 
	g_CallKeyItem[7].cbPri='3'; 
	g_CallKeyItem[7].strNum=L"210"; 
	 
	g_CallKeyItem[8].strName=L"紧急"; 
	g_CallKeyItem[8].cbtype=2; 
	g_CallKeyItem[8].cbPri='0'; 
	g_CallKeyItem[8].strNum=L"299";	 
 
} 
 
INT GetMMIPort() 
{ 
	return g_CommonSet.iMMIport; 
} 
INT GetMMIState() 
{ 
	return g_CommonSet.iMMIState; 
} 
 
INT GetWorkMode() 
{ 
	return g_CommonSet.iWorkMode; 
} 
 
INT GetUIMode() 
{ 
	return g_CommonSet.iWitchUI; 
} 
INT GetWorkModeNum() 
{ 
	return g_CommonSet.iWorkModeNum; 
} 
 
 
INT GetWorkModeByNum(BYTE cbNum) 
{ 
	BOOL hi=cbNum & 0x80; 
	if(hi) 
	{ 
		if(cbNum>=0x81 && cbNum<=0xe4) 
			return MODE_BOTH; 
	} 
	else 
	{ 
		 
		if(cbNum==GSMR_MODENUM_VALUE) 
			return MODE_GSMR; 
		if(cbNum>=M450_MODENUM_VALUE_MIN && cbNum<=M450_MODENUM_VALUE_MAX) 
			return MODE_450M; 
 
	} 
 
	//... 
	return MODE_BOTH; 
} 
 
INT GetRows(const CString& str) 
{ 
	INT row=1; 
	int len=str.GetLength(); 
	for(int i=0;iUNICODE 
	iSize=7; 
	iSize=ANSIS_UNICODES((CHAR*)FromAcsii.train_sn, ToUnicode.train_sn, iSize); 
	//机车号,原来是ASCII码->UNICODE 
	iSize=8; 
	iSize=ANSIS_UNICODES((CHAR*)FromAcsii.train_id, ToUnicode.train_id, iSize); 
	//?,不必转换 
	ToUnicode.cmder_num= FromAcsii.cmder_num; 
	//命令编号,原来是ASCII码->UNICODE 
	iSize=6; 
	iSize=ANSIS_UNICODES((CHAR*)FromAcsii.tran_command_num, ToUnicode.tran_command_num, iSize); 
	//调度员姓名 
	iSize=8; 
	iSize=ANSIS_UNICODES((CHAR*)FromAcsii.tran_name, ToUnicode.tran_name, iSize); 
	//命令状态 
	ToUnicode.cmd_state= FromAcsii.cmd_state; 
	//总包数和本包序号 
	ToUnicode.sum_pg= FromAcsii.sum_pg; 
	ToUnicode.cur_pg= FromAcsii.cur_pg; 
	//调度命令正文 
	if(FromAcsii.ptext && FromAcsii.ptext->m_pData) 
	{ 
		iSize=FromAcsii.ptext->m_slen; 
		 
		ToUnicode.ptext=new TCHAR[iSize+32]; 
		memset(ToUnicode.ptext, 0, (iSize+32)*sizeof(TCHAR)); 
		int iReturn= ANSIS_UNICODES((CHAR*)FromAcsii.ptext->m_pData, ToUnicode.ptext, iSize); 
	} 
	// 
	return TRUE; 
} 
 
 
BOOL  BulidIIFrame(const BYTE *data,INT ilen,INTEGRATION_INFO &ii) 
{ 
 
	if(ilen<20) 
		return FALSE; 
 
	INT size=(DWORD)&ii.RunningLen - (DWORD)ⅈ 
	memcpy(&ii,data,size); 
	 
	CMySplit ms((char*)data+size,ilen-size); 
 
	int cnt=ms.GetSize(); //cnt==3 
 
	if(3!=cnt) 
	{ 
	return FALSE; 
	} 
 
	const MyData *p=ms.GetAt(0); 
	ii.RunningLen=p->_ilen; 
	if(ii.RunningLen>0) 
	{ 
		memcpy(ii.Running,p->_data,ii.RunningLen); 
	} 
	p=ms.GetAt(1); 
	ii.TrainIDLen=p->_ilen; 
	if(ii.TrainIDLen>0) 
	{ 
		memcpy(ii.TrainID,p->_data,ii.TrainIDLen); 
	} 
 
	p=ms.GetAt(2); 
	ii.LineNameLen=p->_ilen; 
	if(ii.LineNameLen>0) 
	{ 
		memcpy(ii.LineName,p->_data,ii.LineNameLen); 
	} 
 
	return TRUE; 
	 
 
} 
 
 
 
 
struct Sn_Frequency  
{ 
	INT sn; 
	TCHAR szSn[32]; 
}g_Ftable[]= 
{ 
0,L"未知频点", 
1,L"457.500MHz" , 
2,L"457.550MHz", 
3,L"457.700MHz", 
4,L"457.825MHz", 
5,L"457.925MHz", 
6,L"458.000MHz",   
7,L"458.200MHz", 
8,L"458.250MHz", 
9,L"457.500MHz", 
10,L"457.550MHz", 
11,L"457.700MHz",   
12,L"457.825MHz",   
13,L"457.925MHz", 
14,L"458.000MHz",   
15,L"458.200MHz", 
16,L"458.250MHz", 
17,L"457.500MHz",   
18,L"457.550MHz", 
19,L"457.700MHz",   
20,L"457.825MHz",   
21,L"457.925MHz", 
22,L"458.000MHz",   
23,L"458.200MHz", 
24,L"458.250MHz", 
25,L"457.700MHz",   
26,L"457.700MHz", 
}; 
 
//根据模式号得到频点 
CString GetFBySn(BYTE sn) 
{ 
	//if(sn==101) 
	if(sn==101) 
		return _T("GSM-R"); 
	else if(sn>=sizeof(g_Ftable)/sizeof(g_Ftable[0])) 
	{ 
		if(0!= (sn&0x80))//最高位为1 
		{ 
			return _T("GSM-R+")+GetFBySn(sn&0x7f); 
		} 
		else 
		{ 
			return _T("未知频点"); 
		} 
	} 
	else 
		return g_Ftable[sn].szSn; 
 
} 
 
//根据机车号的前4字符型数字,返回车型符号 
CString GetTrainTypeByID(const BYTE* pData, INT iLength) 
{ 
	CString strID; 
	unsigned int iID = 0; 
	for(INT iTemp= 0; iTemp<3 && iTemp< iLength; iTemp++) 
	{ 
		strID += (TCHAR)pData[iTemp]; 
		iID = (iID *10 +(int)pData[iTemp] -0x30); 
 
	} 
	if(iTemp <3) 
		return strID; 
 
//	for(int i = 0;i<(sizeof TrainNum /sizeof TrainNum[0]) ;i++) 
	for(int i = 0;i<(sizeof TrainNameCollate / sizeof TrainNameCollate[0]);i++) 
	{ 
		if(iID == TrainNameCollate[i].num ) 
		{ 
			return TrainNameCollate[i].type; 
		} 
	} 
	strID.Format(_T("XXX")); 
	return strID; 
 
} 
 
// 
CString GetTrainTypeByID(CString strIn) 
{ 
	CString strID; 
	unsigned int iID = 0; 
	for(int i = 0;i<3;i++) 
	{ 
		iID = (iID*10 +strIn[i]-0x30); 
	} 
 
	strID= strIn.Left(3); 
 
	if(i <3) 
		return strID; 
 
	for(i = 0;i<(sizeof TrainNameCollate / sizeof TrainNameCollate[0]) ;i++) 
	{ 
		if(iID == TrainNameCollate[i].num ) 
		{ 
			return TrainNameCollate[i].type; 
		} 
	} 
 
	TRACE(L"\nCString GetTrainTypeByID(CString strIn) strID = %s\n",strID); 
	return strID;	 
} 
 
 
UINT GetValueByStr(const CString& str) 
{ 
	UINT value=0; 
	CString tmp(str); 
	int len=str.GetLength(); 
	TCHAR ch; 
	for(int i=0;i='0' && ch<='9') 
			break; 
		else 
		{ 
		tmp=str.Mid(i+1); 
		} 
	} 
 
	len=tmp.GetLength(); 
	for(i=0;i='0' && ch<='9') 
			value=value*10+(ch-'0'); 
		else 
			break; 
	} 
	value=min((UINT)value,(unsigned int)-1); 
	return value; 
	 
} 
 
 
 
/////////////////////////////////////////////////////////////////////////////////// 
//车次号,机车号<-->车次功能号,机车功能号 
#define  TFN_MAX	5 
#define EFN_MAX		5 
/////////////////////////////////////////////////////////////////////////////////// 
//车次号,机车号<-->车次功能号,机车功能号 
 
UINT GetBinaryByStr(const CString& str) 
{ 
	UINT value=0; 
	CString tmp(str); 
	int len=str.GetLength(); 
	TCHAR ch; 
	for(int i=0;i='0' && ch<='9') 
			break; 
		else 
		{ 
		tmp=str.Mid(i+1); 
		} 
	} 
 
	len=tmp.GetLength(); 
	for(i=0;i='0' && ch<='9') 
			value=value*10+(ch-'0'); 
		else 
			break; 
	} 
	value=min((UINT)value,(unsigned int)-1); 
	return value; 
	 
} 
 
 
//05-06-28 ADD 
CString GetTFNByFRN(const CString &strTRN) 
{ 
 
 
	int len=strTRN.GetLength(); 
	if(len>2) 
	{ 
		TCHAR ch; 
		ch=strTRN[0]; 
		ch=toupper(ch); 
		if(ch>='A' &&  ch <='Z') 
		{ 
			CString str; 
			TCHAR ch2=strTRN[1]; 
			ch2=toupper(ch2); 
			if(ch2>='A' &&  ch2 <='Z') 
			{ 
				str.Format(_T("%02d%02d"),ch,ch2); 
				return str+strTRN.Mid(2); 
 
			} 
			else 
			{ 
				str.Format(_T("00%02d"),ch); 
				return str+strTRN.Mid(1); 
			} 
			 
		} 
		else 
		{ 
			return _T("0000")+strTRN; 
		} 
 
 
	} 
	else 
		return _T("0000")+strTRN; 
 
	 
} 
 
 
BOOL TranTRNtoTFN(const CString& strTRN,CString& strTFN) 
{ 
 
	if(strTRN.IsEmpty()) 
		return FALSE; 
	 
	if ( 
		strTRN.Left(4)==_T("0862")/*北电*/ 
		&& strTRN.Right(2)==_T("01") 
		) 
	return FALSE; 
 
/*	UINT v=GetBinaryByTRN(strTRN); 
	if(0==v) 
		return FALSE; 
*/	 
 
 
CString newstrTRN; 
//newstrTRN.Format(_T("%u"),v); 
newstrTRN=GetTFNByFRN(strTRN); 
 
CString tmpstrhead(_T("0862")); 
CString tmpstrtail(_T("01")); 
 
strTFN=tmpstrhead+newstrTRN+tmpstrtail; 
return TRUE; 
} 
 
 
 
BOOL TranTFNtoTRN(const CString& strTFN,CString& strTRN) 
{ 
 
	CString strRet(strTFN); 
	CString tmpstrRet(strTFN); 
 
	if(tmpstrRet.Left(3)==_T("086") || tmpstrRet.Left(3)==_T("+86")) 
	{ 
		tmpstrRet=tmpstrRet.Mid(3); 
	} 
	if(tmpstrRet.Left(1)==_T("2") && tmpstrRet.Right(2)==_T("01")) 
	{ 
		tmpstrRet=tmpstrRet.Mid(1,tmpstrRet.GetLength()-1-2); 
	} 
 
	INT len=tmpstrRet.GetLength(); 
	if(len>4) 
	{ 
		if(tmpstrRet.Mid(0,4)!=_T("0000")) 
		{ 
			CHAR ch,ch2; 
			CHAR chh=(CHAR)tmpstrRet[0],chl=(CHAR)tmpstrRet[1]; 
			ch=(chh-'0')*10+(chl-'0'); 
			chh=(CHAR)tmpstrRet[2],chl=(CHAR)tmpstrRet[3]; 
			ch2=(chh-'0')*10+(chl-'0'); 
			BOOL bFlag=TRUE; 
			for(int i=4;i=3 ? 3 : 0; 
		for(int i=len;i3) 
	{ 
		CString str=newstrEFN.Left(3); 
		BOOL bFlag=TRUE; 
		for(int i=3;i2 && strTmpTFN.Right(2)==_T("01")) 
			{ 
				strTFN=strTmpTFN.Left(strTmpTFN.GetLength()-1); 
				strTFN+=_T("8"); 
			} 
 
		} 
 
	} 
	return strTFN; 
} 
 
 
 
 
#define  dim(x) (sizeof(x) /sizeof(x[0])) 
 
void FillPhoneRecord(CPtrList &Ptrlist) 
{ 
 
	CPhoneBook* pPB=NULL; 
	CPhoneBookRecord* pPBR=NULL; 
 
	//01. 北京铁路局 
	pPB=new CPhoneBook; 
	lstrcpy(pPB->szUnit,_T("01.北京铁路局")); 
	pPBR=new CPhoneBookRecord;	 
	 
	lstrcpy(pPBR->szName,_T("机务调度")); 
	lstrcpy(pPBR->szNum,_T("02226237678")); 
	pPBR->ct=1; 
	pPBR->pri=4; 
	pPB->PtrList.AddTail(pPBR);	 
	pPBR=new CPhoneBookRecord;	 
	lstrcpy(pPBR->szName,_T("电务调度")); 
	lstrcpy(pPBR->szNum,_T("02226237679")); 
	pPBR->ct=1; 
	pPBR->pri=4; 
	pPB->PtrList.AddTail(pPBR); 
	 
 
	pPBR=new CPhoneBookRecord;	 
	lstrcpy(pPBR->szName,_T("维修中心")); 
	lstrcpy(pPBR->szNum,_T("13302045409")); 
	pPBR->ct=1; 
	pPBR->pri=4; 
	pPB->PtrList.AddTail(pPBR); 
	Ptrlist.AddTail(pPB); 
 
	 
	//02.大同铁路局 
	pPB=new CPhoneBook; 
	lstrcpy(pPB->szUnit,_T("02.大同铁路局")); 
	Ptrlist.AddTail(pPB); 
 
	//03.哈尔滨铁路局 
	pPB=new CPhoneBook; 
	lstrcpy(pPB->szUnit,_T("03.哈尔滨铁路局")); 
	Ptrlist.AddTail(pPB); 
 
	//04.沈阳铁路局 
	pPB=new CPhoneBook; 
	lstrcpy(pPB->szUnit,_T("04.沈阳铁路局")); 
	Ptrlist.AddTail(pPB); 
 
	//05.呼和浩特铁路局 
	pPB=new CPhoneBook; 
	lstrcpy(pPB->szUnit,_T("05.呼和浩特铁路局")); 
	Ptrlist.AddTail(pPB); 
 
	//06.郑州铁路局 
	pPB=new CPhoneBook; 
	lstrcpy(pPB->szUnit,_T("06.郑州铁路局")); 
	Ptrlist.AddTail(pPB); 
 
	//07.济南铁路局 
	pPB=new CPhoneBook; 
	lstrcpy(pPB->szUnit,_T("07.济南铁路局")); 
	Ptrlist.AddTail(pPB); 
 
	//08.上海铁路局 
	pPB=new CPhoneBook; 
	lstrcpy(pPB->szUnit,_T("08.上海铁路局")); 
	Ptrlist.AddTail(pPB); 
 
	//09.西安铁路局 
	pPB=new CPhoneBook; 
	lstrcpy(pPB->szUnit,_T("09.西安铁路局")); 
	Ptrlist.AddTail(pPB); 
 
	//10.武汉铁路局 
	pPB=new CPhoneBook; 
	lstrcpy(pPB->szUnit,_T("10.武汉铁路局")); 
	Ptrlist.AddTail(pPB); 
 
 
	//11.成都铁路局 
	pPB=new CPhoneBook; 
	lstrcpy(pPB->szUnit,_T("11.成都铁路局")); 
	Ptrlist.AddTail(pPB); 
 
	//12.南昌铁路局 
	pPB=new CPhoneBook; 
	lstrcpy(pPB->szUnit,_T("12.南昌铁路局")); 
	Ptrlist.AddTail(pPB); 
	 
	//13.广铁(集团)公司 
	pPB=new CPhoneBook; 
	lstrcpy(pPB->szUnit,_T("13.广铁(集团)公司")); 
	Ptrlist.AddTail(pPB); 
 
	//14.柳州铁路局 
	pPB=new CPhoneBook; 
	lstrcpy(pPB->szUnit,_T("14.柳州铁路局")); 
	Ptrlist.AddTail(pPB); 
 
 
	//15.昆明铁路局 
	pPB=new CPhoneBook; 
	lstrcpy(pPB->szUnit,_T("15.昆明铁路局")); 
	Ptrlist.AddTail(pPB); 
 
	//16.兰州铁路局 
	pPB=new CPhoneBook; 
	lstrcpy(pPB->szUnit,_T("16.兰州铁路局")); 
	Ptrlist.AddTail(pPB); 
 
	//17.乌鲁木齐铁路局 
	pPB=new CPhoneBook; 
	lstrcpy(pPB->szUnit,_T("17.乌鲁木齐铁路局")); 
	Ptrlist.AddTail(pPB); 
 
	//18.青藏公司 
	pPB=new CPhoneBook; 
	lstrcpy(pPB->szUnit,_T("18.青藏公司")); 
	Ptrlist.AddTail(pPB); 
 
 
} 
 
void CreatePhoneBookRecord(HKEY hKey,CPtrList &ptrlist) 
{ 
 
	if(ptrlist.GetCount()<=0) 
		return ; 
	POSITION pos=ptrlist.GetHeadPosition(); 
	while(pos) 
	{ 
		CPhoneBook* pPB=(CPhoneBook*)ptrlist.GetNext(pos); 
		if(pPB && lstrlen(pPB->szUnit)>0) 
		{ 
				 
			DWORD dwDisposition;  
			HKEY hSubKey=NULL; 
			INT rc=::RegCreateKeyEx(hKey, pPB->szUnit, 0L, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hSubKey, &dwDisposition); 
			if(ERROR_SUCCESS == rc  &&  dwDisposition==REG_CREATED_NEW_KEY) //REG_CREATED_NEW_KEY  
			{ 
					if(pPB->PtrList.GetCount()>0) 
					{ 
						POSITION pos2=pPB->PtrList.GetHeadPosition(); 
						while(pos2) 
						{ 
							CPhoneBookRecord *pPBR=(CPhoneBookRecord *)pPB->PtrList.GetNext(pos2); 
							if(pPBR && lstrlen(pPBR->szName)>0) 
							{ 
								HKEY hSubKey2; 
								hSubKey2=NULL; 
								rc=::RegCreateKeyEx(hSubKey, pPBR->szName, 0L, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hSubKey2, &dwDisposition); 
								if(ERROR_SUCCESS==rc &&  dwDisposition==REG_CREATED_NEW_KEY) 
								{ 
									RegSetValueEx(hSubKey2, _T("num"), 0,REG_SZ,  (CONST BYTE*)pPBR->szNum,lstrlen(pPBR->szNum)*(sizeof TCHAR)); 
									RegSetValueEx(hSubKey2, _T("ct"), 0,REG_DWORD,  (CONST BYTE*)&pPBR->ct,sizeof pPBR->ct); 
									RegSetValueEx(hSubKey2, _T("pri"), 0,REG_DWORD,  (CONST BYTE*)&pPBR->pri,sizeof pPBR->pri);									 
 
								}								 
								if(hSubKey2) 
								{ 
										RegFlushKey(hSubKey2); 
										RegCloseKey(hSubKey2); 
								} 
							} 
 
						} 
					} 
			} 
			if(hSubKey) 
			{ 
				RegFlushKey(hSubKey); 
				RegCloseKey(hSubKey); 
			} 
		} 
	} 
 
} 
 
 
void FillRoadRecord(CPtrList &Ptrlist) 
{ 
 
	CRoadBook* pRB=NULL; 
	CRoadRecord* pRR=NULL; 
 
	//01. 北京铁路局 
	pRB=new CRoadBook; 
	lstrcpy(pRB->szName,_T("01.北京铁路局")); 
 
	pRR=new CRoadRecord;	 
	lstrcpy(pRR->szName,_T("01.区段一")); 
	pRR->mode=101; 
	pRB->PtrList.AddTail(pRR); 
	 
	pRR=new CRoadRecord;	 
	lstrcpy(pRR->szName,_T("02.区段二")); 
	pRR->mode=1; 
	pRB->PtrList.AddTail(pRR); 
 
	pRR=new CRoadRecord;	 
	lstrcpy(pRR->szName,_T("03.区段三")); 
	pRR->mode=2; 
	pRB->PtrList.AddTail(pRR); 
 
	pRR=new CRoadRecord;	 
	lstrcpy(pRR->szName,_T("04.区段四")); 
	pRR->mode=3; 
	pRB->PtrList.AddTail(pRR); 
 
	pRR=new CRoadRecord;	 
	lstrcpy(pRR->szName,_T("05.区段五")); 
	pRR->mode=4; 
	pRB->PtrList.AddTail(pRR); 
 
	pRR=new CRoadRecord;	 
	lstrcpy(pRR->szName,_T("06.区段六")); 
	pRR->mode=5; 
	pRB->PtrList.AddTail(pRR); 
 
	pRR=new CRoadRecord;	 
	lstrcpy(pRR->szName,_T("07.区段七")); 
	pRR->mode=6; 
	pRB->PtrList.AddTail(pRR); 
 
	pRR=new CRoadRecord;	 
	lstrcpy(pRR->szName,_T("08.区段八")); 
	pRR->mode=7; 
	pRB->PtrList.AddTail(pRR); 
 
 
	pRR=new CRoadRecord;	 
	lstrcpy(pRR->szName,_T("09.区段九")); 
	pRR->mode=8; 
	pRB->PtrList.AddTail(pRR); 
	 
	pRR=new CRoadRecord;	 
	lstrcpy(pRR->szName,_T("10.区段十")); 
	pRR->mode=9; 
	pRR->mode|=0x80; 
	pRB->PtrList.AddTail(pRR); 
 
	pRR=new CRoadRecord;	 
	lstrcpy(pRR->szName,_T("11.区段十一")); 
	pRR->mode=2; 
	pRR->mode|=0x80; 
	pRB->PtrList.AddTail(pRR); 
 
	pRR=new CRoadRecord;	 
	lstrcpy(pRR->szName,_T("12.区段十二")); 
	pRR->mode=3; 
	pRR->mode|=0x80; 
	pRB->PtrList.AddTail(pRR); 
 
	pRR=new CRoadRecord;	 
	lstrcpy(pRR->szName,_T("13.区段十三")); 
	pRR->mode=4; 
	pRR->mode|=0x80; 
	pRB->PtrList.AddTail(pRR); 
 
	pRR=new CRoadRecord;	 
	lstrcpy(pRR->szName,_T("14.区段十四")); 
	pRR->mode=5; 
	pRR->mode|=0x80; 
	pRB->PtrList.AddTail(pRR); 
 
	pRR=new CRoadRecord;	 
	lstrcpy(pRR->szName,_T("15.区段十五")); 
	pRR->mode=6; 
	pRR->mode|=0x80; 
	pRB->PtrList.AddTail(pRR); 
 
	pRR=new CRoadRecord;	 
	lstrcpy(pRR->szName,_T("16.区段十六")); 
	pRR->mode=7; 
	pRR->mode|=0x80; 
	pRB->PtrList.AddTail(pRR); 
 
 
 
	Ptrlist.AddTail(pRB); 
		 
	 
	//02.大同铁路局 
	pRB=new CRoadBook; 
	lstrcpy(pRB->szName,_T("02.大同铁路局")); 
	Ptrlist.AddTail(pRB); 
 
	//03.哈尔滨铁路局 
	pRB=new CRoadBook; 
	lstrcpy(pRB->szName,_T("03.哈尔滨铁路局")); 
	Ptrlist.AddTail(pRB); 
 
	//04.沈阳铁路局 
	pRB=new CRoadBook; 
	lstrcpy(pRB->szName,_T("04.沈阳铁路局")); 
	Ptrlist.AddTail(pRB); 
 
	//05.呼和浩特铁路局 
	pRB=new CRoadBook; 
	lstrcpy(pRB->szName,_T("05.呼和浩特铁路局")); 
	Ptrlist.AddTail(pRB); 
 
	//06.郑州铁路局 
	pRB=new CRoadBook; 
	lstrcpy(pRB->szName,_T("06.郑州铁路局")); 
	Ptrlist.AddTail(pRB); 
 
	//07.济南铁路局 
	pRB=new CRoadBook; 
	lstrcpy(pRB->szName,_T("07.济南铁路局")); 
	Ptrlist.AddTail(pRB); 
 
	//08.上海铁路局 
	pRB=new CRoadBook; 
	lstrcpy(pRB->szName,_T("08.上海铁路局")); 
	Ptrlist.AddTail(pRB); 
 
	//09.西安铁路局 
	pRB=new CRoadBook; 
	lstrcpy(pRB->szName,_T("09.西安铁路局")); 
	Ptrlist.AddTail(pRB); 
 
	//10.武汉铁路局 
	pRB=new CRoadBook; 
	lstrcpy(pRB->szName,_T("10.武汉铁路局")); 
	Ptrlist.AddTail(pRB); 
 
 
	//11.成都铁路局 
	pRB=new CRoadBook; 
	lstrcpy(pRB->szName,_T("11.成都铁路局")); 
	Ptrlist.AddTail(pRB); 
 
	//12.南昌铁路局 
	pRB=new CRoadBook; 
	lstrcpy(pRB->szName,_T("12.南昌铁路局")); 
	Ptrlist.AddTail(pRB); 
	 
	//13.广铁(集团)公司 
	pRB=new CRoadBook; 
	lstrcpy(pRB->szName,_T("13.广铁(集团)公司")); 
	Ptrlist.AddTail(pRB); 
 
	//14.柳州铁路局 
	pRB=new CRoadBook; 
	lstrcpy(pRB->szName,_T("14.柳州铁路局")); 
	Ptrlist.AddTail(pRB); 
 
 
	//15.昆明铁路局 
	pRB=new CRoadBook; 
	lstrcpy(pRB->szName,_T("15.昆明铁路局")); 
	Ptrlist.AddTail(pRB); 
 
	//16.兰州铁路局 
	pRB=new CRoadBook; 
	lstrcpy(pRB->szName,_T("16.兰州铁路局")); 
	Ptrlist.AddTail(pRB); 
 
	//17.乌鲁木齐铁路局 
	pRB=new CRoadBook; 
	lstrcpy(pRB->szName,_T("17.乌鲁木齐铁路局")); 
	Ptrlist.AddTail(pRB); 
 
	//18.青藏公司 
	pRB=new CRoadBook; 
	lstrcpy(pRB->szName,_T("18.青藏公司")); 
	Ptrlist.AddTail(pRB); 
 
 
} 
 
void CreateRoadBookRecord(HKEY hKey,CPtrList &ptrlist) 
{ 
 
	if(ptrlist.GetCount()<=0) 
		return ; 
	POSITION pos=ptrlist.GetHeadPosition(); 
	while(pos) 
	{ 
		CRoadBook* pRB=(CRoadBook*)ptrlist.GetNext(pos); 
		if(pRB && lstrlen(pRB->szName)>0) 
		{ 
				 
			DWORD dwDisposition;  
			HKEY hSubKey=NULL; 
			INT rc=::RegCreateKeyEx(hKey, pRB->szName, 0L, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hSubKey, &dwDisposition); 
			if(ERROR_SUCCESS == rc  &&  dwDisposition==REG_CREATED_NEW_KEY) //REG_CREATED_NEW_KEY  
			{ 
					if(pRB->PtrList.GetCount()>0) 
					{ 
						POSITION pos2=pRB->PtrList.GetHeadPosition(); 
						while(pos2) 
						{ 
							CRoadRecord *pRR=(CRoadRecord*)pRB->PtrList.GetNext(pos2); 
							if(pRR && lstrlen(pRR->szName)>0) 
							{ 
								HKEY hSubKey2; 
								hSubKey2=NULL; 
								rc=::RegCreateKeyEx(hSubKey, pRR->szName, 0L, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hSubKey2, &dwDisposition); 
								if(ERROR_SUCCESS==rc &&  dwDisposition==REG_CREATED_NEW_KEY) 
								{ 
									RegSetValueEx(hSubKey2, _T("line"), 0,REG_SZ,  (CONST BYTE*)pRR->szName,lstrlen(pRR->szName)*(sizeof TCHAR)); 
									RegSetValueEx(hSubKey2, _T("mode"), 0,REG_DWORD,  (CONST BYTE*)&pRR->mode,sizeof pRR->mode);																	 
 
								}								 
								if(hSubKey2) 
								{ 
										//RegFlushKey(hSubKey2); 
										RegCloseKey(hSubKey2); 
								} 
							} 
 
						} 
					} 
			} 
			if(hSubKey) 
			{ 
				RegFlushKey(hSubKey); 
				RegCloseKey(hSubKey); 
			} 
		} 
	} 
 
} 
 
 
BOOL LoadSetting() 
{ 
 
	DWORD cbData=0; 
	HKEY hKey=NULL; 
	HKEY hSubKey=NULL; 
	DWORD dwDisposition; //REG_CREATED_NEW_KEY 
	::RegCreateKeyEx(HKEY_LOCAL_MACHINE, _T("Software\\tcb-mobile\\gsmr-mmi"), 0L, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hKey, &dwDisposition); 
 
 
	if( dwDisposition==REG_CREATED_NEW_KEY) //REG_CREATED_NEW_KEY  
	{	 
		 
		//main setting 
		RegSetValueEx(hKey,_T("maintain-pwd"),NULL,REG_SZ,(BYTE*)g_CommonSet.strUserPwd.GetBuffer(0),g_CommonSet.strUserPwd.GetLength()*sizeof (TCHAR));				 
		RegSetValueEx(hKey,_T("start-svrname"),NULL,REG_SZ,(BYTE*)g_CommonSet.strSvrName.GetBuffer(0),g_CommonSet.strSvrName.GetLength()*sizeof (TCHAR));				 
			 
		dwDisposition=0; 
		//init shortcut-call setting			 
		if(ERROR_SUCCESS==::RegCreateKeyEx(hKey, _T("call-shortcut"), 0L, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hSubKey, &dwDisposition)) 
		{ 
			 
			RegSetValueEx(hSubKey,_T("front-dis"),NULL,REG_SZ,(BYTE*)g_CallKeyItem[0].strNum.GetBuffer(0),g_CallKeyItem[0].strNum.GetLength()*sizeof (TCHAR));				 
			 
			RegSetValueEx(hSubKey,_T("dis"),NULL,REG_SZ,(BYTE*)g_CallKeyItem[1].strNum.GetBuffer(0),g_CallKeyItem[1].strNum.GetLength()*sizeof (TCHAR)); 
			 
			RegSetValueEx(hSubKey,_T("front-sta"),NULL,REG_SZ,(BYTE*)g_CallKeyItem[2].strNum.GetBuffer(0),g_CallKeyItem[2].strNum.GetLength()*sizeof (TCHAR)); 
				 
			RegSetValueEx(hSubKey,_T("cur-sta"),NULL,REG_SZ,(BYTE*)g_CallKeyItem[3].strNum.GetBuffer(0),g_CallKeyItem[3].strNum.GetLength()*sizeof (TCHAR)); 
			 
			RegSetValueEx(hSubKey,_T("behind-sta"),NULL,REG_SZ,(BYTE*)g_CallKeyItem[4].strNum.GetBuffer(0),g_CallKeyItem[4].strNum.GetLength()*sizeof (TCHAR)); 
			 
			RegSetValueEx(hSubKey,_T("chief"),NULL,REG_SZ,(BYTE*)g_CallKeyItem[5].strNum.GetBuffer(0),g_CallKeyItem[5].strNum.GetLength()*sizeof (TCHAR)); 
			 
			RegSetValueEx(hSubKey,_T("beside-sta"),NULL,REG_SZ,(BYTE*)g_CallKeyItem[6].strNum.GetBuffer(0),g_CallKeyItem[6].strNum.GetLength()*sizeof (TCHAR)); 
			 
			RegSetValueEx(hSubKey,_T("inside-sta"),NULL,REG_SZ,(BYTE*)g_CallKeyItem[7].strNum.GetBuffer(0),g_CallKeyItem[7].strNum.GetLength()*sizeof (TCHAR)); 
 
			RegSetValueEx(hSubKey,_T("alarm-call"),NULL,REG_SZ,(BYTE*)g_CallKeyItem[8].strNum.GetBuffer(0),g_CallKeyItem[8].strNum.GetLength()*sizeof (TCHAR)); 
				 
				 
			if(hSubKey) 
			{ 
				RegFlushKey(hSubKey); 
				::RegCloseKey(hSubKey); 
				hSubKey=NULL; 
			} 
		} 
		 
		dwDisposition=0; 
		if(ERROR_SUCCESS==::RegCreateKeyEx(hKey, _T("phonebook"), 0L, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hSubKey, &dwDisposition)) 
		{ 
			//RegFlushKey(hKey); 
			//if(hKey) RegCloseKey(hKey); 
 
			if(dwDisposition==REG_CREATED_NEW_KEY) 
			{	 
				FillPhoneRecord(g_PhoneBookList); 
				CreatePhoneBookRecord(hSubKey,g_PhoneBookList); 
				RegFlushKey(hSubKey); 
				if(hSubKey)  
				{ 
					RegCloseKey(hSubKey); 
				hSubKey=NULL; 
				} 
				 
			} 
			 
		} 
		 
	 
		dwDisposition=0; 
		if(ERROR_SUCCESS==::RegCreateKeyEx(hKey, _T("roadbook"), 0L, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hSubKey, &dwDisposition)) 
		{ 
			//RegFlushKey(hKey); 
			//if(hKey) RegCloseKey(hKey); 
			if(dwDisposition==REG_CREATED_NEW_KEY) 
			{	 
				FillRoadRecord(g_RoadBookList); 
				CreateRoadBookRecord(hSubKey,g_RoadBookList); 
				RegFlushKey(hSubKey); 
				if(hSubKey) 
				{ 
					RegCloseKey(hSubKey); 
					hSubKey=NULL; 
				} 
				 
			} 
			else 
			{ 
				FillRoadRecord(g_RoadBookList); 
			} 
			 
		} 
 
		if(hKey) 
		{ 
		RegFlushKey(hKey); 
		if(hKey) RegCloseKey(hKey); 
		} 
		return FALSE; 
				 
	} 
	else //REG_OPENED_EXISTING_KEY 
	{ 
		//load Main setting 
		{			 
			INT rc; 
			DWORD dwDSize; 
			DWORD dwType=0; 
			TCHAR szData[MAX_PATH]; 
			dwDSize=dim(szData); 
			ZeroMemory(szData,sizeof(szData)); 
			rc=RegQueryValueEx(hKey,_T("maintain-pwd"),NULL,&dwType,(BYTE*)&szData,&dwDSize); 
			if(ERROR_SUCCESS==rc && dwDSize>0 && dwType==REG_SZ) 
			{ 
				g_CommonSet.strUserPwd=szData; 
			} 
			 
			dwType=REG_NONE; 
			ZeroMemory(szData,sizeof(szData)); 
			rc=RegQueryValueEx(hSubKey,_T("start-svrname"),NULL,&dwType,(BYTE*)&szData,&dwDSize); 
			if(ERROR_SUCCESS==rc && dwDSize>0 && dwType==REG_SZ) 
			{ 
				g_CommonSet.strSvrName=szData;	 
			}	 
			 
 
		} 
		//load shortcut-call setting 
		 
		if(ERROR_SUCCESS==::RegOpenKeyEx(hKey,_T("call-shortcut"),0,KEY_ALL_ACCESS,&hSubKey)) 
		{ 
			 
			INT rc; 
			DWORD dwDSize; 
			DWORD dwType=REG_NONE; 
			TCHAR szData[256]; 
			dwDSize=dim(szData); 
			ZeroMemory(szData,sizeof(szData)); 
			rc=RegQueryValueEx(hSubKey,_T("front-dis"),NULL,&dwType,(BYTE*)&szData,&dwDSize); 
			if(ERROR_SUCCESS==rc && dwDSize>0 && dwType==REG_SZ) 
			{ 
				g_CallKeyItem[0].strNum=szData;	 
			}	 
			ZeroMemory(szData,sizeof(szData)); 
			rc=RegQueryValueEx(hSubKey,_T("dis"),NULL,&dwType,(BYTE*)&szData,&dwDSize); 
			if(ERROR_SUCCESS==rc && dwDSize>0 && dwType==REG_SZ) 
			{ 
				g_CallKeyItem[1].strNum=szData;	 
			} 
			ZeroMemory(szData,sizeof(szData)); 
			rc=RegQueryValueEx(hSubKey,_T("front-sta"),NULL,&dwType,(BYTE*)&szData,&dwDSize); 
			if(ERROR_SUCCESS==rc && dwDSize>0 && dwType==REG_SZ) 
			{ 
				g_CallKeyItem[2].strNum=szData;	 
			} 
			ZeroMemory(szData,sizeof(szData)); 
			rc=RegQueryValueEx(hSubKey,_T("cur-sta"),NULL,&dwType,(BYTE*)&szData,&dwDSize); 
			if(ERROR_SUCCESS==rc && dwDSize>0 && dwType==REG_SZ) 
			{ 
				g_CallKeyItem[3].strNum=szData;	 
			} 
			ZeroMemory(szData,sizeof(szData)); 
			rc=RegQueryValueEx(hSubKey,_T("behind-sta"),NULL,&dwType,(BYTE*)&szData,&dwDSize); 
			if(ERROR_SUCCESS==rc && dwDSize>0 && dwType==REG_SZ) 
			{ 
				g_CallKeyItem[4].strNum=szData;	 
			} 
			ZeroMemory(szData,sizeof(szData)); 
			rc=RegQueryValueEx(hSubKey,_T("chief"),NULL,&dwType,(BYTE*)&szData,&dwDSize); 
			if(ERROR_SUCCESS==rc && dwDSize>0 && dwType==REG_SZ) 
			{ 
				g_CallKeyItem[5].strNum=szData;	 
			} 
			ZeroMemory(szData,sizeof(szData)); 
			rc=RegQueryValueEx(hSubKey,_T("beside-sta"),NULL,&dwType,(BYTE*)&szData,&dwDSize); 
			if(ERROR_SUCCESS==rc && dwDSize>0 && dwType==REG_SZ) 
			{ 
				g_CallKeyItem[6].strNum=szData;	 
			} 
			ZeroMemory(szData,sizeof(szData)); 
			rc=RegQueryValueEx(hSubKey,_T("inside-sta"),NULL,&dwType,(BYTE*)&szData,&dwDSize); 
			if(ERROR_SUCCESS==rc && dwDSize>0 && dwType==REG_SZ) 
			{ 
				g_CallKeyItem[7].strNum=szData;	 
			} 
			ZeroMemory(szData,sizeof(szData)); 
			rc=RegQueryValueEx(hSubKey,_T("alarm-call"),NULL,&dwType,(BYTE*)&szData,&dwDSize); 
			if(ERROR_SUCCESS==rc && dwDSize>0 && dwType==REG_SZ) 
			{ 
				g_CallKeyItem[8].strNum=szData;	 
			} 
			 
			 
			if(hSubKey) 
			{ 
				::RegCloseKey(hSubKey); 
				hSubKey=NULL; 
			} 
		} 
		else  
		{ 
			dwDisposition=0; 
 
			if(ERROR_SUCCESS==::RegCreateKeyEx(hKey, _T("call-shortcut"), 0L, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hSubKey, &dwDisposition)) 
			{ 
				 
				RegSetValueEx(hSubKey,_T("front-dis"),NULL,REG_SZ,(BYTE*)g_CallKeyItem[0].strNum.GetBuffer(0),g_CallKeyItem[0].strNum.GetLength()*sizeof (TCHAR));				 
				 
				RegSetValueEx(hSubKey,_T("dis"),NULL,REG_SZ,(BYTE*)g_CallKeyItem[1].strNum.GetBuffer(0),g_CallKeyItem[1].strNum.GetLength()*sizeof (TCHAR)); 
								 
				RegSetValueEx(hSubKey,_T("front-sta"),NULL,REG_SZ,(BYTE*)g_CallKeyItem[2].strNum.GetBuffer(0),g_CallKeyItem[2].strNum.GetLength()*sizeof (TCHAR)); 
				 
				RegSetValueEx(hSubKey,_T("cur-sta"),NULL,REG_SZ,(BYTE*)g_CallKeyItem[3].strNum.GetBuffer(0),g_CallKeyItem[3].strNum.GetLength()*sizeof (TCHAR)); 
				 
				RegSetValueEx(hSubKey,_T("behind-sta"),NULL,REG_SZ,(BYTE*)g_CallKeyItem[4].strNum.GetBuffer(0),g_CallKeyItem[4].strNum.GetLength()*sizeof (TCHAR)); 
				 
				RegSetValueEx(hSubKey,_T("chief"),NULL,REG_SZ,(BYTE*)g_CallKeyItem[5].strNum.GetBuffer(0),g_CallKeyItem[5].strNum.GetLength()*sizeof (TCHAR)); 
				 
				RegSetValueEx(hSubKey,_T("beside-sta"),NULL,REG_SZ,(BYTE*)g_CallKeyItem[6].strNum.GetBuffer(0),g_CallKeyItem[6].strNum.GetLength()*sizeof (TCHAR)); 
 
				RegSetValueEx(hSubKey,_T("inside-sta"),NULL,REG_SZ,(BYTE*)g_CallKeyItem[7].strNum.GetBuffer(0),g_CallKeyItem[7].strNum.GetLength()*sizeof (TCHAR)); 
				 
				RegSetValueEx(hSubKey,_T("alarm-call"),NULL,REG_SZ,(BYTE*)g_CallKeyItem[8].strNum.GetBuffer(0),g_CallKeyItem[8].strNum.GetLength()*sizeof (TCHAR)); 
				 
 
				 
				if(hSubKey) 
				{ 
					RegFlushKey(hSubKey); 
					::RegCloseKey(hSubKey); 
					hSubKey=NULL; 
				} 
			} 
 
		} 
		 
		 
		//load phone info 
		if(ERROR_SUCCESS==::RegOpenKeyEx(hKey,_T("phonebook"),0,KEY_ALL_ACCESS,&hSubKey)) 
		{				 
				INT nCnt,rc;				 
				DWORD dwNSize,dwCSize;				 
				FILETIME ft; 
				 
				TCHAR szName[256]; 
				dwNSize=dim(szName); 
				TCHAR szClass[256]; 
				dwCSize=dim(szClass); 
				nCnt=0;		 
				rc=::RegEnumKeyEx(hSubKey,nCnt,szName,&dwNSize,NULL,szClass,&dwCSize,&ft); 
				while (rc==ERROR_SUCCESS) 
				{ 
					TRACE(_T("%s\r\n"),szName); 
					CPhoneBook *pPB=new CPhoneBook ; 
					lstrcpy(pPB->szUnit,szName); 
 
					HKEY hSubKey2=NULL; 
					if(ERROR_SUCCESS==::RegOpenKeyEx(hSubKey,szName,0,KEY_ALL_ACCESS,&hSubKey2)) 
					{ 
						INT nCnt2,rc2; 
						DWORD dwNSize2,dwCSize2;				 
						FILETIME ft2;					 
						TCHAR szName2[256]; 
						TCHAR szClass2[256]; 
						dwNSize2=dim(szName2);					 
						dwCSize2=dim(szClass2); 
						nCnt2=0;						 
						rc2=::RegEnumKeyEx(hSubKey2,nCnt2,szName2,&dwNSize2,NULL,szClass2,&dwCSize2,&ft2); 
						while(rc2==ERROR_SUCCESS) 
						{ 
							TRACE(_T("  %s\r\n"),szName2);	 
							CPhoneBookRecord *pPBR=new CPhoneBookRecord;							 
							lstrcpy(pPBR->szName,szName2); 
							 
							HKEY hSubKey3=NULL; 
							INT rc3; 
							rc3=RegOpenKeyEx(hSubKey2,szName2,0,KEY_ALL_ACCESS,&hSubKey3); 
							if(rc3==ERROR_SUCCESS) 
							{ 
																 
								INT nCnt3=0,rc3; 
								DWORD dwNSize3,dwDSize,dwType; 
								TCHAR szName3[256]; 
								BYTE bData[1024];								 
								dwNSize3=dim(szName3); 
								dwDSize=dim(bData); 
 
								rc3=RegEnumValue(hSubKey3,nCnt3,szName3,&dwNSize3,NULL,&dwType,bData,&dwDSize); 
								while(rc3==ERROR_SUCCESS) 
								{ 
									TRACE(_T("    %s=%s\r\n"),szName3,(TCHAR*)bData); 
									 
									if(0==lstrcmp(szName3,_T("num"))) 
									{ 
										memset(pPBR->szNum,0,sizeof pPBR->szNum); 
										lstrcpy(pPBR->szNum,(TCHAR*)bData); 
 
									}else if(0==lstrcmp(szName3,_T("ct"))) 
									{ 
										pPBR->ct=*(DWORD*)bData; 
									}else if(0==lstrcmp(szName3,_T("pri"))) 
									{ 
										pPBR->pri=*(DWORD*)bData;	 
									} 
																			 
									 
									dwNSize3=dim(szName3); 
									dwDSize=dim(bData); 
									rc3=RegEnumValue(hSubKey3,++nCnt3,szName3,&dwNSize3,NULL,&dwType,bData,&dwDSize); 
								 
								}																 
 
							} 
							if(hSubKey3) 
								::RegCloseKey(hSubKey3); 
 
							pPB->PtrList.AddTail(pPBR); 
							 
							dwNSize2=dim(szName2); 
							dwCSize2=dim(szClass2); 
							rc2=::RegEnumKeyEx(hSubKey2,++nCnt2,szName2,&dwNSize2,NULL,szClass2,&dwCSize2,&ft2); 
						} 
					 
						 
					} 
					if(hSubKey2) 
						::RegCloseKey(hSubKey2); 
 
					g_PhoneBookList.AddTail(pPB); 
					 
					dwNSize=dim(szName); 
					dwCSize=dim(szClass); 
					rc=::RegEnumKeyEx(hSubKey,++nCnt,szName,&dwNSize,NULL,szClass,&dwCSize,&ft); 
				} 
 
				if(hSubKey)  
				{ 
					RegCloseKey(hSubKey); 
					hSubKey=NULL; 
				} 
 
		} 
		else 
		{ 
 
			dwDisposition=0; 
			if(ERROR_SUCCESS==::RegCreateKeyEx(hKey, _T("phonebook"), 0L, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hSubKey, &dwDisposition)) 
			{ 
				//RegFlushKey(hKey); 
				if(hKey) RegCloseKey(hKey); 
				if(dwDisposition==REG_CREATED_NEW_KEY) 
				{	 
					FillPhoneRecord(g_PhoneBookList); 
					CreatePhoneBookRecord(hSubKey,g_PhoneBookList); 
					RegFlushKey(hSubKey); 
					if(hSubKey) RegCloseKey(hSubKey); 
					 
				} 
				 
			} 
		} 
		//load road info 
		if(ERROR_SUCCESS==::RegOpenKeyEx(hKey,_T("roadbook"),0,KEY_ALL_ACCESS,&hSubKey)) 
		{ 
			 
 
				INT nCnt,rc;				 
				DWORD dwNSize,dwCSize;				 
				FILETIME ft; 
				 
				TCHAR szName[256]; 
				dwNSize=dim(szName); 
				TCHAR szClass[256]; 
				dwCSize=dim(szClass); 
				nCnt=0;		 
				rc=::RegEnumKeyEx(hSubKey,nCnt,szName,&dwNSize,NULL,szClass,&dwCSize,&ft); 
				while (rc==ERROR_SUCCESS) 
				{ 
					TRACE(_T("%s\r\n"),szName); 
					CRoadBook *pRB=new CRoadBook ; 
					lstrcpy(pRB->szName,szName); 
 
					HKEY hSubKey2=NULL; 
					if(ERROR_SUCCESS==::RegOpenKeyEx(hSubKey,szName,0,KEY_ALL_ACCESS,&hSubKey2)) 
					{ 
						INT nCnt2,rc2; 
						DWORD dwNSize2,dwCSize2;				 
						FILETIME ft2;					 
						TCHAR szName2[256]; 
						TCHAR szClass2[256]; 
						ZeroMemory(szName2,sizeof szName2); 
						dwNSize2=dim(szName2);					 
						dwCSize2=dim(szClass2); 
						nCnt2=0;						 
						rc2=::RegEnumKeyEx(hSubKey2,nCnt2,szName2,&dwNSize2,NULL,szClass2,&dwCSize2,&ft2); 
						while(rc2==ERROR_SUCCESS) 
						{ 
							TRACE(_T("  %s\r\n"),szName2);	 
							CRoadRecord *pRR=new CRoadRecord;		 
							 
							lstrcpy(pRR->szName,szName2); 
							 
							HKEY hSubKey3=NULL; 
							INT rc3; 
							rc3=RegOpenKeyEx(hSubKey2,szName2,0,KEY_ALL_ACCESS,&hSubKey3); 
							if(rc3==ERROR_SUCCESS) 
							{ 
																 
								INT nCnt3=0,rc3; 
								DWORD dwNSize3,dwDSize,dwType; 
								TCHAR szName3[256]; 
								BYTE bData[1024];								 
								dwNSize3=dim(szName3); 
								dwDSize=dim(bData); 
 
								ZeroMemory(szName3,sizeof szName3); 
								rc3=RegEnumValue(hSubKey3,nCnt3,szName3,&dwNSize3,NULL,&dwType,bData,&dwDSize); 
								while(rc3==ERROR_SUCCESS) 
								{ 
									TRACE(_T("    %s=%s\r\n"),szName3,(TCHAR*)bData); 
									 
									if(0==lstrcmp(szName3,_T("line"))) 
									{ 
										//lstrcpy(pRR->szName,(TCHAR*)bData); 
 
									}else if(0==lstrcmp(szName3,_T("mode"))) 
									{ 
										pRR->mode=*(BYTE*)bData; 
									} 
																												 
									dwNSize3=dim(szName3); 
									dwDSize=dim(bData); 
									rc3=RegEnumValue(hSubKey3,++nCnt3,szName3,&dwNSize3,NULL,&dwType,bData,&dwDSize); 
								 
								}																 
 
							} 
							if(hSubKey3) 
								::RegCloseKey(hSubKey3); 
 
							pRB->PtrList.AddTail(pRR); 
							 
							dwNSize2=dim(szName2); 
							dwCSize2=dim(szClass2); 
							rc2=::RegEnumKeyEx(hSubKey2,++nCnt2,szName2,&dwNSize2,NULL,szClass2,&dwCSize2,&ft2); 
						} 
					 
						 
					} 
					if(hSubKey2) 
						::RegCloseKey(hSubKey2); 
 
					g_RoadBookList.AddTail(pRB); 
					 
					dwNSize=dim(szName); 
					dwCSize=dim(szClass); 
					rc=::RegEnumKeyEx(hSubKey,++nCnt,szName,&dwNSize,NULL,szClass,&dwCSize,&ft); 
				} 
 
				if(hSubKey)  
				{ 
					RegCloseKey(hSubKey); 
					hSubKey=NULL; 
				} 
 
 
		} 
		else 
		{ 
			dwDisposition=0; 
			if(ERROR_SUCCESS==::RegCreateKeyEx(hKey, _T("roadbook"), 0L, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hSubKey, &dwDisposition)) 
			{ 
				//RegFlushKey(hKey); 
				//if(hKey) RegCloseKey(hKey); 
				if(dwDisposition==REG_CREATED_NEW_KEY) 
				{	 
					FillRoadRecord(g_RoadBookList); 
					CreateRoadBookRecord(hSubKey,g_RoadBookList); 
					RegFlushKey(hSubKey); 
					if(hSubKey) RegCloseKey(hSubKey); 
					 
				} 
				else 
				{ 
					FillRoadRecord(g_RoadBookList); 
				} 
				 
			} 
			 
			 
		} 
			 
		if(hKey) RegCloseKey(hKey); 
		return TRUE;	 
	} 
} 
 
 
void SetFTPKey() 
{ 
	INT rc; 
	HKEY hKey=NULL; 
	DWORD dwDisposition=0; //REG_CREATED_NEW_KEY 
	rc=::RegCreateKeyEx(HKEY_LOCAL_MACHINE, _T("Comm\\FTPD"), 0L, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hKey, &dwDisposition); 
	if(ERROR_SUCCESS==rc && dwDisposition!=REG_CREATED_NEW_KEY) 
	{ 
		BOOL bFlash=FALSE; 
		 
		DWORD dwDSize; 
		DWORD dwType; 
		TCHAR szData[MAX_PATH]; 
		 
		TCHAR DefDir[]=_T("\\"); 
		 
		dwType=REG_NONE; 
		dwDSize=dim(szData); 
		ZeroMemory(szData,sizeof(szData)); 
 
		rc=RegQueryValueEx(hKey,_T("DefaultDir"),NULL,&dwType,(BYTE*)&szData,&dwDSize); 
		if(ERROR_SUCCESS==rc && dwDSize>0 && dwType==REG_SZ) 
		{ 
			if(lstrcmp(DefDir,szData)!=0) 
			{ 
				bFlash=TRUE; 
				RegSetValueEx(hKey,_T("DefaultDir"),NULL,REG_SZ,(BYTE*)DefDir,lstrlen(DefDir)*sizeof(TCHAR));				 
			} 
			 
		} 
		 
		 
		DWORD enable=1; 
		 
		dwType=REG_NONE; 
		dwDSize=dim(szData); 
		ZeroMemory(szData,sizeof(szData)); 
 
		rc=RegQueryValueEx(hKey,_T("AllowAnonymous"),NULL,&dwType,(BYTE*)&szData,&dwDSize); 
		if(ERROR_SUCCESS==rc && dwDSize>0 && dwType==REG_DWORD) 
		{ 
			if(*(DWORD*)szData != 1) 
			{	 
				bFlash=TRUE; 
				RegSetValueEx(hKey,_T("AllowAnonymous"),NULL,REG_DWORD,(BYTE*)&enable,sizeof enable); 
			} 
		} 
		 
		dwType=REG_NONE; 
		dwDSize=dim(szData); 
		ZeroMemory(szData,sizeof(szData)); 
 
		rc=RegQueryValueEx(hKey,_T("AllowAnonymousUpload"),NULL,&dwType,(BYTE*)&szData,&dwDSize); 
		if(ERROR_SUCCESS==rc && dwDSize>0 && dwType==REG_DWORD) 
		{ 
			if(*(DWORD*)szData != 1) 
			{			 
				bFlash=TRUE; 
				RegSetValueEx(hKey,_T("AllowAnonymousUpload"),NULL,REG_DWORD,(BYTE*)&enable,sizeof enable);		 
			} 
		} 
		 
		dwType=REG_NONE; 
		dwDSize=dim(szData); 
		ZeroMemory(szData,sizeof(szData)); 
		rc=RegQueryValueEx(hKey,_T("AllowAnonymousVroots"),NULL,&dwType,(BYTE*)&szData,&dwDSize); 
		if(ERROR_SUCCESS==rc && dwDSize>0 && dwType==REG_DWORD) 
		{ 
			if(*(DWORD*)szData != 1) 
			{			 
				bFlash=TRUE; 
				RegSetValueEx(hKey,_T("AllowAnonymousVroots"),NULL,REG_DWORD,(BYTE*)&enable,sizeof enable);	 
				 
			} 
		} 
	 
		dwType=REG_NONE; 
		dwDSize=dim(szData); 
		ZeroMemory(szData,sizeof(szData)); 
		rc=RegQueryValueEx(hKey,_T("IsEnabled"),NULL,&dwType,(BYTE*)&szData,&dwDSize); 
		if(ERROR_SUCCESS==rc && dwDSize>0 && dwType==REG_DWORD) 
		{ 
			if(*(DWORD*)szData != 1) 
			{			 
				bFlash=TRUE; 
				RegSetValueEx(hKey,_T("IsEnabled"),NULL,REG_DWORD,(BYTE*)&enable,sizeof enable);	 
				 
			} 
		} 
 
		if(bFlash) 
		{ 
			::RegFlushKey(hKey); 
		} 
		::RegCloseKey(hKey); 
	} 
 
 
}