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

📄 senddlg.cpp

📁 串口短信收发
💻 CPP
字号:
// SendDlg.cpp : implementation file
//

#include "stdafx.h"
#include "SMS_duanxin.h"

#include "SendDlg.h"
#include "PDUdecoding.h"
#include "RecDlg.h"
#include "JustinIO.h"
#include "PhonebookDlg.h"
#include "SettingDlg.h"

#include "SMS_duanxinDoc.h"
#include "SMS_duanxinView.h"

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

int i=0;
int nsum1=0;
/////////////////////////////////////////////////////////////////////////////
// CSendDlg dialog


CSendDlg::CSendDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CSendDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CSendDlg)
	//}}AFX_DATA_INIT
}


void CSendDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CSendDlg)
	DDX_Control(pDX, IDC_PHONENUM_LIST, m_selephone);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CSendDlg, CDialog)
	//{{AFX_MSG_MAP(CSendDlg)
	ON_BN_CLICKED(IDC__SEND_BUTTON, OnSendButton)
	ON_BN_CLICKED(IDC_PHONEBOOK, OnPhonebook)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CSendDlg message handlers

BOOL CSendDlg::OnInitDialog()
{
	CDialog::OnInitDialog();
	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
	CFile file("电话本.txt",CFile::modeRead);
	CArchive ar(&file,CArchive::load);
	int nsum;
	CString no,name,phone;
	ar>>no>>nsum>>phone;
	ar>>no>>name>>phone;
	while(nsum--)
	{	
		ar>>no>>name>>phone;
		phone.TrimRight("\r\n");
		m_selephone.AddString(phone);
		nsum1++;
	}
	ar.Flush();
	ar.Close();
	file.Close();
	m_selephone.SetCurSel(-1);//初始选择
	TP_PID=0;
return TRUE;
}


//发送控件
void CSendDlg::OnSendButton() 
{
	// TODO: Add your control notification handler code here
	
	//获得用户的输入信息
	CString desPhoneNum;
	CString smsContent;
	CString m_SMSC = "13800716500";
	int smsLength;
	//CSettingDlg set;
    //CSMS_duanxinApp theApp;
	SM_PARAM smParam; 
	UpdateData(true);

  
	//GetDlgItemText(IDC_PHONENUM_LIST,desPhoneNum);
	GetDlgItemText(IDC_SMSCONTENT_EDIT,smsContent);
//	m_SMSC = set.m_strSmsc;
	//smsLength = strlen(smsContent);
	
/*	//检查号码
	if(desPhoneNum.GetLength() < 11)
	{
		AfxMessageBox("请输入正确的号码!");
		m_selephone.SetFocus();
		m_selephone.SetEditSel(-1,0);
		return;
	}*/

	//检查短消息内容是否为空,或超长
	CString strUnicode;
	WCHAR wchar[1024];
	smsLength= MultiByteToWideChar(CP_ACP,0,smsContent,-1,wchar,1024);
	if(smsLength <= -1)
	{
		AfxMessageBox("请输入消息内容!");
		m_selephone.SetFocus();
		m_selephone.SetEditSel(-1,0);
		return;
	}
	else if(smsLength > 70)
	{
		AfxMessageBox("消息内容太长,无法发送!");
		m_selephone.SetFocus();
		m_selephone.SetEditSel(-1,0);
		return;
	}
	
	// m_SMSC="13800716500";       TP_PID=0;
	//填充SM_PARAM结构体内容	
    sprintf(smParam.SCA, "%s",(LPCSTR)m_SMSC);    // 短消息服务中心号码(SMSC地址)
    //sprintf(smParam.TPA, "%s",(LPCSTR)desPhoneNum);   // 目标号码(TP-DA)
	sprintf(smParam.TP_UD,"%s",(LPCSTR)smsContent);  //发送的消息内容(TP_UD)
    smParam.TP_PID=TP_PID;                        // 用户信息协议标识(TP-PID)
    smParam.TP_DCS = GSM_UCS2;                      // 用户信息编码方式(TP-DCS)
	
    
   	
    //OpenComm(theApp.m_strPort, theApp.m_strRate, NOPARITY, 8, ONESTOPBIT);
	if(AfxMessageBox("确定发送吗?", MB_YESNO) == IDYES)
	{
		//发送短消息	
		for(int j=0;j<nsum1;j++)
		{	
		    CString strtemp=m_selephone.SetCurSel(j);
	        m_selephone.GetLBText(j,strtemp);
	        GetDlgItemText(IDC_PHONENUM_LIST,desPhoneNum);
	        sprintf(smParam.TPA, "%s",(LPCSTR)desPhoneNum); //目标号码(TP-DA)
            gsmSendMessage(&smParam);
			//Sleep(500);//睡眠500ms	
		}
		CloseComm();  
	}
    
}

//打开通信录,添加联系人
void CSendDlg::OnPhonebook() 
{
	// TODO: Add your control notification handler code here
	//提取所选列表项号码列内容,放入联系人列表中
	CPhonebookDlg teleadd;
	teleadd.DoModal();
}	


⌨️ 快捷键说明

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