?? gprsmsgdlg.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 + -