📄 dlgdelsta.cpp
字号:
// DlgDelSta.cpp : implementation file
//
#include "stdafx.h"
#include "pcm120.h"
#include "DlgDelSta.h"
#include "DlgAllStaSet.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CDlgDelSta dialog
CDlgDelSta::CDlgDelSta(CWnd* pParent /*=NULL*/)
: CDialog(CDlgDelSta::IDD, pParent)
{
//{{AFX_DATA_INIT(CDlgDelSta)
//}}AFX_DATA_INIT
}
void CDlgDelSta::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDlgDelSta)
DDX_Control(pDX, IDC_LIST_STANAME, m_ctrList);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CDlgDelSta, CDialog)
//{{AFX_MSG_MAP(CDlgDelSta)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDlgDelSta message handlers
BOOL CDlgDelSta::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
CStringArray staAllName;
ReadConfigStaName(staAllName);
int nstraSize;
nstraSize =staAllName.GetSize();
for(int n=0;n<nstraSize;n++)
{
m_ctrList.AddString(staAllName.GetAt(n));
}
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CDlgDelSta::ReadConfigStaName(CStringArray &staName)
{
CDlgAllStaSet dlgalstaset;
CString strPath;
char Get[255];
dlgalstaset.GetModulePath(strPath,NULL);
strPath+="PCM120networksetup.ini";
GetPrivateProfileString("general","StationCnt","0",Get,255,strPath);
int iCntSta =atoi(LPCTSTR(Get));
for(int i=0;i<iCntSta;i++)
{
CString strSection;
strSection.Format("station%d",i+1);
GetPrivateProfileString(strSection,"stationname","NULL",Get,255,strPath);
staName.Add(Get);
}
}
void CDlgDelSta::OnOK()
{
// TODO: Add extra validation here
// CDialog::OnOK();
int nSel;
nSel=m_ctrList.GetCurSel();
DelConfigSta(nSel);
m_ctrList.DeleteString(nSel);
}
void CDlgDelSta::DelConfigSta(int nDel)//删除第几个站,从0开始
{
CDlgAllStaSet dlgalstaset;
CString strPath,strTemppath;
char Get[255];
dlgalstaset.GetModulePath(strPath,NULL);
strTemppath= strPath+"temp.ini";
strPath+="PCM120networksetup.ini";
GetPrivateProfileString("general","StationCnt","0",Get,255,strPath);
int iCntSta =atoi(LPCTSTR(Get));
CStdioFile stdfile;
CFile sfile;
CString strTempCnt;
strTempCnt.Format("%d",iCntSta-1);
CString strLentem,strFir,strMid,strLast,strAllconf,strNeedRep;
WritePrivateProfileString("general","StationCnt",strTempCnt,strPath);
strFir.Format("[station%d]",nDel+1);
strMid.Format("[station%d]",nDel+2);
int bDel=0;
if(sfile.Open(strPath,CFile::modeRead))
{
char *pCharConf=new char[sfile.GetLength()+1];
sfile.Read(pCharConf,sfile.GetLength());
pCharConf+='\0';
strAllconf=(LPCTSTR)pCharConf;
delete[] pCharConf;
int nPosb,nPose;
nPosb =strAllconf.Find(strFir);
nPose =strAllconf.Find(strMid);
strNeedRep=strAllconf.Mid(nPosb,nPose-nPosb);
strAllconf.Replace(strNeedRep,"");
for(int j=nDel;j<=iCntSta;j++)
{
strFir.Format("[station%d]",j+1);
strMid.Format("[station%d]",j+2);
strAllconf.Replace(strMid,strFir);
}
}
sfile.Close();
sfile.Remove(strPath);
if(stdfile.Open(strPath,CFile::modeCreate|CFile::modeWrite))
{
stdfile.WriteString(strAllconf) ;
}
stdfile.Close();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -