📄 gsmgprsview.cpp
字号:
if(bMsgState==TRUE)
ShowRing();//显示来电
}
CFormView::OnTimer(nIDEvent);
}
void CGsmGprsView::OnButtonLink()
{
// TODO: Add your control notification handler code here
char ans[128];
WriteComm("AT\r", 3);
ReadComm(ans, 128);//at+clip=1
if (strstr(ans, "OK") == NULL)
m_strShowLink="未连接";
else m_strShowLink="已连接";
UpdateData(FALSE);
memset(ans,0,128);
}
void CGsmGprsView::OnButtonSendmsg()
{
// TODO: Add your control notification handler code here
UpdateData();
char ans[1024]={0};
char cSendMsg[128];//
int nlength;
if( ((CButton*)GetDlgItem(IDC_CHECK_AUTORETURN))->GetCheck())
// (GetDlgItem(IDC_CHECK_AUTORETURN)->GetCheck()!=NULL)
{
m_strSendMsg+="\r";
}
nlength=m_strSendMsg.GetLength();
strcpy(cSendMsg,m_strSendMsg);
// TRACE("nlength");
// cSendMsg[nlength+1]="\r";
WriteComm(cSendMsg,nlength);
ReadComm(ans, 1024);
//memset(ans,0,1024);
m_strReceiveMsg=ans;
UpdateData(FALSE);
memset(ans,0,1024);
}
void CGsmGprsView::OnButtonSimread()
{
// TODO: Add your control notification handler code here
char ans[128];
WriteComm("AT+CPMS=SM\r",11);
ReadComm(ans, 128);//
if (strstr(ans, "OK") == NULL)
m_strSimRead="不成功";
else m_strSimRead="成功";
m_strFlashRead.Empty();
UpdateData(FALSE);
memset(ans,0,128);
}
void CGsmGprsView::OnButtonFlashread()
{
// TODO: Add your control notification handler code here
char ans[128];
WriteComm("AT+CPMS=ME\r",11);
ReadComm(ans, 128);//
if (strstr(ans, "OK") == NULL) //查询子串中有没有"OK"
m_strFlashRead="不成功";
else m_strFlashRead="成功";
m_strSimRead.Empty();
UpdateData(FALSE);
memset(ans,0,128);
}
void CGsmGprsView::OnButtonPdu()
{
// TODO: Add your control notification handler code here
char ans[128];
WriteComm("AT+CMGF=0\r",10);
ReadComm(ans, 128); //
if (strstr(ans, "OK") == NULL)
m_strPduMode="不成功";
else m_strPduMode="成功";
m_strTextMode.Empty();
UpdateData(FALSE);
memset(ans,0,128);
}
void CGsmGprsView::OnButtonEmptyrev()
{
// TODO: Add your control notification handler code here
m_strReceiveMsg.Empty();
UpdateData(FALSE);
}
void CGsmGprsView::OnButtonEmptysend()
{
// TODO: Add your control notification handler code here
m_strSendMsg.Empty();
//m_strReceiveMsg.Empty();
UpdateData(FALSE);
}
void CGsmGprsView::OnButtonText()
{
// TODO: Add your control notification handler code here
char ans[128];
WriteComm("AT+CMGF=1\r",10);
ReadComm(ans, 128);//
if (strstr(ans, "OK") == NULL)
m_strTextMode ="不成功";
else m_strTextMode="成功";
m_strPduMode.Empty();
UpdateData(FALSE);
memset(ans,0,128);
}
void CGsmGprsView::OnButtonOricheck()
{
// TODO: Add your control notification handler code here
if(AfxMessageBox("确定要恢复出厂设置吗?",MB_OKCANCEL)==IDOK)
{
char ans[24];
WriteComm("AT&F\r",5);
ReadComm(ans, 24);//
if (strstr(ans, "OK") == NULL)
m_strOriCheck ="不成功";
else m_strOriCheck="成功";
UpdateData(FALSE);
}
}
void CGsmGprsView::OnButtonSimsave()
{
// TODO: Add your control notification handler code here
char ans[128];
WriteComm("AT+CPMS=ME,\r",18);
ReadComm(ans, 128);//
if (strstr(ans, "OK") == NULL)
m_strSimSave ="不成功";
else m_strSimSave="成功";
m_strFlashSave.Empty();
UpdateData(FALSE);
memset(ans,0,128);
}
void CGsmGprsView::OnButtonFlashsave()
{
// TODO: Add your control notification handler code here
char ans[128];
WriteComm("AT+CNMI=2,1,0,0,1\r",18);
ReadComm(ans, 128);//
if (strstr(ans, "OK") == NULL)
m_strFlashSave ="不成功";
else m_strFlashSave="成功";
m_strSimSave.Empty();
UpdateData(FALSE);
memset(ans,0,128);
}
void CGsmGprsView::OnButtonPhoneback()
{
// TODO: Add your control notification handler code here
char ans[24];
WriteComm("ATA\r",4);
ReadComm(ans,24);//
if (strstr(ans, "OK") == NULL)
m_strPhoneBack ="";
else m_strPhoneBack="已接通";
//m_strPhoneBack.Empty();
UpdateData(FALSE);
memset(ans,0,24);
}
void CGsmGprsView::OnButtonHandphone()
{
// TODO: Add your control notification handler code here
char ans[24];
WriteComm("ATH\r",4);
ReadComm(ans,24);//
if (strstr(ans, "OK") == NULL)
m_strHandPhone ="";
else m_strHandPhone="已挂机";
//m_strSimSave.Empty();
UpdateData(FALSE);
memset(ans,0,24);
}
void CGsmGprsView::OnSelendokComboReadpos()
{
// TODO: Add your control notification handler code here
// char ans[64]={0};
int i=m_ctrlReadPos.GetCurSel();
switch(i)
{
case 0:
strReadPos="\"ME\",";
break;
case 1:
strReadPos="\"SM\",";
break;
case 2:
strReadPos="\"MT\",";
break;
}
CString strCommand="AT+CPMS=";
strCommand=strCommand+strReadPos+strWriteSendPos+"\"MT\"\\r";
// int length=strCommand.GetLength();
char cCommand[128]={0};
strcpy(cCommand,strCommand);
//Command+=strWriteSendPos;
int length=strlen(cCommand);
//WriteComm(cCommand,strlen(cCommand));
// WriteComm(cCommand,length);
// ReadComm(ans,64);
// TRACE(ans);
// memset(cCommand,0,length);
//strCpms="AT+CPMS=\"ME\",\"ME\",\"MT\"\r";
}
void CGsmGprsView::OnSelendokComboWritesendpos()
{
// TODO: Add your control notification handler code here
int i=m_ctrlWriteReadPos.GetCurSel();
switch(i)
{
case 0:
strWriteSendPos="\"ME\",";
break;
case 1:
strWriteSendPos="\"SM\",";
break;
case 2:
strWriteSendPos="\"MT\",";
break;
}
CString strCommand="AT+CPMS=";
strCommand+=strReadPos+strWriteSendPos+"\"MT\"\\r\\n";
int length=strCommand.GetLength();
char cCommand[64]={0};
strcpy(cCommand,strCommand);
//Command+=strWriteSendPos;
WriteComm(cCommand,length);
}
void CGsmGprsView::InitListCtrl()
{
FILE *fp;
char filename[255];
int i = 0;
memset(filename,0,255);
strcpy(filename,"E:\\Info.txt");
if( (fp = fopen(filename,"rb")) == NULL)
{
return;
}
while(!feof(fp))//检测流上的文件结束符
{
if (ferror(fp))//检测流上的错误
break;
InfoContent *Info = new InfoContent;
memset(Info,0,sizeof(InfoContent));
if (fread(Info,sizeof(InfoContent),1,fp))
{
m_ListCtrl.InsertItem(i,Info->chNumber);//i行列
m_ListCtrl.SetItemText(i,1,Info->chTimer);
m_ListCtrl.SetItemText(i,2,Info->chContent);
InfoList.AddTail(Info);
i++;
}
else
{
delete Info;
Info = 0;
}
}
fclose(fp);
}
void CGsmGprsView::SaveText(CString strNumber, CString strContent, CString strTime)
{
CString strTempNumber,strTempTimer,strTempContent;
FILE *fp;
char filename[255];
int i = 0;
memset(filename,0,255);
strcpy(filename,"E:\\Info.txt");
if( (fp = fopen(filename,"ab")) == NULL )
{
return ;
}
strTempNumber=strNumber;
strTempTimer=strTime;
strTempContent=strContent;
InfoContent *Info = new InfoContent;//开辟一块区域,结构体指针
memset(Info,0,sizeof(InfoContent));
strcpy(Info->chNumber,strTempNumber);//读进指针指向的数据
strcpy(Info->chTimer,strTempTimer);
strcpy(Info->chContent,strTempContent);
fseek(fp, 0, SEEK_END);//指针指到结尾位置
fwrite(Info,sizeof(InfoContent),1,fp);//开始写文件内容
fclose(fp);
InfoList.AddTail(Info);//
m_ListCtrl.DeleteAllItems();//删除所有的内容,因为有新内容读入
POSITION pos = InfoList.GetHeadPosition();//POSITION为变量类型
while (pos)//不停的循环读出内容
{
InfoContent * Info = InfoList.GetNext(pos);//插入
m_ListCtrl.InsertItem(i,Info->chNumber);//第i行第0列,缺省为0
m_ListCtrl.SetItemText(i,1,Info->chTimer);//第i行第1列
m_ListCtrl.SetItemText(i,2,Info->chContent);//第i行第2列
i++;
}
}
//DEL void CGsmGprsView::OnButton1()
//DEL {
//DEL // TODO: Add your control notification handler code here
//DEL CString strStatus;
//DEL
//DEL strStatus.Format("STATUS:%s OPENED,通信速率%s,短信中心号码%s",m_strPort1,
//DEL m_strRate1,m_strSmsc1);
//DEL
//DEL //strStatus.Format("STATUS:COM%s OPENED,通信速率%s,短信中心号码%s","33",
//DEL //"m_strRate","m_strSmsc");
//DEL
//DEL m_ctrlPortStatus.SetWindowText(strStatus);
//DEL UpdateData(FALSE);
//DEL }
//DEL BOOL CGsmGprsView::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
//DEL {
//DEL // TODO: Add your message handler code here and/or call default
//DEL
//DEL CString strStatus;
//DEL
//DEL strStatus.Format("STATUS:%s OPENED,通信速率%s,短信中心号码%s",m_strPort1,
//DEL m_strRate1,m_strSmsc1);
//DEL
//DEL //strStatus.Format("STATUS:COM%s OPENED,通信速率%s,短信中心号码%s","33",
//DEL //"m_strRate","m_strSmsc");
//DEL
//DEL m_ctrlPortStatus.SetWindowText(strStatus);
//DEL UpdateData(FALSE);
//DEL return CFormView::OnSetCursor(pWnd, nHitTest, message);
//DEL }
void CGsmGprsView::OnButtonSendcomm()
{
// TODO: Add your control notification handler code here
CString strCommand="AT+CPMS=";
strCommand=strCommand+strReadPos+strWriteSendPos+strReceivePos;
// int length=strCommand.GetLength();
char cCommand[128]={0};
strcpy(cCommand,strCommand);
//Command+=strWriteSendPos;
int length=strlen(cCommand);
WriteComm(cCommand,length);
}
void CGsmGprsView::OnSelendokComboRevpos()
{
// TODO: Add your control notification handler code here
int i=m_ctrlReceivePos.GetCurSel();
switch(i)
{
case 0:
strReceivePos="\"MT\"";
break;
case 1:
strReceivePos="\"SM\"";
break;
}
}
//DEL void CGsmGprsView::OnButtonRing()
//DEL {
//DEL // TODO: Add your control notification handler code here
//DEL char ans[24];
//DEL
//DEL WriteComm("at\r",3);
//DEL
//DEL ReadComm(ans,24);//
//DEL if (strstr(ans, "RING")==NULL)
//DEL
//DEL memset(ans,0,24);
//DEL else
//DEL MessageBox("有电话");
//DEL // else //m_strPhoneBack="已接通";
//DEL //m_strPhoneBack.Empty();
//DEL
//DEL //UpdateData(FALSE);
//DEL memset(ans,0,24);
//DEL }
void CGsmGprsView::ShowRing()
{
char ans[64]={0};
CString strRingMsg;
//WriteComm("at\r",3);
ReadComm(ans,64);//at+clip=1
if (strstr(ans, "+CLIP")==NULL) //查找来电的号码
{
memset(ans,0,64);
}
else
{
strRingMsg=ans;
int LenNum=strRingMsg.Find(":");//找冒号后的
strRingMsg=strRingMsg.Mid(LenNum+3,11);//后移11个为号码
strRingMsg=strRingMsg+"来电";
MessageBox(strRingMsg);
}
// else //m_strPhoneBack="已接通";
//m_strPhoneBack.Empty();
//UpdateData(FALSE);
memset(ans,0,24);
}
void CGsmGprsView::OnButtonShowclock()
{
// TODO: Add your control notification handler code here
char ans[128] = {0};
WriteComm("AT+CCLK?\r",9);
ReadComm(ans, 128);//
if (strstr(ans, "OK") == NULL)
m_strShowClock="未连接";
else m_strShowClock=ans;
m_strShowClock=m_strShowClock.Mid(10);
m_strShowClock=m_strShowClock.SpanExcluding("\r\n");
m_strShowClock.Remove('\"');
UpdateData(FALSE);
memset(ans,0,128);
}
void CGsmGprsView::OnNumberKey(UINT nID)
{
CString strNum;
switch(nID)
{
case IDC_BUTTON_1:
strNum="1";
break;
case IDC_BUTTON_2:
strNum="2";
break;
case IDC_BUTTON_3:
strNum="3";
break;
case IDC_BUTTON_11:
strNum="4";
break;
case IDC_BUTTON_5:
strNum="5";
break;
case IDC_BUTTON_6:
strNum="6";
break;
case IDC_BUTTON_7:
strNum="7";
break;
case IDC_BUTTON_8:
strNum = "8";
break;
case IDC_BUTTON_9:
strNum="9";
break;
case IDC_BUTTON_10:
strNum="0";
break;
case IDC_BUTTON_4:
strNum="#";
break;
case IDC_BUTTON_12:
strNum="*";
break;
}
UpdateData();
m_strShowNum = m_strShowNum + strNum; //取数
UpdateData(FALSE);
}
//DEL void CGsmGprsView::OnButton_4()
//DEL {
//DEL // TODO: Add your control notification handler code here
//DEL
//DEL }
//DEL void CGsmGprsView::OnButton_4()
//DEL {
//DEL // TODO: Add your control notification handler code here
//DEL
//DEL }
void CGsmGprsView::OnButtonDodigital()
{
// TODO: Add your control notification handler code here
// MessageBox("已删除完毕!");
UpdateData();
CEdit* pShowNum=(CEdit*)GetDlgItem(IDC_EDIT_SHOWNUMBER);
if(bMsgState==FALSE)
MessageBox("线程被占用,请稍候再拨!");
else
{
if(m_strShowNum.GetLength() < 11)
{
AfxMessageBox("请输入正确的号码!");
pShowNum->SetFocus();//这个函数要求得到输入焦点
// pShowNum->SetSel(-1, 0);//选中组合框的编辑控件中的字符指定起始位置。
//如果为-1,则清除当前的选择指定起始位置。
return;
}
else
{
if(AfxMessageBox("确定拨打吗?", MB_YESNO) == IDYES)
{
bMsgState=FALSE;//是否发短信的布尔值
// theApp.m_pSmsTraffic->stExitThread
// theApp.m_pSmsTraffic=NULL;
bDoPhone=FALSE;
char ans[128]={0};
char cPhone[128]={0};
int Length=0;
CString strPhone="atd";
//Length=m_strShowNum.GetLength();
strPhone=strPhone+m_strShowNum+";"+"\r";
Length=strPhone.GetLength();
strcpy(cPhone,strPhone);
WriteComm(cPhone,Length);
ReadComm(ans, 128);//
memset(ans,0,128);
memset(cPhone,0,128);
//
Sleep(15000);
bMsgState=TRUE;
bDoPhone=TRUE;
}
}
// strPhone.Empty();
// UpdateData(FALSE);
// theApp.m_pSmsTraffic = new CSmsTraffic;
}
}
void CGsmGprsView::OnButton3()
{
// TODO: Add your control notification handler code here
//ADH
}
//DEL void CGsmGprsView::OnButton_CANELLNUM()
//DEL {
//DEL // TODO: Add your control notification handler code here
//DEL
//DEL }
void CGsmGprsView::OnButtonCancellnum()
{
// TODO: Add your control notification handler code here
//MessageBox("已删除完毕!");
UpdateData(TRUE);
if(!(m_strShowNum.IsEmpty()))
{
int length=m_strShowNum.GetLength();
// m_strShowNum.MakeReverse;
m_strShowNum=m_strShowNum.Left(length-1);
// m_strShowNum.MakeReverse;
UpdateData(FALSE);
// length--;
}
else
MessageBox("已删除完毕!");
}
void CGsmGprsView::OnButton4()
{
// TODO: Add your control notification handler code here
//CSettingsDlg dlg;
// dlg.DoModal();
}
void CGsmGprsView::OnButtonEdit()
{
// TODO: Add your control notification handler code here
// CGsmGprsView::OnOK();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -