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

📄 gprsmsgdlg.cpp

📁 周立功WinCE光盘资料
💻 CPP
字号:
// GPRSMsgDlg.cpp : implementation file
//

#include "stdafx.h"
#include "GPRSMsg.h"
#include "GPRSMsgDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CGPRSMsgDlg dialog

CGPRSMsgDlg::CGPRSMsgDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CGPRSMsgDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CGPRSMsgDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CGPRSMsgDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CGPRSMsgDlg)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CGPRSMsgDlg, CDialog)
	//{{AFX_MSG_MAP(CGPRSMsgDlg)
	ON_BN_CLICKED(IDC_SENDMSG, OnSendmsg)
	ON_WM_TIMER()
	ON_BN_CLICKED(IDC_SET_MSGCENTR_TELCODE, OnSetMsgcentrTelcode)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CGPRSMsgDlg message handlers

BOOL CGPRSMsgDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);				// Set big icon
	SetIcon(m_hIcon, FALSE);			// Set small icon
	CenterWindow(GetDesktopWindow());	// center to the hpc screen

	// 初始化 GPRS 模块
	BOOL ret = m_GPRS.GPRS_Init(_T("COM1:"), 115200, (DWORD)this);
	if (ret == FALSE)
	{
		MessageBox(_T("GPRS初始化失败, 请检查是否安装正确."));
		return FALSE;
	}
	
	m_GPRS.OnGPRSRecv = OnGPRSRecv;		/* 设置回调函数	*/
	SetDlgItemText(IDC_MSGCENTR_TELCODE, _T("+8613800200500"));
	m_GPRS.GPRS_DeleteShortMsg(1);		/* 删除第 1 条短信*/
	SetTimer(1, 1000, NULL);			/* 每 1 秒读取一次短信 */

	return TRUE;
}


/*******************************************************************************************
函数名称: CALLBACK CGPRSMsgDlg::OnGPRSRecv
描    述: GPRS 接收回调函数, 当有电话打入或对方挂机时, 将执行该函数
输入参数: DWORD UserParam: 用户在调用 GPRS_Init() 函数时传入的参数.
		  DWORD Status	 : GPRS 状态
		  CString strData: 状态对应的字符串, 如果有电话打入, 则该字符为来电号码	
输出参数: 无
返    回: 无
********************************************************************************************/
void CALLBACK CGPRSMsgDlg::OnGPRSRecv(DWORD UserParam, DWORD Status, CString strData)
{

}


/*******************************************************************************************
函数名称: OnSendmsg
描    述: 发送短信
********************************************************************************************/
void CGPRSMsgDlg::OnSendmsg() 
{
	CString strTelCode, strMsg;

	GetDlgItemText(IDC_SENDMSG_TELCODE, strTelCode);				/* 获取发送短信电话号码及内容*/	
	GetDlgItemText(IDC_EDIT_SENDMSG, strMsg);	

	if ((strTelCode == "") || (strMsg == ""))
	{																/* 判断输入内容是否正确 */
		MessageBox(_T("电话号码或短信内容不能为空."));
		return;
	}

	BOOL ret = m_GPRS.GPRS_SendShortMessage(strTelCode, strMsg);	/* 发送短信 */
	if (ret == TRUE)
		MessageBox(_T("短信发送成功."));
	else
		MessageBox(_T("短信发送失败."));
}


/*******************************************************************************************
函数名称: OnTimer
描    述: 定时服务处理函数
********************************************************************************************/
void CGPRSMsgDlg::OnTimer(UINT nIDEvent) 
{
	BOOL ret;
	CString strTelCode, strMsg;

	ret = m_GPRS.GPRS_ReadShortMessage(1, &strTelCode, &strMsg);	/* 读取第 0 条短信 */
	if (ret == TRUE)
	{
		for (int i = 0; i < strMsg.GetLength(); i++)
		{	
			if ((char)strMsg.GetAt(i) == '\n')						/* 有过行字符 */
			if ((char)strMsg.GetAt(i - 1) != '\r')					/* 但没有回车字符 */
			{
				strMsg.Insert(i, '\r');								/* 插入回车符 */
			}
		}
	
		SetDlgItemText(IDC_RECVMSG_TELCODE, strTelCode);			/* 显示电话号码 */
		SetDlgItemText(IDC_DISP_RECVMSG, strMsg);					/* 显示短信内容 */
		m_GPRS.GPRS_DeleteShortMsg(1);								/* 删除短信 */
	}
	
	SetTimer(1, 1000, NULL);										/* 每 1 秒读取一次短信 */
	CDialog::OnTimer(nIDEvent);
}

void CGPRSMsgDlg::OnSetMsgcentrTelcode() 
{
	CString strCode;

	GetDlgItemText(IDC_MSGCENTR_TELCODE, strCode);

	BOOL ret = m_GPRS.GPRS_SetShortMSGCenterTel(strCode);			/* 设置短信中号码 */
	if (ret == TRUE)
		MessageBox(_T("设置短信中心号码成功."));
	else
		MessageBox(_T("设置短信中心号码失败."));
}

⌨️ 快捷键说明

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