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

📄 smsinterfaceview.cpp

📁 对Motorola的手机模块
💻 CPP
字号:
// smsinterfaceView.cpp : implementation of the CSmsinterfaceView class
//

#include "stdafx.h"
#include "smsinterface.h"
#include "smsinterfaceDoc.h"
#include "smsinterfaceView.h"
#include "MainFrm.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CSmsinterfaceView
IMPLEMENT_DYNCREATE(CSmsinterfaceView, CFormView)

BEGIN_MESSAGE_MAP(CSmsinterfaceView, CFormView)
	//{{AFX_MSG_MAP(CSmsinterfaceView)
	ON_BN_CLICKED(IDC_BTN_PHONENUMADD, OnAddPhoneNum)
	ON_BN_CLICKED(IDC_BTN_NUMADD, OnNumAddSendList)
	ON_BN_CLICKED(IDC_BTN_NUMDEL, OnDelSendNum)
	ON_BN_CLICKED(IDC_BTN_SEND, OnSendMessage)
	ON_BN_CLICKED(IDC_BTN_RESET, OnReset)
	ON_BN_CLICKED(IDC_BTN_SAVESMS, OnBtnSavesms)
	//}}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()

/////////////////////////////////////////////////////////////////////////////
// CSmsinterfaceView construction/destruction

CSmsinterfaceView::CSmsinterfaceView()
	: CFormView(CSmsinterfaceView::IDD)
{
	//{{AFX_DATA_INIT(CSmsinterfaceView)
	m_messagetext = _T("");
	m_phonenum = _T("");
	//}}AFX_DATA_INIT
	// TODO: add construction code here
}

CSmsinterfaceView::~CSmsinterfaceView()
{
}

void CSmsinterfaceView::DoDataExchange(CDataExchange* pDX)
{
	CFormView::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CSmsinterfaceView)
	DDX_Control(pDX, IDC_LIST2, m_listsendnum);
	DDX_Control(pDX, IDC_LIST1, m_listmemnum);
	DDX_Text(pDX, IDC_EDITSMSTEXT, m_messagetext);
	DDX_Text(pDX, IDC_EDITSMSPHONENUM, m_phonenum);
	//}}AFX_DATA_MAP
}

BOOL CSmsinterfaceView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CFormView::PreCreateWindow(cs);
}

void CSmsinterfaceView::OnInitialUpdate()
{
	CFormView::OnInitialUpdate();
	GetParentFrame()->RecalcLayout();
	ResizeParentToFit();
	//CFrameWnd* pframe;
	//pframe=this->GetParentFrame();
	//pframe->PostMessage(WM_REQUEST_PHONEBOOKNUM,0,0);
	
}

/////////////////////////////////////////////////////////////////////////////
// CSmsinterfaceView printing

BOOL CSmsinterfaceView::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default preparation
	return DoPreparePrinting(pInfo);
}

void CSmsinterfaceView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add extra initialization before printing
}

void CSmsinterfaceView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add cleanup after printing
}

void CSmsinterfaceView::OnPrint(CDC* pDC, CPrintInfo* /*pInfo*/)
{
	// TODO: add customized printing code here
}

/////////////////////////////////////////////////////////////////////////////
// CSmsinterfaceView diagnostics

#ifdef _DEBUG
void CSmsinterfaceView::AssertValid() const
{
	CFormView::AssertValid();
}

void CSmsinterfaceView::Dump(CDumpContext& dc) const
{
	CFormView::Dump(dc);
}

CSmsinterfaceDoc* CSmsinterfaceView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CSmsinterfaceDoc)));
	return (CSmsinterfaceDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CSmsinterfaceView message handlers

void CSmsinterfaceView::OnAddPhoneNum()
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	int respos;
	if(m_phonenum==_T(""))
		return;
	respos=m_listsendnum.FindString(-1,m_phonenum);
	if(respos<0)
		m_listsendnum.AddString(m_phonenum);
	else
	{
		CString strnote;
		strnote.Format("号码:%s 已经被添加了!请输入其他号码。",m_phonenum);
		AfxMessageBox(strnote,IDOK);
	}
	//m_phonenum=_T("");
	CEdit* editwnd;
	editwnd=(CEdit*)this->GetDlgItem(IDC_EDITSMSPHONENUM);
	editwnd->SetFocus();
	editwnd->SetSel(0,-1);
	UpdateData(FALSE);
}

void CSmsinterfaceView::OnNumAddSendList() 
{
	// TODO: Add your control notification handler code here
	UpdateData();
	int i,sum;
	int nItemSel;
	int nBuffer[256];
	CString stritem;
	m_listmemnum.SetActiveWindow();		
	sum=m_listmemnum.GetSelCount();
	if(sum)
	{
		
		nItemSel=m_listmemnum.GetSelItems(256,nBuffer);
		for(i=nItemSel-1;i>=0;i--)
		{
			int n=m_listmemnum.GetTextLen( nBuffer[i] );
			m_listmemnum.GetText(nBuffer[i],stritem.GetBuffer(n));
			stritem.ReleaseBuffer();
			if(stritem!=_T(""))
			{
				int pos;
				pos=stritem.Find(':',0);
				pos=stritem.Find(' ',pos+1);
				pos+=2;
				CString tempstr;
				GetSubStr(stritem,pos,stritem.GetLength()-1,tempstr);
				stritem=tempstr;
				int respos;
				respos=m_listsendnum.FindString(-1,stritem);
				if(respos<0)
					m_listsendnum.AddString(stritem);
				else
				{
					CString strnote;
					strnote.Format("号码:%s 已经被添加了!",stritem);
					AfxMessageBox(strnote,IDOK);
				}
			}
		}

	}
}

void CSmsinterfaceView::OnDelSendNum() 
{
	// TODO: Add your control notification handler code here
	int i,sum;
	int nItemSel;
	int nBuffer[256];
	sum=m_listsendnum.GetSelCount();
	if(sum)
	{
		nItemSel=m_listsendnum.GetSelItems(256,nBuffer);
		for(i=nItemSel-1;i>=0;i--)
		{
			m_listsendnum.DeleteString(nBuffer[i]);
			//SendMessage(m_listsendnum,LB_GETTEXT,nBuffer[i],(LPARAM)outChar);
		}
	}
}

void CSmsinterfaceView::OnSendMessage() 
{
	// TODO: Add your control notification handler code here
	UpdateData();
	//得到群发电话号码
	int len;
	len=m_messagetext.GetLength();
	if(len<140)
	{
	CString strtext,phonenum;
	dialnumar.RemoveAll();
	for ( int i=0;i <m_listsendnum.GetCount();i++)
	{
		m_listsendnum.GetText( i, strtext);
		GetDialnum(strtext,phonenum);
		dialnumar.Add(phonenum);
	}
	CFrameWnd* pframe;
	pframe=this->GetParentFrame();
	messagetext=m_messagetext;
	len=messagetext.GetLength();
	i=0;
	nBuffertext[0]=len;
	while(i<len)
	{
		nBuffertext[i+1]=messagetext.GetAt(i);
		i++;
	}
	pframe->PostMessage(WM_REQUEST_SMSSENDTEXT,(WPARAM)nBuffertext,(LPARAM)&dialnumar);
	}
	else
		AfxMessageBox("您输入的消息文本太长,请修改!",MB_OK);
}

void CSmsinterfaceView::OnReset() 
{
	// TODO: Add your control notification handler code here
	UpdateData();
	m_messagetext=_T("");
	m_phonenum=_T("");
	m_listsendnum.ResetContent();
	CWnd* editwnd;
	editwnd=this->GetDlgItem(IDC_EDITSMSTEXT);
	editwnd->SetFocus();
	dialnumar.RemoveAll();
	UpdateData(FALSE);
}


LRESULT CSmsinterfaceView::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam) 
{
	// TODO: Add your specialized code here and/or call the base class
	if(message==WM_GETPHONEBOOKLIST)
	{
		
		CFile gfile;
		CFileException e;
		if(!(gfile.Open( "e:/smsinterface/phonebook.dat", CFile::modeReadWrite|CFile::modeCreate|CFile::modeNoTruncate, &e )))
		{
	     #ifdef _DEBUG
	         afxDump << "File could not be opened " << e.m_cause << "\n";
	     #endif	
		}
		phonebookar.RemoveAll();
		ReadAllEntry(gfile,phonebookar);
		gfile.Close();
		GetPhoneBookList(phonebookar);
		
	}
	return CFormView::DefWindowProc(message, wParam, lParam);
}

void CSmsinterfaceView::GetPhoneBookList(CStringArray& phonebook)
{
	int i=0;
	int nSize=phonebook.GetSize()/3;
	m_listmemnum.ResetContent();
	i=nSize-1;
	while(i>=0)
	{
		CString indexstr,namestr,phonestr,str;
		indexstr=phonebook[i*3];
		namestr=phonebook[i*3+1];
		phonestr=phonebook[i*3+2];
		str=indexstr;
		str+=_T(":");
		str+=namestr;
		str+=_T("  ");
		str+=phonestr;
		m_listmemnum.AddString(str);
		i--;
	}

}

void CSmsinterfaceView::DeCodeUni(CString sstr, CString &dstr)
{
	CFile gfile;
	CFileException e;
    if( !gfile.Open( "e:/smsinterface/unitoansi.dit", CFile::modeRead|CFile::typeBinary, &e ) )
	{
     #ifdef _DEBUG
         afxDump << "File could not be opened " << e.m_cause << "\n";
     #endif
		 return;
	}
	WCHAR wch;
	UINT result;
	WORD tempch,ansistr;
	unsigned char cha,chb;
	int len,i;
	i=0;
	len=sstr.GetLength();
	while(i+1<len)
	{
		unsigned char cha,chb;
		cha=sstr.GetAt(i++);
		chb=sstr.GetAt(i++);
		wch=cha*0x100+chb;
		result=1;
		gfile.Seek(0,CFile::begin);
		ansistr=0;
		while(result)
		{
			result=gfile.Read(&tempch,2);
			if(result)
				if(tempch==wch)
				{
					gfile.Read(&tempch,2);
					ansistr=tempch;
					break;
				}
				else
					result=gfile.Read(&tempch,2);
		}
		if(!result)
			ansistr=0xB0A1;
		char ch;
		ch=ansistr / 0x100;
		dstr.Insert(dstr.GetLength(),ch);
		ch=ansistr % 0x100;
		dstr.Insert(dstr.GetLength(),ch);	
	}
	gfile.Close();
}

void CSmsinterfaceView::GetSubStr(CString str, int sindex, int eindex,CString& substr)
{
	int endindex,startindex;
	if((sindex>=str.GetLength())||(sindex>eindex))
	{
		substr=_T("");
		return;
	}
	startindex=sindex;
	if(eindex>=str.GetLength())
		endindex=str.GetLength()-1;
	else
		endindex=eindex;
	int i;
	for(i=startindex;i<=endindex;i++)
		substr.Insert(100,str.GetAt(i));
}

void CSmsinterfaceView::OnBtnSavesms() 
{
	// TODO: Add your control notification handler code here
	UpdateData();
	CString strtext,phonenum;
	for ( int i=0;i <m_listsendnum.GetCount();i++)
	{
		m_listsendnum.GetText( i, strtext);
		GetDialnum(strtext,phonenum);
		dialnumar.Add(phonenum);
	}
	CFrameWnd* pframe;
	pframe=this->GetParentFrame();
	messagetext=m_messagetext;
	int len;
	len=messagetext.GetLength();
	i=0;
	nBuffertext[0]=len;
	while(i<len)
	{
		nBuffertext[i+1]=messagetext.GetAt(i);
		i++;
	}
	pframe->PostMessage(WM_REQUEST_SMSTEXTSAVE,(WPARAM)nBuffertext,(LPARAM)&dialnumar);
}

void CSmsinterfaceView::GetDialnum(CString pblist, CString &dialnum)
{
	int len,i,j;
	BOOL flag;
	len=pblist.GetLength();
	i=0;
	flag=FALSE;
	while((!flag)&&(i+2<len))
	{
		char ch1,ch2,ch3;
		ch1=pblist.GetAt(i);
		ch2=pblist.GetAt(i+1);
		ch3=pblist.GetAt(i+2);
		if((ch1==' ')&&(ch2==':')&&(ch3==' '))
			flag=TRUE;
		i++;
	}
	dialnum.Empty();
	if(!flag)
		dialnum=pblist;
	else
		for(j=i;j<pblist.GetLength();j++)
			dialnum.Insert(dialnum.GetLength()+1,pblist.GetAt(i));
}

void CSmsinterfaceView::IntToHexstr(int dec, CString &hexstr)
{
	int s;
	s=dec / 0x10;
	if(s<10)
		s+=0x30;
	else
		s+=55;
	hexstr.Insert(10,s);
	s=dec % 0x10;
	if(s<10)
		s+=0x30;
	else
		s+=55;
	hexstr.Insert(10,s);
	

}

BOOL CSmsinterfaceView::ReadAllEntry(CFile &file, CStringArray &ar)
{
	BOOL result;
	result=TRUE;
	while(result)
	{
		CString s1,s2,s3;
		result=ReadOneEntry(file,s1,s2,s3);
		if(result)
		{
			ar.Add(s1);
			ar.Add(s2);
			ar.Add(s3);
		}
	}
	return(TRUE);
}

BOOL CSmsinterfaceView::ReadOneItem(CFile &file, CString &str)
{
	int result;
	unsigned char ch;
	result=file.Read(&ch,1);
	if(!result)
		return FALSE;
	while(result)
		if(ch!=0xff)
		{
			str.Insert(str.GetLength(),ch);
			result=file.Read(&ch,1);
		}
		else
			break;
	return TRUE;
}

BOOL CSmsinterfaceView::ReadOneEntry(CFile &file, CString &indexstr, CString &namestr, CString &phonestr)
{
	BOOL result;
	result=ReadOneItem(file,indexstr);
	if(!result)
		return(FALSE);
	result=ReadOneItem(file,namestr);
	result=ReadOneItem(file,phonestr);
	return(TRUE);
}

⌨️ 快捷键说明

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