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

📄 smsdlg.cpp

📁 一个用COM或USB接口连接gsm/gprs手机进行短信收发的程序,用到的是simense的通讯模块
💻 CPP
字号:
/* ************************************************************************
	 *	 CSmsDlg.cpp :  Impliment file  of cmd Socket receive server  *
	 *	 Version     :  0.07                                          *
	 *	 Date        :  30th,Nov 2002                                 * 
	 *	 Author      :  Caihy                           	          *
	 *	 Email       :  cai_hai_ying2002@163.com                      *
 *************************************************************************/


#include "stdafx.h"
#include "Sms.h"
#include "SmsDlg.h"
#include "AFXPRIV.H"   //USES_CONVERSION  A2W
extern char* m_Message;           //Message
extern char* m_Number;      //the called number 

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

/////////////////////////////////////////////////////////////////////////////
// CSmsDlg dialog


CSmsDlg::CSmsDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CSmsDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CSmsDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}

//DEL CSmsDlg::~CSmsDlg()
//DEL {
//DEL //	if(m_Com.GetPortOpen()) 
//DEL //	{
//DEL //		m_Com.SetPortOpen(FALSE);
//DEL //		AfxMessageBox("端口关闭");
//DEL //	}
//DEL }


void CSmsDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CSmsDlg)
	DDX_Control(pDX, ID_COMMCTRL, m_Com);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CSmsDlg, CDialog)
	//{{AFX_MSG_MAP(CSmsDlg)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CSmsDlg message handlers

BEGIN_EVENTSINK_MAP(CSmsDlg, CDialog)
    //{{AFX_EVENTSINK_MAP(CSmsDlg)
	ON_EVENT(CSmsDlg, ID_COMMCTRL, 1 /* OnComm */, OnOnCommCommctrl, VTS_NONE)
	//}}AFX_EVENTSINK_MAP
END_EVENTSINK_MAP()

void CSmsDlg::OnOnCommCommctrl() 
{
}

void CSmsDlg::SendString(CString m_strSend)
{
	char TxData[400];   //only 100 characters
	int Count = m_strSend.GetLength();

	//convert CString m_strSend to CByteArray array
	for(int i = 0; i < Count; i++) TxData[i] = m_strSend.GetAt(i); 

	CByteArray array;
	array.RemoveAll();
	array.SetSize(Count);

	for(i=0;i<Count;i++) array.SetAt(i,TxData[i]);
	m_Com.SetOutput(COleVariant(array));
}

int CSmsDlg::SmsConvertPDU() 
{
	USES_CONVERSION;
	unsigned char  EndChar=0x1A;  //末尾字符,表示ctrl+Z
//	char* m_test = "刘博你好吗?我们是中国人,我们在上海闸北区,我们爱你,祝你永远快乐,永远努力!好运常伴!上海复高科技有限公司全体员工fugle!";
	int i;
    CString SCAL = "089168";
//	CString SCA = "3108200105F0";
	CString PDUtype = "11";
	CString MR = "00";
//	CString DA = "0B813119286551F0"; //8byte   me
//	CString DA = "0B813140661099F8"; //8byte   liujing
	CString DAH = "0B81";
	CString DA;
	DA.Empty();
	char MidDA[13];
	for(i=0;i<9;i=i+2)
	{
		MidDA[i] = m_Number[i+1];
		MidDA[i+1] = m_Number[i];
	}
	MidDA[11] = m_Number[10];
	MidDA[10] = 'F';
	for(i=0;i<12;i++) DA=DA+CString(MidDA[i]);
//	DA.Format("%X",DA);

	CString PID = "00";
	CString DCS = "08";
	CString VP = "AA"; //4 days

	LPWSTR temp = A2W(m_Message);
	int len = wcslen(temp);
	CString te,s;
	
	for(i=0;i<len;i++) 
	{
		s.Format("%04X", (WORD)temp[i]);
	//	m_FinalUserData[i] = BYTE(temp[1]);
		te += s;
	//	s += CString(m_FinalUserData[i]);
	}
//	m_FinalData = (BYTE*)temp;
	CString UDL;
	UDL.Format("%02X",len*2);
	CString UD = te;

//	CString UD ="4E2D56FD4EBA"; //发送汉字"中国人"

	CString m_PDU = SCAL+SCA+PDUtype+MR+DAH+DA+PID+DCS+VP+UDL+UD;
	PDUSms = m_PDU+CString(EndChar,1);
	int TotalLen = PDUSms.GetLength();
	return (14+len*2);
}

void CSmsDlg::SmsPDU()
{
	SendString(PDUSms); //Sms after receive '>' char
}

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

// following code must be write if u do not use ClassWizard	
//	DWORD style=WS_VISIBLE|WS_CHILD;
//	if (!m_Com.Create(NULL,style,CRect(0,0,0,0),this,ID_COMMCTRL))
//	{
//		TRACE0("Failed to create OLE Communications Control\n");
//	    return -1; //fail to create  
//	}
	
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}


//DEL void CSmsDlg::OnClose() 
//DEL {
//DEL 
//DEL //	CDialog::DestroyWindow();
//DEL 
//DEL 	int a = DestroyWindow();
//DEL 	TRACE("%d\n",a);
//DEL 	
//DEL 	//	CDialog::OnClose();
//DEL }


⌨️ 快捷键说明

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