📄 messagedlg.cpp
字号:
pos=pos+2;
if(""==sms.GetLastReadSMSSend())
{
str=str+_T("[来自]:存储信息");
str=str+_T("\r\n");
}
Var_datetime=sms.GetLastReadSMSTime();
Var_DateTime=Var_datetime;
str=str+_T("[时间]:");
str=str+Var_DateTime.Format(_T("%Y.%m.%d "));
str=str+Var_DateTime.Format(_T("%H:%M:%S"));
str=str+_T("\r\n");
str=str+_T("[内容]:");
str=str+sms.GetLastReadSMSText();
str=str+_T("\r\n\r\n");
ReadStr.Insert(pos,str);
m_ReadText=ReadStr;
UpdateData(FALSE);
}
}
}
Beep(900,100);
}
void CMessageDlg::OnClear()
{
m_SendText="";
m_ReadText="";
ReadStr="";
UpdateData(FALSE);
}
void CMessageDlg::OnDelete()
{
int i;
for(i=1;i<=sms.GetInboxCount();i++)
{
if(sms.ReadSMSMessage(i))
{
sms.DeleteSMSMessage(i);
}
}
m_ReadText="";
UpdateData(FALSE);
Beep(900,100);
}
void CMessageDlg::OnTimer(UINT nIDEvent)
{
CString str;
COleDateTime time;
time=COleDateTime::GetCurrentTime();
str=time.Format(_T("%Y.%m.%d "));
str=str+time.Format(_T("%H:%M:%S "));
switch(time.GetDayOfWeek())
{
case 1: str=str+_T("星期日");
break;
case 2: str=str+_T("星期一");
break;
case 3: str=str+_T("星期二");
break;
case 4: str=str+_T("星期三");
break;
case 5: str=str+_T("星期四");
break;
case 6: str=str+_T("星期五");
break;
case 7: str=str+_T("星期六");
break;
}
m_Time=str;
timerupdate=TRUE;
UpdateData(FALSE);
timerupdate=FALSE;
CDialog::OnTimer(nIDEvent);
}
void CMessageDlg::OnChangeSendText()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.
// TODO: Add your control notification handler code here
UpdateData(TRUE);
char ch[20];
_itoa(m_SendText.GetLength(),ch,10);
m_CharNum=ch;
_itoa((m_SendText.GetLength()-1)/70+1,ch,10);
m_MessageNum=ch;
if(0==m_SendText.GetLength())
m_MessageNum="0";
m_Result="";
UpdateData(FALSE);
if(0==m_SendText.GetLength()%70&&0!=m_SendText.GetLength())
{
Beep(500,600);
}
}
void CMessageDlg::PhoneState()
{
UpdateData(TRUE);
char buffer[20];
CString str;
_ltoa(sms.GetBatteryLevel(),buffer,10);
str="电池电量:";
str=str+buffer;
str=str+"%";
m_BatterLevel=str;
_ltoa(sms.GetSignalLevel(),buffer,10);
str="信号强度:";
str=str+buffer;
str=str+"%";
m_Signal=str;
UpdateData(FALSE);
}
void CMessageDlg::WritePhoneBook()
{
//源文件句柄
CStdioFile InputFile;
//文件状态
CFileStatus FileStatus;
//消息字符串
CString msg;
//电话簿文件名字符串
CString PhoneBook("PhoneBook.txt");
//列表中提取的电话号码
CString PhoneNumber;
//判断文件能否打开
if(!InputFile.Open(PhoneBook, CFile::modeCreate | CFile::modeWrite | CFile::typeBinary ) )
{
msg.Format(_T("%s can not open"),PhoneBook);
AfxMessageBox (msg ) ;
return;
}
for(int i=0;i<PhoneNumList.GetCount();i++)
{
PhoneNumList.GetLBText(i,PhoneNumber);
PhoneNumber=PhoneNumber+"\r\n";
InputFile.WriteString(PhoneNumber);
}
InputFile.Close();
}
void CMessageDlg::GetPhoneNumber()
{
//源文件句柄
CStdioFile InputFile;
//文件状态
CFileStatus FileStatus;
//消息字符串
CString msg;
//电话簿文件名字符串
CString PhoneBook("PhoneBook.txt");
//电话簿中提取的电话号码
CString PhoneNumber;
//判断文件是否存在
if (!CFile::GetStatus(PhoneBook,FileStatus))
{
msg.Format(_T("%s does not exist!\nbut you can create it."),PhoneBook);
AfxMessageBox (msg ) ;
return;
}
//判断文件能否打开
if(!InputFile.Open(PhoneBook, CFile::modeReadWrite | CFile::typeBinary ) )
{
msg.Format(_T("%s can not open\nbut you can create it."),PhoneBook);
AfxMessageBox (msg ) ;
return;
}
//从源文件读数据
while(InputFile.ReadString(PhoneNumber))
{
//采用二进制方式打开文本后,尾部回车也被当作一个字符,因此要剪裁掉
PhoneNumber.TrimLeft();
PhoneNumber.TrimRight();
CString str;
str=PhoneNumber.Right(11);
if(_T("13")==str.Left(2))
{
PhoneNumList.AddString(PhoneNumber);
}
}
InputFile.Close();
}
void CMessageDlg::OnSavebook()
{
WritePhoneBook();
}
void CMessageDlg::OnLoadbook()
{
ClearPhoneList();
GetPhoneNumber();
}
void CMessageDlg::ClearPhoneList()
{
int num;
num=PhoneNumList.GetCount();
for(int i=0;i<num;i++)
PhoneNumList.DeleteString(0);
}
void CMessageDlg::OnAddPhoneNum()
{
UpdateData(TRUE);
CString str;
for(int i=0;i<PhoneNumList.GetCount();i++)
{
PhoneNumList.GetLBText(i,str);
if (str.Right(11)==m_PhoneNum.Right(11))
{
MessageBox(_T("此号码已存在\r\n\r\n")+str);
return;
}
}
PhoneNumList.AddString(m_PhoneNum);
OnSavebook();
}
void CMessageDlg::OnDeltephonenum()
{
UpdateData(TRUE);
PhoneNumList.DeleteString(PhoneNumList.GetCurSel());
OnSavebook();
m_PhoneNum="";
UpdateData(FALSE);
}
void CMessageDlg::OnModifyphonenum()
{
UpdateData(TRUE);
PhoneNumList.DeleteString(PhoneNumList.FindString(-1,m_SelectString));
PhoneNumList.AddString(m_PhoneNum);
OnSavebook();
}
void CMessageDlg::OnCloseupCombo()
{
UpdateData(TRUE);
if (CB_ERR!=PhoneNumList.GetCurSel())
{
PhoneNumList.GetLBText(PhoneNumList.GetCurSel(),m_SelectString);
}
}
void CMessageDlg::OnSaveMessage()
{
//源文件句柄
CStdioFile InputFile;
//文件状态
CFileStatus FileStatus;
//消息字符串
CString msg,message;
//信息中提取的电话号码
CString PhoneNumber;
int pos;
while(""!=ReadStr)
{
ReadStr.Delete(0,5);
pos=ReadStr.Find(_T("\r\n"),0);
PhoneNumber=ReadStr.Left(pos);
PhoneNumber=PhoneNumber.Right(11);
PhoneNumber=PhoneNumber+".txt";
//去掉来电号码
ReadStr.Delete(0,pos+1);
//寻找下一个来电位置
pos=ReadStr.Find(_T("[来自]:"),0);
//如果没有下一个来电
if(-1==pos)
{
pos=10000;
message=ReadStr;
ReadStr="";
}
else
{
//将第一个来电输出并删除
message=ReadStr.Left(pos);
ReadStr.Delete(0,pos);
}
//输出
//判断文件是否存在
if (!CFile::GetStatus(PhoneNumber,FileStatus))
{
msg.Format(_T("%s does not exist,Now will Create it!"),PhoneNumber);
AfxMessageBox (msg ) ;
if(!InputFile.Open(PhoneNumber, CFile::modeCreate |CFile::modeWrite | CFile::typeBinary) )
{
msg.Format(_T("%s can not open"),PhoneNumber);
AfxMessageBox (msg ) ;
return;
}
//开始写文件
InputFile.WriteString(message);
}
else
//判断文件能否打开
if(!InputFile.Open(PhoneNumber, CFile::modeWrite | CFile::typeBinary ) )
{
msg.Format(_T("%s can not open"),PhoneNumber);
AfxMessageBox (msg ) ;
return;
}
//开始写文件
else
{
//将指针指到文件末尾
InputFile.SeekToEnd();
InputFile.WriteString(message);
}
InputFile.Close();
}
}
void CMessageDlg::OnOnSMSReportReceivedSms(long Index, double Time, LPCTSTR Send, long Delivery)
{
m_Result=_T("发送成功!");
UpdateData(FALSE);
}
void CMessageDlg::OnSetfocusSendText()
{
}
void CMessageDlg::SaveSelf()
{
//源文件句柄
CStdioFile InputFile;
//文件状态
CFileStatus FileStatus;
//消息字符串
CString msg;
//电话簿文件名字符串
CString SelfMessage("SelfMessage.txt");
//欲存储的信息
CString str;
COleDateTime time;
time=COleDateTime::GetCurrentTime();
str=_T("[发送]:");
str=str+m_PhoneNum+_T("\r\n");
str=str+_T("[时间]:");
str=str+time.Format(_T("%Y.%m.%d "));
str=str+time.Format(_T("%H:%M:%S\r\n"));
str=str+_T("[内容]:");
str=str+m_SendText;
str=str+_T("\r\n\r\n");
//判断文件是否存在
if (!CFile::GetStatus(SelfMessage,FileStatus))
{
msg.Format(_T("%s does not exist,Now will Create it!"),SelfMessage);
AfxMessageBox (msg ) ;
if(!InputFile.Open(SelfMessage, CFile::modeCreate |CFile::modeWrite | CFile::typeBinary) )
{
msg.Format(_T("%s can not open"),SelfMessage);
AfxMessageBox (msg ) ;
return;
}
//开始写文件
InputFile.WriteString(str);
}
else
//判断文件能否打开
if(!InputFile.Open(SelfMessage, CFile::modeWrite | CFile::typeBinary ) )
{
msg.Format(_T("%s can not open"),SelfMessage);
AfxMessageBox (msg ) ;
return;
}
//开始写文件
else
{
//将指针指到文件末尾
InputFile.SeekToEnd();
InputFile.WriteString(str);
}
InputFile.Close();
}
void CMessageDlg::OnOpenSave()
{
CFileDialog dlg(TRUE,NULL,NULL,OFN_ALLOWMULTISELECT|OFN_SHOWHELP|OFN_NOCHANGEDIR,_T("|*.*||"));
if(dlg.DoModal()==IDOK)
{
POSITION POS;
//得到第一个文件位置
POS=dlg.GetStartPosition();
//源文件句柄
CStdioFile InputFile;
//输出文件句柄
CStdioFile OutputFile;
//文件状态
CFileStatus FileStatus;
//源文件名称
CString SourceFile;
//消息字符串
CString msg;
//目标文件名称
CString TargetFile;
//开始转化
while(POS!=NULL)
{
//得到源文件名
SourceFile=dlg.GetNextPathName(POS);
//判断文件是否存在
if (!CFile::GetStatus(SourceFile,FileStatus))
{
msg.Format(_T("%s does not exist"),SourceFile);
AfxMessageBox (msg ) ;
continue;
}
//判断文件能否打开
if(!InputFile.Open(SourceFile, CFile::modeRead | CFile::typeBinary ) )
{
msg.Format(_T("%s can not open"),SourceFile);
AfxMessageBox (msg ) ;
continue;
}
m_Result=SourceFile;
m_ReadText="";
//从源文件读数据
while(InputFile.ReadString(SourceFile))
{
//向目标文件写数据
m_ReadText=m_ReadText+SourceFile+"\r\n";
}
InputFile.Close();
}
}
UpdateData(FALSE);
}
void CMessageDlg::OnInsertFlash()
{
m_SendText=m_SendText+_T(".");
UpdateData(FALSE);
OnChangeSendText();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -