⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 smseditview.cpp

📁 对Motorola的手机模块
💻 CPP
📖 第 1 页 / 共 2 页
字号:
	{
     #ifdef _DEBUG
         afxDump << "File could not be opened " << e.m_cause << "\n";
     #endif
		 return;
	}
	WCHAR wch;
	UINT result;
	WORD tempch,ansistr;
	unsigned char cha,chb;
	int len,i;
	i=0;
	len=sstr.GetLength();
	while(i+1<len)
	{
		unsigned char cha,chb;
		cha=sstr.GetAt(i++);
		chb=sstr.GetAt(i++);
		wch=cha*0x100+chb;
		result=1;
		gfile.Seek(0,CFile::begin);
		ansistr=0;
		while(result)
		{
			result=gfile.Read(&tempch,2);
			if(result)
				if(tempch==wch)
				{
					gfile.Read(&tempch,2);
					ansistr=tempch;
					break;
				}
				else
					result=gfile.Read(&tempch,2);
		}
		if(!result)
			ansistr=0xB0A1;
		char ch;
		ch=ansistr / 0x100;
		dstr.Insert(dstr.GetLength(),ch);
		ch=ansistr % 0x100;
		dstr.Insert(dstr.GetLength(),ch);	
	}
	gfile.Close();
}

void CSmsEditView::GetSubStr(CString str, int sindex, int eindex,CString& substr)
{
	int endindex,startindex;
	if((sindex>=str.GetLength())||(sindex>eindex))
	{
		substr=_T("");
		return;
	}
	startindex=sindex;
	if(eindex>=str.GetLength())
		endindex=str.GetLength()-1;
	else
		endindex=eindex;
	int i;
	for(i=startindex;i<=endindex;i++)
		substr.Insert(100,str.GetAt(i));
}

void CSmsEditView::OnSelchangeListPhonebook() 
{
	// TODO: Add your control notification handler code here
	UpdateData();
	CString stritem;
	int nIndex =m_lstphonebook.GetCurSel();
	int nCount =m_lstphonebook.GetCount();
	if ((nIndex >=0 ) && (nCount >= 1))
	{
	   int n=m_lstphonebook.GetTextLen( nIndex );
	   m_lstphonebook.GetText(nIndex,stritem.GetBuffer(n));
	   stritem.ReleaseBuffer();
	   m_phonenum.Empty();
	   m_name.Empty();
	   m_index.Empty();
	   Getphbookitem(stritem,m_index,m_phonenum,m_name);
	   isselected=TRUE;
	}
	UpdateData(FALSE);
}

void CSmsEditView::OnSetfocusListPhonebook() 
{
	// TODO: Add your control notification handler code here
	UpdateData();
	CString stritem;
	int nIndex =m_lstphonebook.GetCurSel();
	int nCount = m_lstphonebook.GetCount();
	if((nIndex >=0 ) && (nCount >= 1))
	{
	   int n=m_lstphonebook.GetTextLen( nIndex );
	   m_lstphonebook.GetText(nIndex,stritem.GetBuffer(n));
	   stritem.ReleaseBuffer();
	   m_phonenum.Empty();
	   m_name.Empty();
	   m_index.Empty();
	   Getphbookitem(stritem,m_index,m_phonenum,m_name);
	   isselected=TRUE;
	}
	UpdateData(FALSE);
}

void CSmsEditView::Getphbookitem(CString stritem,CString &indexstr, CString &phonestr, CString &namestr)
{
	int pos;
	pos=stritem.Find(':',0);
	GetSubStr(stritem,0,pos-1,indexstr);
	int sindex,eindex;
	sindex=pos+2;
	pos=stritem.Find(' ',sindex);
	eindex=pos-1;
	GetSubStr(stritem,sindex,eindex,namestr);
	GetSubStr(stritem,eindex+3,stritem.GetLength()-1,phonestr);

}

void CSmsEditView::OnButtonCancel() 
{
	// TODO: Add your control notification handler code here
	CEdit* editwnd;
	CEdit* editwnd2;
	isoperating=FALSE;
	editwnd=(CEdit*)this->GetDlgItem(IDC_EDIT_NAME);
	::EnableWindow(editwnd->m_hWnd,isoperating);
	editwnd2=(CEdit*)this->GetDlgItem(IDC_EDIT_PHONE);
	::EnableWindow(editwnd2->m_hWnd,isoperating);
	m_btncancel.EnableWindow(isoperating);
	editwnd->SetFocus();
	editwnd->SetSel(0,-1);
	m_lstphonebook.EnableWindow(!isoperating);
	if(whichbtn==EDITENTRY)
	{
		m_btnadd.EnableWindow(!isoperating);
		m_btndel.EnableWindow(!isoperating);	
		m_btnedit.SetWindowText("编      辑");
	}
	if(whichbtn==ADDENTRY)
	{
		m_btnedit.EnableWindow(!isoperating);
		m_btndel.EnableWindow(!isoperating);	
		m_btnadd.SetWindowText("添      加");
	}
	if(whichbtn==EDITENTRY)
	{
		m_btnadd.EnableWindow(!isoperating);
		m_btnedit.EnableWindow(!isoperating);	
		m_btndel.SetWindowText("删      除");
	}
	whichbtn=0;
	
}

void CSmsEditView::AnsiToUni(CString ans, CString &uni)
{
	char ch[2];
	unsigned char cha,chb;
	int i,len,re;
	len=ans.GetLength();
	i=0;
	while(i<len)
	{
		WCHAR wch;
		cha=ans.GetAt(i++);
		if(cha<0x80)
		{
			chb=0x00;
		}
		else
		{
			ch[0]=cha;
			cha=ans.GetAt(i++);
			ch[1]=cha;
			int re=MultiByteToWideChar(CP_ACP,0,ch,2,&wch,1);
			cha=wch % 0x100;
			chb=wch / 0x100;
		}
		uni.Insert(uni.GetLength()+1,chb);
		uni.Insert(uni.GetLength()+1,cha);
	}
}
BOOL CSmsEditView::ReadAllEntry(CFile &file, CStringArray &ar)
{
	BOOL result;
	result=TRUE;
	while(result)
	{
		CString s1,s2,s3;
		result=ReadOneEntry(file,s1,s2,s3);
		if(result)
		{
			ar.Add(s1);
			ar.Add(s2);
			ar.Add(s3);
		}
	}
	return(TRUE);
}

BOOL CSmsEditView::ReadOneItem(CFile &file, CString &str)
{
	int result;
	unsigned char ch;
	result=file.Read(&ch,1);
	if(!result)
		return FALSE;
	while(result)
		if(ch!=0xff)
		{
			str.Insert(str.GetLength(),ch);
			result=file.Read(&ch,1);
		}
		else
			break;
	return TRUE;
}

BOOL CSmsEditView::ReadOneEntry(CFile &file, CString &indexstr, CString &namestr, CString &phonestr)
{
	BOOL result;
	result=ReadOneItem(file,indexstr);
	if(!result)
		return(FALSE);
	result=ReadOneItem(file,namestr);
	result=ReadOneItem(file,phonestr);
	return(TRUE);
}

BOOL CSmsEditView::GetOneEntry(int nIndex, CFile &file, cpbw &phoneentry)
{
	file.Seek(0,CFile::begin);
	BOOL result;
	result=ReadOneEntry(file,phoneentry.indexstr,phoneentry.namestr,phoneentry.phonestr);
	int i=0;
	if(!result)
		return(FALSE);
	if(nIndex==i)
		return(TRUE);
	while(i==nIndex)
	{
		result=ReadOneEntry(file,phoneentry.indexstr,phoneentry.namestr,phoneentry.phonestr);
		if(!result)
			return(FALSE);
		i++;
	}
	return(TRUE);
}

void CSmsEditView::WriteOneItem(CFile &file, CString str)
{
	char ch=0xff;
	str.Insert(str.GetLength(),ch);
	file.Write(str,str.GetLength());
}

void CSmsEditView::WriteOneEntry(CFile &file, CString &indexstr, CString &namestr, CString &phonestr)
{
	WriteOneItem(file,indexstr);
	WriteOneItem(file,namestr);
	WriteOneItem(file,phonestr);
}

BOOL CSmsEditView::EditOneEntry(int nIndex, CFile &file, cpbw phoneentry)
{
	CString sindex;
	sindex.Format("%d",nIndex);
	CFile filebak;
	CFileException e;
    if( !filebak.Open( "e:/smsinterface/phonebookbak.dat", CFile::modeWrite|CFile::modeCreate, &e ) )
	{
     #ifdef _DEBUG
         afxDump << "File could not be opened " << e.m_cause << "\n";
     #endif
		 return FALSE;
	}
	int i=0;
	BOOL result;
	cpbw pentry;
	result=ReadOneEntry(file,pentry.indexstr,pentry.namestr,pentry.phonestr);
	while(result)
	{
		if(i==nIndex)
			WriteOneEntry(filebak,phoneentry.indexstr,phoneentry.namestr,phoneentry.phonestr);
		else
			WriteOneEntry(filebak,pentry.indexstr,pentry.namestr,pentry.phonestr);
		pentry.namestr=_T("");
		pentry.phonestr=_T("");
		pentry.indexstr=_T("");
		i++;
		result=ReadOneEntry(file,pentry.indexstr,pentry.namestr,pentry.phonestr);
	}
	file.Close();
	filebak.Close();
	CFile::Remove("e:/smsinterface/phonebook.dat");
	CFile::Rename("e:/smsinterface/phonebookbak.dat","e:/smsinterface/phonebook.dat");
	if(i<=nIndex)
		return(FALSE);
	else
		return(TRUE);
}

BOOL CSmsEditView::DelOneEntry(int nIndex, CFile &file)
{
	CString sindex;
	sindex.Format("%d",nIndex);
	CFile filebak;
	CFileException e;
    if( !filebak.Open( "e:/smsinterface/phonebookbak.dat", CFile::modeWrite|CFile::modeCreate, &e ) )
	{
     #ifdef _DEBUG
         afxDump << "File could not be opened " << e.m_cause << "\n";
     #endif
		 return FALSE;
	}
	int i=0;
	int j=0;
	BOOL result;
	cpbw pentry;
	result=ReadOneEntry(file,pentry.indexstr,pentry.namestr,pentry.phonestr);
	while(result)
	{
		CString s;
		s.Format("%d",j);
		if(i!=nIndex)
		{
			WriteOneEntry(filebak,s,pentry.namestr,pentry.phonestr);
			j++;
			pentry.namestr=_T("");
			pentry.phonestr=_T("");
			pentry.indexstr=_T("");
		}
		else
		{
			pentry.namestr=_T("");
			pentry.phonestr=_T("");
			pentry.indexstr=_T("");
		}
		i++;
		result=ReadOneEntry(file,pentry.indexstr,pentry.namestr,pentry.phonestr);
	}
	file.Close();
	filebak.Close();
	CFile::Remove("e:/smsinterface/phonebook.dat");
	CFile::Rename("e:/smsinterface/phonebookbak.dat","e:/smsinterface/phonebook.dat");
	if(i<=nIndex)
		return(FALSE);
	else
		return(TRUE);
}

BOOL CSmsEditView::AddOneEntry(CFile &file, cpbw phoneentry)
{
	BOOL result;
	cpbw pentry;
	CString num;
	result=ReadOneEntry(file,pentry.indexstr,pentry.namestr,pentry.phonestr);
	if(!result)
	{
		num=_T("0");
		WriteOneEntry(file,num,phoneentry.namestr,phoneentry.phonestr);
		return(TRUE);
	}
	while(result)
	{
		pentry.namestr=_T("");
		pentry.phonestr=_T("");
		num=pentry.indexstr;
		pentry.indexstr=_T("");
		result=ReadOneEntry(file,pentry.indexstr,pentry.namestr,pentry.phonestr);
	}
	CString s;
	s.Format("%d",atoi(num)+1);
	WriteOneEntry(file,s,phoneentry.namestr,phoneentry.phonestr);
	return(TRUE);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -