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

📄 setpoliceuint.cpp

📁 电子监控的网络编程实例
💻 CPP
字号:
// SetPoliceUint.cpp : implementation file
//

#include "stdafx.h"
#include "videocapture.h"
#include "SetPoliceUint.h"

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

/////////////////////////////////////////////////////////////////////////////
// CSetPoliceUint dialog


CSetPoliceUint::CSetPoliceUint(CWnd* pParent /*=NULL*/)
	: CDialog(CSetPoliceUint::IDD, pParent)
{
	//{{AFX_DATA_INIT(CSetPoliceUint)
	m_strUnit = _T("");
	m_tel = _T("");
	//}}AFX_DATA_INIT
}


void CSetPoliceUint::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CSetPoliceUint)
	DDX_Control(pDX, IDC_LIST, m_list);
	DDX_Text(pDX, IDC_EDIT_POLICE_UNIT, m_strUnit);
	DDV_MaxChars(pDX, m_strUnit, 50);
	DDX_Text(pDX, IDC_EDIT_TEL, m_tel);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CSetPoliceUint, CDialog)
	//{{AFX_MSG_MAP(CSetPoliceUint)
	ON_BN_CLICKED(IDC_POLICE_DEL, OnPoliceDel)
	ON_BN_CLICKED(IDC_POLICE_ADD, OnPoliceAdd)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CSetPoliceUint message handlers

BOOL CSetPoliceUint::OnInitDialog() 
{
	CDialog::OnInitDialog();
	try
	{
		CStdioFile* pTxtFile = new CStdioFile();
		if(!pTxtFile->Open(".\\Police.dat",CFile::modeRead | CFile::typeText))
		{
			ShowMessage("Police.dat文件不存在\n系统将新建该文件!",MB_OK|MB_ICONEXCLAMATION);
			
			pTxtFile->Open(".\\Police.dat",CFile::modeWrite | CFile::modeCreate);
			pTxtFile->WriteString("无锡交巡警支队");
			m_list.InsertString(0,"无锡交巡警支队");
		}
		
		
		CString str;
		while(pTxtFile->GetPosition()<pTxtFile->GetLength())
		{
			pTxtFile->ReadString(str);
			m_list.InsertString(m_list.GetCount(),str);
		}
		pTxtFile->Close();
		delete pTxtFile;
	}
	catch (...) {
		WriteLog("读写文件Police.dat失败");
		ShowMessage("读写文件Police.dat失败",MB_OK|MB_ICONERROR);
		return FALSE;
	}
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CSetPoliceUint::OnPoliceDel() 
{
	try{
		int index=m_list.GetCurSel();
		if (index!=LB_ERR)
		{
			m_list.DeleteString(index);
			if (index!=0)
				m_list.SetCurSel(--index);
			else if (m_list.GetCount()!=LB_ERR)
				m_list.SetCurSel(0);	
		}
	}
	catch (...) {
		WriteLog("删除执法单位失败");
		ShowMessage("删除执法单位失败",MB_OK|MB_ICONERROR);		
	}	
}

void CSetPoliceUint::OnPoliceAdd() 
{
	try{
		UpdateData();
		if(m_strUnit.GetLength()>0)
		{
			m_list.InsertString(m_list.GetCurSel()+1,m_strUnit+"---"+m_tel);
			m_list.SetCurSel(m_list.GetCurSel()+1);
			m_strUnit="";
			UpdateData(FALSE);
		}		
	}
	catch (...) {
		WriteLog("添加执法失败");
		ShowMessage("添加执法失败",MB_OK|MB_ICONERROR);		
	}		
}

BOOL CSetPoliceUint::DestroyWindow() 
{
	try{
		CStdioFile* pTxtFile = new CStdioFile();
		pTxtFile->Open(".\\Police.dat",CFile::modeCreate | CFile::modeWrite);
		BYTE a=0x0A;
		CString str;
		
		int count=m_list.GetCount();	
		if(count!=LB_ERR)
		{
			for(int i=0;i<count;i++)
			{
				m_list.GetText(i,str);
				pTxtFile->WriteString(str);
				pTxtFile->Write(&a,1);					
			}
		}
		pTxtFile->Close();
		delete pTxtFile;
	}
	catch (...) {
		WriteLog("保存执法单位修改失败");
		ShowMessage("保存执法单位修改失败",MB_OK|MB_ICONERROR);		
	}	
	return CDialog::DestroyWindow();
}

⌨️ 快捷键说明

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