www.pudn.com > smsinterface.rar > smsinterfaceView.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 GetParentFrame(); 
	messagetext=m_messagetext; 
	len=messagetext.GetLength(); 
	i=0; 
	nBuffertext[0]=len; 
	while(iPostMessage(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=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 GetParentFrame(); 
	messagetext=m_messagetext; 
	int len; 
	len=messagetext.GetLength(); 
	i=0; 
	nBuffertext[0]=len; 
	while(iPostMessage(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