📄 smseditview.cpp
字号:
// SmsEditView.cpp : implementation file
//
#include "stdafx.h"
#include "smsinterface.h"
#include "SmsEditView.h"
#include "SerialPort.h"
#include "MainFrm.h"
#include <afxwin.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CSmsEditView
IMPLEMENT_DYNCREATE(CSmsEditView, CFormView)
CSmsEditView::CSmsEditView()
: CFormView(CSmsEditView::IDD)
{
//{{AFX_DATA_INIT(CSmsEditView)
m_name = _T("");
m_phonenum = _T("");
//}}AFX_DATA_INIT
isoperating=FALSE;
isselected=FALSE;
}
CSmsEditView::~CSmsEditView()
{
}
void CSmsEditView::DoDataExchange(CDataExchange* pDX)
{
CFormView::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CSmsEditView)
DDX_Control(pDX, IDC_BUTTON_CANCEL, m_btncancel);
DDX_Control(pDX, IDC_BUTTON_EDIT, m_btnedit);
DDX_Control(pDX, IDC_BUTTON_DEL, m_btndel);
DDX_Control(pDX, IDC_BUTTON_ADD, m_btnadd);
DDX_Control(pDX, IDC_LIST_PHONEBOOK, m_lstphonebook);
DDX_Text(pDX, IDC_EDIT_NAME, m_name);
DDX_Text(pDX, IDC_EDIT_PHONE, m_phonenum);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CSmsEditView, CFormView)
//{{AFX_MSG_MAP(CSmsEditView)
ON_BN_CLICKED(IDC_BUTTON_ADD, OnAdd)
ON_BN_CLICKED(IDC_BUTTON_DEL, OnDel)
ON_BN_CLICKED(IDC_BUTTON_EDIT, OnEdit)
ON_LBN_SELCHANGE(IDC_LIST_PHONEBOOK, OnSelchangeListPhonebook)
ON_LBN_SETFOCUS(IDC_LIST_PHONEBOOK, OnSetfocusListPhonebook)
ON_BN_CLICKED(IDC_BUTTON_CANCEL, OnButtonCancel)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSmsEditView diagnostics
#ifdef _DEBUG
void CSmsEditView::AssertValid() const
{
CFormView::AssertValid();
}
void CSmsEditView::Dump(CDumpContext& dc) const
{
CFormView::Dump(dc);
}
CSmsinterfaceDoc* CSmsEditView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CSmsinterfaceDoc)));
return (CSmsinterfaceDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CSmsEditView message handlers
void CSmsEditView::OnInitialUpdate()
{
CFormView::OnInitialUpdate();
GetParentFrame()->RecalcLayout();
ResizeParentToFit();
// TODO: Add your specialized code here and/or call the base class
CEdit* editwnd;
editwnd=(CEdit*)this->GetDlgItem(IDC_EDIT_NAME);
::EnableWindow(editwnd->m_hWnd,FALSE);
CEdit* editwnd2;
editwnd2=(CEdit*)this->GetDlgItem(IDC_EDIT_PHONE);
::EnableWindow(editwnd2->m_hWnd,FALSE);
m_btncancel.EnableWindow(FALSE);
}
BOOL CSmsEditView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Add your specialized code here and/or call the base class
return CFormView::PreCreateWindow(cs);
}
void CSmsEditView::OnAdd()
{
// TODO: Add your control notification handler code here
CEdit* editwnd;
CEdit* editwnd2;
if(!isoperating)
{
isoperating=TRUE;
editwnd=(CEdit*)this->GetDlgItem(IDC_EDIT_NAME);
::EnableWindow(editwnd->m_hWnd,isoperating);
editwnd2=(CEdit*)this->GetDlgItem(IDC_EDIT_PHONE);
::EnableWindow(editwnd2->m_hWnd,isoperating);
m_btncancel.EnableWindow(isoperating);
editwnd2->SetFocus();
editwnd2->SetSel(0,-1);
editwnd2->Clear();
editwnd->SetFocus();
editwnd->SetSel(0,-1);
editwnd->Clear();
m_lstphonebook.EnableWindow(!isoperating);
m_btnedit.EnableWindow(!isoperating);
m_btndel.EnableWindow(!isoperating);
m_btnadd.SetWindowText("保存设置");
whichbtn=ADDENTRY;
}
else
{
UpdateData();
int len=m_name.GetLength();
if(len>20)
{
AfxMessageBox("您输入的姓名太长,请修改!",MB_OK);
return;
}
if(len<=0)
{
AfxMessageBox("您输入的姓名为空,请修改!",MB_OK);
return;
}
len=m_phonenum.GetLength();
if(len>20)
{
AfxMessageBox("您输入的电话号码太长,请修改!",MB_OK);
return;
}
if(len<=0)
{
AfxMessageBox("您输入的电话号码为空,请修改!",MB_OK);
return;
}
cpbw pbcpbw;
pbcpbw.indexstr=m_index;
pbcpbw.namestr=m_name;
pbcpbw.phonestr=m_phonenum;
CFile gfile;
CFileException e;
if( !gfile.Open( "e:/smsinterface/phonebook.dat", CFile::modeReadWrite, &e ) )
{
#ifdef _DEBUG
afxDump << "File could not be opened " << e.m_cause << "\n";
#endif
return;
}
AddOneEntry(gfile,pbcpbw);
phonebookar.RemoveAll();
gfile.Seek(0,CFile::begin);
ReadAllEntry(gfile,phonebookar);
gfile.Close();
GetPhoneBookList(phonebookar);
UpdateData(FALSE);
isoperating=FALSE;
editwnd=(CEdit*)this->GetDlgItem(IDC_EDIT_NAME);
::EnableWindow(editwnd->m_hWnd,isoperating);
editwnd2=(CEdit*)this->GetDlgItem(IDC_EDIT_PHONE);
::EnableWindow(editwnd2->m_hWnd,isoperating);
m_btncancel.EnableWindow(isoperating);
m_lstphonebook.EnableWindow(!isoperating);
m_btnedit.EnableWindow(!isoperating);
m_btndel.EnableWindow(!isoperating);
m_btnadd.SetWindowText("添 加");
whichbtn=0;
}
}
void CSmsEditView::OnDel()
{
// TODO: Add your control notification handler code here
if(isselected)
{
int res;
res=AfxMessageBox("您确定要删除这一项吗?",MB_YESNO);
if(res==IDYES)
{
UpdateData();
cpbw pbcpbw;
pbcpbw.indexstr=m_index;
pbcpbw.namestr=m_name;
pbcpbw.phonestr=m_phonenum;
CFile gfile;
CFileException e;
if( !gfile.Open( "e:/smsinterface/phonebook.dat", CFile::modeReadWrite, &e ) )
{
#ifdef _DEBUG
afxDump << "File could not be opened " << e.m_cause << "\n";
#endif
return;
}
DelOneEntry(atoi(pbcpbw.indexstr),gfile);
phonebookar.RemoveAll();
if( !gfile.Open( "e:/smsinterface/phonebook.dat", CFile::modeReadWrite, &e ) )
{
#ifdef _DEBUG
afxDump << "File could not be opened " << e.m_cause << "\n";
#endif
return;
}
ReadAllEntry(gfile,phonebookar);
gfile.Close();
GetPhoneBookList(phonebookar);
UpdateData(FALSE);
m_btncancel.EnableWindow(isoperating);
whichbtn=0;
}
}
}
void CSmsEditView::OnEdit()
{
// TODO: Add your control notification handler code here
CEdit* editwnd;
CEdit* editwnd2;
if(isselected)
if(!isoperating)
{
isoperating=TRUE;
editwnd=(CEdit*)this->GetDlgItem(IDC_EDIT_NAME);
::EnableWindow(editwnd->m_hWnd,isoperating);
editwnd2=(CEdit*)this->GetDlgItem(IDC_EDIT_PHONE);
::EnableWindow(editwnd2->m_hWnd,isoperating);
m_btncancel.EnableWindow(isoperating);
editwnd->SetFocus();
editwnd->SetSel(0,-1);
m_lstphonebook.EnableWindow(!isoperating);
m_btnadd.EnableWindow(!isoperating);
m_btndel.EnableWindow(!isoperating);
m_btnedit.SetWindowText("保存设置");
whichbtn=EDITENTRY;
}
else
{
UpdateData();
int len=m_name.GetLength();
if(len>20)
{
AfxMessageBox("您输入的姓名太长,请修改!",MB_OK);
return;
}
if(len<=0)
{
AfxMessageBox("您输入的姓名为空,请修改!",MB_OK);
return;
}
len=m_phonenum.GetLength();
if(len>20)
{
AfxMessageBox("您输入的电话号码太长,请修改!",MB_OK);
return;
}
if(len<=0)
{
AfxMessageBox("您输入的电话号码为空,请修改!",MB_OK);
return;
}
cpbw pbcpbw;
pbcpbw.indexstr=m_index;
pbcpbw.namestr=m_name;
pbcpbw.phonestr=m_phonenum;
CFile gfile;
CFileException e;
if( !gfile.Open( "e:/smsinterface/phonebook.dat", CFile::modeReadWrite, &e ) )
{
#ifdef _DEBUG
afxDump << "File could not be opened " << e.m_cause << "\n";
#endif
return;
}
EditOneEntry(atoi(pbcpbw.indexstr),gfile,pbcpbw);
phonebookar.RemoveAll();
if( !gfile.Open( "e:/smsinterface/phonebook.dat", CFile::modeReadWrite, &e ) )
{
#ifdef _DEBUG
afxDump << "File could not be opened " << e.m_cause << "\n";
#endif
return;
}
ReadAllEntry(gfile,phonebookar);
gfile.Close();
GetPhoneBookList(phonebookar);
UpdateData(FALSE);
isoperating=FALSE;
editwnd=(CEdit*)this->GetDlgItem(IDC_EDIT_NAME);
::EnableWindow(editwnd->m_hWnd,isoperating);
editwnd2=(CEdit*)this->GetDlgItem(IDC_EDIT_PHONE);
::EnableWindow(editwnd2->m_hWnd,isoperating);
m_btncancel.EnableWindow(isoperating);
m_lstphonebook.EnableWindow(!isoperating);
m_btnadd.EnableWindow(!isoperating);
m_btndel.EnableWindow(!isoperating);
m_btnedit.SetWindowText("编 辑");
whichbtn=0;
}
}
LRESULT CSmsEditView::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::modeRead, &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 CSmsEditView::GetPhoneBookList(CStringArray &phonebook)
{
int i=0;
int nSize=phonebook.GetSize()/3;
m_lstphonebook.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_lstphonebook.AddString(str);
i--;
}
}
void CSmsEditView::DeCodeUni(CString sstr, CString &dstr)
{
CFile gfile;
CFileException e;
if( !gfile.Open( "e:/smsinterface/unitoansi.dit", CFile::modeRead|CFile::typeBinary, &e ) )
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -