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

📄 smm4comdlg.cpp

📁 手机开发环境BREW实例
💻 CPP
字号:
// SMM4COMDlg.cpp : implementation file
//

#include "stdafx.h"
#include "SMM4COM.h"
#include "SMM4COMDlg.h"
#include "SMM.h"

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

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About



class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
		// No message handlers
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CSMM4COMDlg dialog
//DWORD WINAPI RecvSMSIndex();

CSMM4COMDlg::CSMM4COMDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CSMM4COMDlg::IDD, pParent)
{
	nIDEvent = 2;
	//{{AFX_DATA_INIT(CSMM4COMDlg)
	m_strMobile = _T("13991802016");
	m_strRecvContent = _T("");
	m_strSendContent = _T("nihao你好!");
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

CSMM4COMDlg::~CSMM4COMDlg()
{
//	KillTimer(nIDEvent);
}
void CSMM4COMDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CSMM4COMDlg)
	DDX_Text(pDX, IDC_EDTMOBILEID, m_strMobile);
	DDV_MaxChars(pDX, m_strMobile, 12);
	DDX_Text(pDX, IDC_EDTRECVCONTENT, m_strRecvContent);
	DDV_MaxChars(pDX, m_strRecvContent, 1024);
	DDX_Text(pDX, IDC_EDTSENDCONTENT, m_strSendContent);
	DDV_MaxChars(pDX, m_strSendContent, 512);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CSMM4COMDlg, CDialog)
	//{{AFX_MSG_MAP(CSMM4COMDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_BNTSEND, OnBntsend)
	ON_WM_TIMER()
	ON_BN_CLICKED(IDC_BNTINIT, OnBntinit)
	ON_BN_CLICKED(IDC_BUTTON_RECV, OnButtonRecv)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CSMM4COMDlg message handlers

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

	// Add "About..." menu item to system menu.

	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// 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
	
	// TODO: Add extra initialization here

	m_cCSMM.Open(1, 115200,8,NOPARITY,1,0);
//	SetTimer(nIDEvent,ELAPSE,NULL);
//	DWORD dwTreadID;


	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CSMM4COMDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CSMM4COMDlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CSMM4COMDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CSMM4COMDlg::OnBntsend() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	int i,nTempLength;
	char szMobileID[20];
	char szSendContent[USER_BUFFER_SIZE];

	nTempLength = m_strMobile.GetLength();
	for(i = 0;i < nTempLength;i++)
	{
		szMobileID[i] = m_strMobile.GetAt(i);
	}
	szMobileID[nTempLength] = '\0';

	nTempLength = m_strSendContent.GetLength();
	for(i = 0;i < nTempLength;i++)
		szSendContent[i] = m_strSendContent.GetAt(i);
	szSendContent[nTempLength] = '\0';

	if(!m_cCSMM.SMSSend(szMobileID,szSendContent))
		m_strRecvContent = _T("OK");
	else
		m_strRecvContent = _T("ERROR");
	UpdateData(FALSE);
}

void CSMM4COMDlg::OnTimer(UINT nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default
	UpdateData(TRUE);
	OnButtonRecv();
	
	
	CDialog::OnTimer(nIDEvent);
}

void CSMM4COMDlg::OnBntinit() 
{
	// TODO: Add your control notification handler code here

	//发送AT+CMGF命令;
	if(!m_cCSMM.SetInNoEcho("0"))
	{
		if(!m_cCSMM.SetSMSFormat("1"))
		{
			if(!m_cCSMM.SetSMSTEChar("UCS2"))
			{
				if(!m_cCSMM.SetSMSModeParameter("17,167,0,25"))
				{
					if(!m_cCSMM.SetSMSRecvPrompt("2,1,0,0,0"))
						AfxMessageBox("Init Successed!");
					else
						AfxMessageBox("Init (CNMI) Fail!");
				}
				else
					AfxMessageBox("Init (CSMP) Fail!");
			}
			else
				AfxMessageBox("Init (CSCS) Fail!");
		}
		else
			AfxMessageBox("Init (CMGF) Fail!");
	}
	else
		AfxMessageBox("Init (ATE) Fail!");
}

void CSMM4COMDlg::OnButtonRecv() 
{
	// TODO: Add your control notification handler code here
	int nSMSIndex = 0;
	char szSMSContent[USER_BUFFER_SIZE];
	szSMSContent[0] = '\0';
	nSMSIndex = m_cCSMM.SMSRecv();

	if(nSMSIndex != 0)
	{
		if(!m_cCSMM.SMSRead(szSMSContent,nSMSIndex))
		{
			CString strSMSContent(szSMSContent);
			m_strRecvContent += strSMSContent;
			if(m_cCSMM.SMSDel(nSMSIndex))
				m_strRecvContent += _T(" Delete Message Recorde Fail!");
		}
		else
		{
			m_strRecvContent += _T("Recieve Message Content Fail!");
		}
	}
	UpdateData(FALSE);

}

⌨️ 快捷键说明

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