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

📄 sendpage.cpp

📁 代码为windows下的无线猫的应用程序(对AT指令的操作)。
💻 CPP
字号:
// SendPage.cpp : implementation file
//

#include "stdafx.h"
#include "SIMTOOL.h"
#include "SendPage.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CSendPage dialog
extern CSIMTOOLApp theApp;
DWORD WINAPI SendMultiSMSProc(LPVOID lpParameter);

CSendPage::CSendPage(CWnd* pParent /*=NULL*/)
	: CDialogResize(CSendPage::IDD, pParent)
{
	//{{AFX_DATA_INIT(CSendPage)
	m_SMS = _T("");
	//}}AFX_DATA_INIT
}


void CSendPage::DoDataExchange(CDataExchange* pDX)
{
	CDialogResize::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CSendPage)
	DDX_Control(pDX, IDC_SMS, m_cSMS);
	DDX_Control(pDX, IDC_SENDNO, m_SendNo);
	DDX_Control(pDX, IDC_SMSCENTER, m_SMSCenter);
	DDX_Control(pDX, IDC_CHKPHONEBOOK, m_chkphonebook);
	DDX_Control(pDX, IDC_CHECKBOX, m_checkbox);
	DDX_Control(pDX, IDC_BTNSEND, m_btnsendsms);
	DDX_Text(pDX, IDC_SMS, m_SMS);
	DDV_MaxChars(pDX, m_SMS, 140);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CSendPage, CDialogResize)
	//{{AFX_MSG_MAP(CSendPage)
	ON_BN_CLICKED(IDC_BTNSEND, OnBtnsend)
	ON_BN_CLICKED(IDC_CHKPHONEBOOK, OnChkphonebook)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

BEGIN_DLGRESIZE_MAP(CSendPage)
	DLGRESIZE_CONTROL(IDC_SMS, DLSZ_SIZE_X | DLSZ_SIZE_Y)
	DLGRESIZE_CONTROL(IDC_BTNIMPORT, DLSZ_MOVE_X)
	DLGRESIZE_CONTROL(IDC_BTNSEND, DLSZ_MOVE_X)
END_DLGRESIZE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CSendPage message handlers

BOOL CSendPage::OnInitDialog()
{
	CDialogResize::OnInitDialog();
	
	// TODO: Add extra initialization here
	InitResizing(FALSE, FALSE, WS_CLIPCHILDREN);

	m_btnsendsms.SetIcon(IDI_SENDSMS, 16, 16);

	CImageList imgList;
	imgList.Create(IDB_TREE_ICONS, 18, 1, RGB(0xFF, 0xFF, 0xFF));

	m_checkbox.SetImageList( &imgList );
	m_checkbox.EnableWindow(FALSE);
	m_SMSCenter.SetWindowText("+8613800100500");
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CSendPage::DeleteTreeItem()
{
}

void CSendPage::OnBtnsend()
{
	// TODO: Add your control notification handler code here
	if (!m_chkphonebook.GetCheck())
	{
		SendSignleSMS();
	}
	else
	{
		SendMultiSMS();
	}
}

void CSendPage::OnChkphonebook() 
{
	// TODO: Add your control notification handler code here
	CString pathname, phoneindex, name, phonenum, itemtmp, tmp;
	CIVStringSet m_setstrings;
	char openfile[MAX_PATH], buf[2], phid[5], num[20], per[50], insertstr[256];
	FILE * openstream;
	int count, nWord, front, back, i;
	CString strAppPath;
	char cTmpPath[MAX_PATH];

	memset(cTmpPath, 0, MAX_PATH);

	strAppPath = theApp.GetAppPath();
	sprintf(cTmpPath, "%s\\tmp.txt", strAppPath);

	memset(openfile,0,MAX_PATH);
	memset(buf, 0, 2);
	memset(phid, 0, 5);
	memset(num, 0, 20);
	memset(per, 0, 50);
	memset(insertstr, 0, 256);
	m_setstrings.Add("\t");
	i = 0;

	if (m_chkphonebook.GetCheck())
	{	
		if((openstream = fopen(cTmpPath, "r")) == NULL)
		{
			m_chkphonebook.SetCheck(FALSE);
			MessageBox("没有已打开的电话簿", "AWS");
			return;
		}

		while(!feof(openstream))
		{
			count = fread(buf, sizeof(char), 1, openstream);
			if(ferror(openstream))
			{
				perror( "Read error" );
				break;
			}
			itemtmp += buf;
			if (strcmp(buf, "\n") == 0)
			{
				UINT nPos = m_setstrings.FindFirstIn(itemtmp, nWord);
				if (nPos != 0xFFFFFFFF)
				{
					do
					{
						front = nPos;
						phoneindex = itemtmp.Left(front);
						nPos = m_setstrings.FindNext(nWord);
						back = nPos;
						tmp = itemtmp.Left(back);
						name = tmp.Right(tmp.GetLength()-front-1);
						front = back;
						tmp = itemtmp.Left(itemtmp.GetLength()-1);
						phonenum = tmp.Right(tmp.GetLength()-front-1);
						nPos = m_setstrings.FindNext(nWord);
					} while (nPos != 0xFFFFFFFF);
					sprintf(phid, "%s", phoneindex);
					sprintf(per, "%s", name);
					sprintf(num, "%s", phonenum);
					sprintf(insertstr, "%s(%s)", per, num);
					m_checkbox.AddString(insertstr, i);
					itemtmp = "";
					i++;
				}
			}
		}
		fclose(openstream);

		m_checkbox.EnableWindow(TRUE);
	}
	else
	{
		m_checkbox.EnableWindow(FALSE);
	}
}

CString CSendPage::GetCheckedTexts()
{
	return m_checkbox.GetCheckedTexts();
}

void CSendPage::SendSignleSMS()
{
	CString RetInfo, toadr, centernum, sms, sDevComm, sStatus, sAppComm;
	unsigned char cUsc2[500];
	char buf[250], cText[100], comm[20];
	int iLen;

	memset(comm, 0, 20);
	memset(cText, 0, 100);
	memset(buf, 0, 250);
	memset(cUsc2, 0, 500);
	
	sAppComm = theApp.GetAppComm();
	sprintf(comm, "%s", sAppComm);
	theApp.SetStatusText("正在寻找GPRS无线网络设备,请稍后...");
	theApp.SetDevText("");
	sDevComm = theApp.OpenDev(comm, 9600);
	if (sDevComm.GetLength() == 0)
	{
		theApp.SetStatusText("设备未被找到或端口未被初始化,正在尝试初始化...");
		sDevComm = theApp.MultiBautOpenDev(comm);
		if (sDevComm.GetLength() == 0)
		{
			theApp.mobile.CloseComm();
			theApp.SetStatusText("没有找到设备或端口波特率不匹配,请确定设备是否连接...");
			MessageBox("没有找到设备或端口波特率不匹配!", "AWS");
			return;
		}
		else
		{
			theApp.SetStatusText("端口初始化完成,正在打开端口...");
			sDevComm = theApp.OpenDev(comm, 9600);
		}
	}

	UpdateData(TRUE);
	m_SendNo.GetWindowText(toadr);
	m_SMSCenter.GetWindowText(centernum);
	sms = m_SMS;
	if (theApp.GetDevType() == "WAVECOM")
	{
		theApp.SetStatusText("");
		sprintf(cText, "ADBON GPRS MODEM : %s/%d", sDevComm, 9600);
		theApp.SetDevText(cText);

		/*
		UpdateData(TRUE);
		m_SendNo.GetWindowText(toadr);
		m_SMSCenter.GetWindowText(centernum);
		sms = m_SMS;
		*/

		if (toadr.GetLength()==0 || centernum.GetLength()==0 || sms.GetLength()==0)
		{
			theApp.mobile.CloseComm();
			MessageBox("请将信息填写完整!", "AWS");
			return;
		}
		m_ProgDlg.Create(IDD_PROGDLG);
		m_ProgDlg.ShowWindow(TRUE);
		m_ProgDlg.SetStatusText("发送短信息...");
		
		theApp.mobile.CSCA(centernum);
		Sleep(10);
		RetInfo = theApp.mobile.ReceiveInfo();
		theApp.mobile.CMGS(toadr, sms);
		Sleep(10);
		RetInfo = theApp.mobile.ReceiveInfo();
		/*
		m_SMS = "";
		UpdateData(FALSE);
		theApp.mobile.CloseComm();
		m_ProgDlg.SetStatusText("信息发送成功!");
		m_ProgDlg.SetBtnEnable(TRUE);
		*/
	}

	if (theApp.GetDevType() == "BENQ")
	{
		theApp.SetStatusText("");
		sprintf(cText, "ADBON GPRS MODEM : %s/%d", sDevComm, 9600);
		theApp.SetDevText(cText);

		/*
		UpdateData(TRUE);
		m_SendNo.GetWindowText(toadr);
		m_SMSCenter.GetWindowText(centernum);
		sms = m_SMS;
		*/

		if (toadr.GetLength()==0 || centernum.GetLength()==0 || sms.GetLength()==0)
		{
			theApp.mobile.CloseComm();
			MessageBox("请将信息填写完整!", "AWS");
			return;
		}
		m_ProgDlg.Create(IDD_PROGDLG);
		m_ProgDlg.ShowWindow(TRUE);
		m_ProgDlg.SetStatusText("发送短信息...");

		sprintf(buf, "%s", sms);
		
		theApp.mobile.CSCA(centernum);
		Sleep(10);
		RetInfo = theApp.mobile.ReceiveInfo();
		
		iLen = strlen(buf);
		theApp.mobile.gsmEncodeUcs2(buf, cUsc2, iLen);
		theApp.mobile.gsmBytes2String(cUsc2, buf, iLen*2);
		sms = buf;

		theApp.mobile.CFUN();
		Sleep(10);
		RetInfo = theApp.mobile.ReceiveInfo();
	
		theApp.mobile.COPS();
		Sleep(10);
		theApp.mobile.ReceiveInfo();
	
		theApp.mobile.QCOPS();
		Sleep(10);
		theApp.mobile.ReceiveInfo();
	
		theApp.mobile.CMGF("1");		// 短信格式: 0: PDU; 1: TEXT
		Sleep(10);
		RetInfo = theApp.mobile.ReceiveInfo();

		theApp.mobile.CSCS("\"UCS2\"");
		Sleep(10);
		RetInfo = theApp.mobile.ReceiveInfo();

		theApp.mobile.CSMP(17,168,0,8);
		Sleep(10);
		RetInfo = theApp.mobile.ReceiveInfo();

		theApp.mobile.CMGS("\""+toadr+"\"", "00000000"+sms);
		Sleep(10);
		RetInfo = theApp.mobile.ReceiveInfo();
		/*
		m_SMS = "";
		UpdateData(FALSE);
		theApp.mobile.CloseComm();
		m_ProgDlg.SetStatusText("信息发送成功!");
		m_ProgDlg.SetBtnEnable(TRUE);
		*/
	}

	if (theApp.GetDevType() == "SAGEM MO1xx")
	{
		theApp.mobile.SetModuleType("SAGEM MO1xx");
		MessageBox("SAGEM MO1xx", "AWS");
	}
	m_SMS = "";
	UpdateData(FALSE);
	theApp.mobile.CloseComm();
	m_ProgDlg.SetStatusText("信息发送成功!");
	m_ProgDlg.SetBtnEnable(TRUE);
}

void CSendPage::SendMultiSMS()
{
	HANDLE hThread, hProc;
	CString RetInfo, sDevComm, sAppComm, sStatus, sCheckTexts, toadr, centernum, sms;
	char cText[100], comm[20];

	memset(cText, 0, 100);
	memset(comm, 0, 20);

	sAppComm = theApp.GetAppComm();
	sprintf(comm, "%s", sAppComm);
	theApp.SetStatusText("正在寻找GPRS无线网络设备,请稍后...");
	theApp.SetDevText("");
	sDevComm = theApp.OpenDev(comm, 9600);
	if (sDevComm.GetLength() == 0)
	{
		theApp.SetStatusText("设备未被找到或端口未被初始化,正在尝试初始化...");
		sDevComm = theApp.MultiBautOpenDev(comm);
		if (sDevComm.GetLength() == 0)
		{
			theApp.mobile.CloseComm();
			theApp.SetStatusText("没有找到设备或端口波特率不匹配,请确定设备是否连接...");
			MessageBox("没有找到设备或端口波特率不匹配!", "AWS");
			return;
		}
		else
		{
			theApp.SetStatusText("端口初始化完成,正在打开端口...");
			sDevComm = theApp.OpenDev(comm, 9600);
		}
	}

	if (theApp.GetDevType() == "WAVECOM")
	{
		theApp.SetStatusText("");
		sprintf(cText, "ADBON GPRS MODEM : %s/%d", sDevComm, 9600);
		theApp.SetDevText(cText);

		UpdateData(TRUE);
		m_SMSCenter.GetWindowText(centernum);
		sms = m_SMS;

		if (centernum.GetLength()==0 || sms.GetLength()==0)
		{
			theApp.mobile.CloseComm();
			MessageBox("请将信息填写完整!", "AWS");
			return;
		}

		sCheckTexts = GetCheckedTexts();

		if (sCheckTexts.GetLength() == 0)
		{
			theApp.mobile.CloseComm();
			MessageBox("没有选中电话号码!", "AWS");
			return;
		}

		// 设置短信中心号码
		theApp.mobile.CSCA(centernum);
		Sleep(10);
		RetInfo = theApp.mobile.ReceiveInfo();

		m_ProgDlg.Create(IDD_PROGDLG);

		ExitEvent=CreateEvent( NULL,    // no security
							   TRUE,    // explicit reset req
							   FALSE,   // initial event reset
							   NULL ) ; // no name
		ExitedEvent=CreateEvent( NULL,    // no security
								 TRUE,    // explicit reset req
								 FALSE,   // initial event reset
								 NULL ) ; // no name

		if ((hThread=CreateThread(NULL,0,SendMultiSMSProc,this,0,&ThreadId))==NULL) {
			CloseHandle(ExitEvent);
			CloseHandle(ExitedEvent);
			MessageBox("创建通讯线程失败","错误信息",MB_OK);
			return;
		}

		hProc=GetCurrentProcess();
		SetPriorityClass(hProc,HIGH_PRIORITY_CLASS);
		SetThreadPriority(hThread,THREAD_PRIORITY_TIME_CRITICAL);
	}

	if (theApp.GetDevType() == "BENQ")
	{
		theApp.SetStatusText("");
		sprintf(cText, "ADBON GPRS MODEM : %s/%d", sDevComm, 9600);
		theApp.SetDevText(cText);

		UpdateData(TRUE);
		m_SMSCenter.GetWindowText(centernum);
		sms = m_SMS;

		if (centernum.GetLength()==0 || sms.GetLength()==0)
		{
			theApp.mobile.CloseComm();
			MessageBox("请将信息填写完整!", "AWS");
			return;
		}

		sCheckTexts = GetCheckedTexts();

		if (sCheckTexts.GetLength() == 0)
		{
			theApp.mobile.CloseComm();
			MessageBox("没有选中电话号码!", "AWS");
			return;
		}

		// 设置短信中心号码
		theApp.mobile.CSCA(centernum);
		Sleep(10);
		RetInfo = theApp.mobile.ReceiveInfo();

		m_ProgDlg.Create(IDD_PROGDLG);

		ExitEvent=CreateEvent( NULL,    // no security
							   TRUE,    // explicit reset req
							   FALSE,   // initial event reset
							   NULL ) ; // no name
		ExitedEvent=CreateEvent( NULL,    // no security
								 TRUE,    // explicit reset req
								 FALSE,   // initial event reset
								 NULL ) ; // no name

		if ((hThread=CreateThread(NULL,0,SendMultiSMSProc,this,0,&ThreadId))==NULL) {
			CloseHandle(ExitEvent);
			CloseHandle(ExitedEvent);
			MessageBox("创建通讯线程失败","错误信息",MB_OK);
			return;
		}

		hProc=GetCurrentProcess();
		SetPriorityClass(hProc,HIGH_PRIORITY_CLASS);
		SetThreadPriority(hThread,THREAD_PRIORITY_TIME_CRITICAL);
	}

	if (theApp.GetDevType() == "SAGEM MO1xx")
	{
		theApp.mobile.SetModuleType("SAGEM MO1xx");
		MessageBox("SAGEM MO1xx", "AWS");
	}
}

DWORD WINAPI SendMultiSMSProc(LPVOID lpParameter)
{
	CSendPage * pParentWnd;
	CString sCheckTexts, sms, sPhoneList, sToAdr, RetInfo, buf;
	char tmp[141], cMsg[100], cPhoneList[2048], buf1[250];
	unsigned char cUsc2[500];
	int iLen;
	int i;
	BOOL bFlag = FALSE;

	memset(buf1, 0, 250);
	memset(cUsc2, 0, 500);
	memset(cMsg, 0, 100);
	memset(tmp, 0, 141);
	memset(cPhoneList, 0, 2048);
	pParentWnd=(CSendPage *) lpParameter;
	
	sCheckTexts = pParentWnd->GetCheckedTexts();
	if (sCheckTexts.Find(",") == -1)
	{
		sPhoneList = sCheckTexts;
	}
	else
	{
		sPhoneList = sCheckTexts.Left(sCheckTexts.GetLength()-1);
		sPhoneList = sPhoneList.Right(sPhoneList.GetLength()-1);
	}
	memset(cPhoneList, 0, sPhoneList.GetLength()+1);
	sprintf(cPhoneList, "%s", sPhoneList);
	pParentWnd->m_cSMS.GetWindowText(tmp, 141);
	sms = tmp;

	sprintf(buf1, "%s", sms);
	iLen = strlen(buf1);
	theApp.mobile.gsmEncodeUcs2(buf1, cUsc2, iLen);
	theApp.mobile.gsmBytes2String(cUsc2, buf1, iLen*2);
	sms = buf1;

	pParentWnd->m_ProgDlg.ShowWindow(TRUE);
	pParentWnd->m_ProgDlg.SetRange(0,sPhoneList.GetLength());
	// 发送短信
	memset(tmp, 0, 141);
	for(i=0; i<sPhoneList.GetLength()+1; i++)
	{
		buf = cPhoneList[i];
		if (buf==")")
		{
			bFlag = FALSE;
			sprintf(cMsg, "正在向%s发送短信息...", tmp);
			pParentWnd->m_ProgDlg.SetStatusText(cMsg);
			sToAdr = tmp;
			memset(tmp, 0, 141);

			theApp.mobile.CFUN();
			Sleep(10);
			RetInfo = theApp.mobile.ReceiveInfo();
		
			theApp.mobile.COPS();
			Sleep(10);
			theApp.mobile.ReceiveInfo();
		
			theApp.mobile.QCOPS();
			Sleep(10);
			theApp.mobile.ReceiveInfo();
		
			theApp.mobile.CMGF("1");		// 短信格式: 0: PDU; 1: TEXT
			Sleep(10);
			RetInfo = theApp.mobile.ReceiveInfo();

			theApp.mobile.CSCS("\"UCS2\"");
			Sleep(10);
			RetInfo = theApp.mobile.ReceiveInfo();

			theApp.mobile.CSMP(17,168,0,8);
			Sleep(10);
			RetInfo = theApp.mobile.ReceiveInfo();

			theApp.mobile.CMGS("\""+sToAdr+"\"", "00000000"+sms);
			Sleep(10);
			RetInfo = theApp.mobile.ReceiveInfo();
			//theApp.mobile.CMGS(sToAdr, sms);
			Sleep(7000);
			RetInfo = theApp.mobile.ReceiveInfo();
		}
		if (bFlag)
		{
			sprintf(tmp, "%s%s", tmp, buf);
		}
		pParentWnd->m_ProgDlg.SetPos(i);
		if (buf=="(")
		{
			bFlag = TRUE;
		}
	}

	pParentWnd->m_ProgDlg.SetPos(0);
	pParentWnd->m_ProgDlg.SetStatusText("信息发送成功!");
	pParentWnd->m_ProgDlg.SetBtnEnable(TRUE);
	pParentWnd->m_cSMS.SetWindowText("");
	theApp.mobile.CloseComm();

	return 0;
}

⌨️ 快捷键说明

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