📄 gsmgprsview.cpp
字号:
// GsmGprsView.cpp : implementation of the CGsmGprsView class
//
#include "stdafx.h"
#include "GsmGprs.h"
#include "GsmGprsDoc.h"
#include "GsmGprsView.h"
///////////////////////////////////////
#include "sms.h"
extern CGsmGprsApp theApp;
///////////////////////////////////////
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CGsmGprsView
IMPLEMENT_DYNCREATE(CGsmGprsView, CFormView)
BEGIN_MESSAGE_MAP(CGsmGprsView, CFormView)
//{{AFX_MSG_MAP(CGsmGprsView)
ON_BN_CLICKED(IDC_BUTTON_SEND, OnButtonSend)
ON_BN_CLICKED(IDC_BUTTON_INITGPRS, OnButtonInitgprs)
ON_BN_CLICKED(IDC_BUTTON_OPENGPRS, OnButtonOpengprs)
ON_BN_CLICKED(IDC_BUTTON_WRITEGPRS, OnButtonWritegprs)
ON_BN_CLICKED(IDC_BUTTON_READGPRS, OnButtonReadgprs)
ON_WM_TIMER()
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CFormView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CFormView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CFormView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CGsmGprsView construction/destruction
CGsmGprsView::CGsmGprsView()
: CFormView(CGsmGprsView::IDD)
{
//{{AFX_DATA_INIT(CGsmGprsView)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// TODO: add construction code here
}
CGsmGprsView::~CGsmGprsView()
{
}
void CGsmGprsView::DoDataExchange(CDataExchange* pDX)
{
CFormView::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CGsmGprsView)
DDX_Control(pDX, IDC_SMS_LIST, m_ListCtrl);
//}}AFX_DATA_MAP
}
BOOL CGsmGprsView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CFormView::PreCreateWindow(cs);
}
void CGsmGprsView::OnInitialUpdate()
{
CFormView::OnInitialUpdate();
GetParentFrame()->RecalcLayout();
ResizeParentToFit();
///////////////////////////////////////////////////////////
m_ListCtrl.SetBkColor(RGB(196,220,232));
m_ListCtrl.SetTextBkColor(RGB(196,220,232));
m_ListCtrl.SetExtendedStyle(LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES);
m_ListCtrl.InsertColumn(0,_T("号码"),LVCFMT_IMAGE|LVCFMT_LEFT);
m_ListCtrl.InsertColumn(1,_T("时间"));
m_ListCtrl.InsertColumn(2,_T("消息内容"));
m_ListCtrl.SetColumnWidth(0,100);
m_ListCtrl.SetColumnWidth(1,150);
m_ListCtrl.SetColumnWidth(2,360);
SetTimer(1, 1000, NULL);
///////////////////////////////////////////////////////////
}
/////////////////////////////////////////////////////////////////////////////
// CGsmGprsView printing
BOOL CGsmGprsView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CGsmGprsView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CGsmGprsView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
void CGsmGprsView::OnPrint(CDC* pDC, CPrintInfo* /*pInfo*/)
{
// TODO: add customized printing code here
}
/////////////////////////////////////////////////////////////////////////////
// CGsmGprsView diagnostics
#ifdef _DEBUG
void CGsmGprsView::AssertValid() const
{
CFormView::AssertValid();
}
void CGsmGprsView::Dump(CDumpContext& dc) const
{
CFormView::Dump(dc);
}
CGsmGprsDoc* CGsmGprsView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CGsmGprsDoc)));
return (CGsmGprsDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CGsmGprsView message handlers
void CGsmGprsView::OnButtonSend()
{
// TODO: Add your control notification handler code here
// 发送短信
CComboBox* pNumberWnd=(CComboBox*)GetDlgItem(IDC_NUMBER);
CComboBox* pContentWnd=(CComboBox*)GetDlgItem(IDC_CONTENT);
CString strSmsc;
CString strNumber;
CString strContent;
strSmsc = theApp.m_strSmsc;
pNumberWnd->GetWindowText(strNumber);
pContentWnd->GetWindowText(strContent);
// 检查号码
if(strNumber.GetLength() < 11)
{
AfxMessageBox("请输入正确的号码!");
pNumberWnd->SetFocus();
pNumberWnd->SetEditSel(-1, 0);
return;
}
// 检查短消息内容是否空,或者超长
CString strUnicode;
WCHAR wchar[1024];
int nCount = ::MultiByteToWideChar(CP_ACP, 0, strContent, -1, wchar, 1024);
if(nCount <= 1)
{
AfxMessageBox("请输入消息内容!");
pContentWnd->SetFocus();
//pContentWnd->SetEditSel(-1, 0);
return;
}
else if(nCount > 70) // 我们决定全部用UCS2编码,最大70个字符(半角/全角)
{
AfxMessageBox("消息内容太长,无法发送!");
pContentWnd->SetFocus();
pContentWnd->SetEditSel(-1, 0);
return;
}
if(AfxMessageBox("确定发送吗?", MB_YESNO) == IDYES)
{
SM_PARAM SmParam;
memset(&SmParam, 0, sizeof(SM_PARAM));
// 去掉号码前的"+"
if(strSmsc[0] == '+') strSmsc = strSmsc.Mid(1);
if(strNumber[0] == '+') strNumber = strNumber.Mid(1);
// 在号码前加"86"
if(strSmsc.Left(2) != "86") strSmsc = "86" + strSmsc;
if(strNumber.Left(2) != "86") strNumber = "86" + strNumber;
// 填充短消息结构
strcpy(SmParam.SCA, strSmsc);
strcpy(SmParam.TPA, strNumber);
strcpy(SmParam.TP_UD, strContent);
SmParam.TP_PID = 0;
SmParam.TP_DCS = GSM_UCS2;
// 发送短消息
theApp.m_pSmsTraffic->PutSendMessage(&SmParam);
// 列表中加入新串
if(pNumberWnd->FindStringExact(-1, strNumber)<0) pNumberWnd->InsertString(0, strNumber);
if(pContentWnd->FindStringExact(-1, strContent)<0) pContentWnd->InsertString(0, strContent);
}
pContentWnd->SetFocus();
pContentWnd->SetEditSel(-1, 0);
}
void CGsmGprsView::OnButtonInitgprs()
{
// TODO: Add your control notification handler code here
// 初始化GPRS
if(Init_Gprs()==FALSE)
{
AfxMessageBox("初始化失败");
return;
}
else
AfxMessageBox("初始化成功");
}
void CGsmGprsView::OnButtonOpengprs()
{
// TODO: Add your control notification handler code here
if(Open_GPGS_Mode()==FALSE)
{
AfxMessageBox("打开GPRS模式失败");
return;
}
else
AfxMessageBox("打开GPRS模式成功");
}
void CGsmGprsView::OnButtonWritegprs()
{
// TODO: Add your control notification handler code here
char* a = "1111";
if(Write_GPRS_Data(a,5)==FALSE)
{
AfxMessageBox("写GPRS模式失败");
return;
}
else
AfxMessageBox("写GPRS模式成功");
}
void CGsmGprsView::OnButtonReadgprs()
{
// TODO: Add your control notification handler code here
if(Read_GPRS_Data()==FALSE)
{
AfxMessageBox("读取GPRS模式失败");
return;
}
else
AfxMessageBox("读取GPRS模式成功");
}
void CGsmGprsView::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
if(nIDEvent == 1)
{
SM_PARAM SmParam;
CString strTime;
CString strNumber;
CString strContent;
// 取接收到的短消息
if(theApp.m_pSmsTraffic->GetRecvMessage(&SmParam))
{
// 取短消息信息
strNumber = SmParam.TPA;
strContent = SmParam.TP_UD;
strTime = "20" + CString(&SmParam.TP_SCTS[0],2)
+ "-" + CString(&SmParam.TP_SCTS[2],2)
+ "-" + CString(&SmParam.TP_SCTS[4],2)
+ " " + CString(&SmParam.TP_SCTS[6],2)
+ ":" + CString(&SmParam.TP_SCTS[8],2)
+ ":" + CString(&SmParam.TP_SCTS[10],2);
// 去掉号码前的"86"
if(strNumber.Left(2) == "86") strNumber = strNumber.Mid(2);
// 最多保留200条
int nItemCount = m_ListCtrl.GetItemCount();
if(nItemCount >= 200)
{
m_ListCtrl.DeleteItem(0);
nItemCount--;
}
// 插入新消息
m_ListCtrl.InsertItem(nItemCount, strNumber);
m_ListCtrl.SetItemText(nItemCount, 1, strTime);
m_ListCtrl.SetItemText(nItemCount, 2, strContent);
m_ListCtrl.EnsureVisible(nItemCount, FALSE);
}
}
CFormView::OnTimer(nIDEvent);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -