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

📄 setpoint.cpp

📁 GPS定位报警程序
💻 CPP
字号:
// SetPoint.cpp : implementation file
//

#include "stdafx.h"
#include "GpsPoint.h"
#include "SetPoint.h"

//#include "GpsPointDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CSetPoint dialog

CSetPoint::CSetPoint(CWnd* pParent /*=NULL*/)
	: CDialog(CSetPoint::IDD, pParent)
{
	//{{AFX_DATA_INIT(CSetPoint)
	m_L1 = _T("");
	m_L2 = _T("");
	m_L3 = _T("");
	m_T1 = _T("");
	m_T2 = _T("");
	m_T3 = _T("");
	m_T4 = _T("");
	m_L4 = _T("");
	//}}AFX_DATA_INIT
}


void CSetPoint::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CSetPoint)
	DDX_Control(pDX, IDC_STATIC_MSG, m_cMsg);
	DDX_Control(pDX, IDC_BUTTON_DELETE, m_Delete);
	DDX_Control(pDX, IDC_BUTTON_CANCEL, m_Cancel);
	DDX_Control(pDX, IDC_BUTTON_ADDUPDATE, m_AddUp);
	DDX_Control(pDX, IDC_LIST_POINT, m_ListPoint);
	DDX_Text(pDX, IDC_STATIC_L1, m_L1);
	DDX_Text(pDX, IDC_STATIC_L2, m_L2);
	DDX_Text(pDX, IDC_STATIC_L3, m_L3);
	DDX_Text(pDX, IDC_EDIT_T1, m_T1);
	DDX_Text(pDX, IDC_EDIT_T2, m_T2);
	DDX_Text(pDX, IDC_EDIT_T3, m_T3);
	DDX_Text(pDX, IDC_EDIT_T4, m_T4);
	DDX_Text(pDX, IDC_STATIC_L4, m_L4);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CSetPoint, CDialog)
	//{{AFX_MSG_MAP(CSetPoint)
	ON_BN_CLICKED(IDC_BUTTON_SAVE, OnButtonSave)
	ON_BN_CLICKED(IDC_BUTTON_EXIT, OnButtonExit)
	ON_WM_DESTROY()
	ON_BN_CLICKED(IDC_BUTTON_CANCEL, OnButtonCancel)
	ON_BN_CLICKED(IDC_BUTTON_ADDUPDATE, OnButtonAddupdate)
	ON_BN_CLICKED(IDC_BUTTON_DELETE, OnButtonDelete)
	ON_NOTIFY(NM_DBLCLK, IDC_LIST_POINT, OnDblclkListPoint)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CSetPoint message handlers

BOOL CSetPoint::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	//配置文件的路径
	strFile=CCommFun::GetAppPath("point.ini");
	strFile1=CCommFun::GetAppPath("setup.ini");
	//初始化表格
	initList();
	//加载设置的点
	iCount=0;
	LoadPoint();
	//定时检测采集的GPS做平均
	iPoint=0;
	for(int i=0;i<100;i++){
		Point[i].dLate=0;
		Point[i].dLong=0;
	}

	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}
//初始化表格
void CSetPoint::initList()
{
	int iWidth;
	CString strTmp;
	DWORD dwStyle= m_ListPoint.GetStyle();
	dwStyle = LVS_EX_GRIDLINES |LVS_EX_FULLROWSELECT;
	m_ListPoint.SetExtendedStyle(dwStyle);
	
	for(int i=1;i<=4;i++){
		strTmp.Format("宽度%d",i);
		iWidth=CCommFun::Getini("表头设置",strTmp,0,strFile1);
		strTmp.Format("名称%d",i);
		strTmp=CCommFun::Getini("表头设置",strTmp,"",strFile1);
		m_ListPoint.InsertColumn(i,strTmp,LVCFMT_LEFT,iWidth);
		//Li
		if(i==1)
			m_L1=strTmp;
		if(i==2)
			m_L2=strTmp;
		if(i==3)
			m_L3=strTmp;
		if(i==4)
			m_L4=strTmp;
	}
	this->UpdateData(FALSE);
}
//保存表头信息
void CSetPoint::SaveList()
{
	int iWidth;
	CString strTmp;
	for(int i=0;i<4;i++){
		iWidth=m_ListPoint.GetColumnWidth(i);
		strTmp.Format("宽度%d",i+1);
		CCommFun::Writeini("表头设置",strTmp,iWidth,strFile1);
	}
}

void CSetPoint::OnButtonExit() 
{
	OnOK();
}

void CSetPoint::OnDestroy() 
{
	CDialog::OnDestroy();
	
	this->KillTimer(1);
	//保存表格宽度
	SaveList();
}
//保存
void CSetPoint::OnButtonSave() 
{
	CString strTmp1,strTmp2,strTmp3;
	//删除文件先
	CFile file;
	file.Open(strFile,CFile::modeCreate);
	file.Close();
	//保存
	CCommFun::Writeini("定位点设置","定位点数目",iCount,strFile);
	for(int i=0;i<m_ListPoint.GetItemCount();i++){
		strTmp1.Format("定点%d",i+1);
		for(int j=0;j<4;j++){
			strTmp2.Format("T%d",j+1);
			strTmp3=m_ListPoint.GetItemText(i,j);
			CCommFun::Writeini(strTmp1,strTmp2,strTmp3,strFile);
		}
	}
	
	OnOK();
}
//加载点设置
void CSetPoint::LoadPoint()
{
	CString strTmp1,strTmp2;
	iCount=CCommFun::Getini("定位点设置","定位点数目",0,strFile);
	for(int i=1;i<=iCount;i++){
		strTmp1.Format("定点%d",i);
		for(int j=1;j<=5;j++){
			strTmp2.Format("T%d",j);
			strTmp2=CCommFun::Getini(strTmp1,strTmp2,"",strFile);
			if(j==1){
				m_ListPoint.InsertItem(i-1,strTmp2);
			}else{
				m_ListPoint.SetItemText(i-1,j-1,strTmp2);
			}
		}
	}
}
//保存点设置
void CSetPoint::SavePoint()
{

}
//取消
void CSetPoint::OnButtonCancel() 
{
	iPoint=101;
	m_T1="";
	m_T2="";
	m_T3="";
	m_T4="";
	m_AddUp.SetWindowText("添加");
	m_Delete.EnableWindow(FALSE);
	this->UpdateData(FALSE);
}
//添加/修改
void CSetPoint::OnButtonAddupdate() 
{
	this->UpdateData(TRUE);
	if(m_T1.Compare("")==0){
		MessageBox("请填写" + m_L1,"提示",MB_OK);
		return;
	}
	if(m_T2.Compare("")==0){
		MessageBox("请填写" + m_L2,"提示",MB_OK);
		return;
	}
	if(m_T3.Compare("")==0){
		MessageBox("请填写" + m_L3,"提示",MB_OK);
		return;
	}
	if(m_T4.Compare("")==0){
		MessageBox("请填写" + m_L4,"提示",MB_OK);
		return;
	}
	if(isExist(m_T1)){
		MessageBox("代码已存在!","提示",MB_OK);
		return;
	}
	CString strTmp;
	m_AddUp.GetWindowText(strTmp);
	if(strTmp.Compare("添加")==0){//添加
		iCount++;
		m_ListPoint.InsertItem(iCount-1,m_T1);
		m_ListPoint.SetItemText(iCount-1,1,m_T2);
		m_ListPoint.SetItemText(iCount-1,2,m_T3);
		m_ListPoint.SetItemText(iCount-1,4,m_T4);
		this->UpdateData(FALSE);
		OnButtonCancel();
	}else{//修改
		m_ListPoint.SetItemText(idx,0,m_T1);
		m_ListPoint.SetItemText(idx,1,m_T2);
		m_ListPoint.SetItemText(idx,2,m_T3);
		m_ListPoint.SetItemText(idx,3,m_T4);
		this->UpdateData(FALSE);
		OnButtonCancel();
	}
	iPoint=101;//停止平均
}
//删除
void CSetPoint::OnButtonDelete() 
{
	if(idx!=-1){
		m_ListPoint.DeleteItem(idx);
		iCount--;
		OnButtonCancel();
	}
	idx=-1;
	iPoint=101;//停止平均
}

//双击编辑
void CSetPoint::OnDblclkListPoint(NMHDR* pNMHDR, LRESULT* pResult) 
{
	//this->KillTimer(1);
	POSITION pos = m_ListPoint.GetFirstSelectedItemPosition();
	idx = m_ListPoint.GetNextSelectedItem(pos);  // 得到项目索引
	if(idx!=-1){
		m_T1=m_ListPoint.GetItemText(idx,0);
		m_T2=m_ListPoint.GetItemText(idx,1);
		m_T3=m_ListPoint.GetItemText(idx,2);
		m_T4=m_ListPoint.GetItemText(idx,3);
		this->UpdateData(FALSE);
		m_AddUp.SetWindowText("修改");
		m_Delete.EnableWindow(TRUE);
	}
	
	*pResult = 0;
}
//判断是否重复
BOOL CSetPoint::isExist(CString strDM)
{
	CString strTmp;
	for(int i=0;i<m_ListPoint.GetItemCount();i++){
		strTmp=m_ListPoint.GetItemText(i,0);
		if((idx!=-1) && (idx==i)){
			
		}else{
			if(strTmp.Compare(strDM)==0){
				return TRUE;
			}
		}
	}
	return FALSE;
}
//显示平均的经纬度
void CSetPoint::ShowLateLong()
{
	this->UpdateData(TRUE);

	double dLate=0;
	double dLong=0;
	long   lJiao=0;
	for(int i=0;i<iPoint;i++){
		dLate+=Point[i].dLate;
		dLong+=Point[i].dLong;
		lJiao+=Point[i].lJiao;
	}
	if(iPoint<=0){
		return;
	}
	CString strTmp;
	COleVariant vt;
	
	strTmp.Format("已采集%d个点做平均",iPoint+1);
	m_cMsg.SetWindowText(strTmp);
	
	m_T2=ftoa(dLate/(iPoint));
	m_T3=ftoa(dLong/(iPoint));
	m_T4=ftoa((int)(lJiao/(iPoint)));

	this->UpdateData(FALSE);
}

void CSetPoint::NewLateLong(double dLate, double dLong,long lJiao,double dV)
{
	if(iPoint>=100){
		return;
	}
	Point[iPoint].dLate=dLate;
	Point[iPoint].dLong=dLong;
	Point[iPoint].lJiao=lJiao;
	//显示平均值
	ShowLateLong();
	iPoint++;
}
//double to CString
CString CSetPoint::ftoa(double dData)
{
	COleVariant vt;
	CString strTmp;

	vt.vt=VT_R8;
	vt.dblVal=dData;
	vt.ChangeType(VT_BSTR);
	strTmp=vt.bstrVal;
	
	return strTmp;
}

BOOL CSetPoint::PreTranslateMessage(MSG* pMsg) 
{
	//避免回车键退出
	if(pMsg->message == WM_KEYDOWN){ 
		switch(pMsg->wParam){
		case VK_RETURN://截获回车 
			return TRUE;
		case VK_ESCAPE://截获ESC 
			return TRUE;
		break;
		}
	}	
	return CDialog::PreTranslateMessage(pMsg);
}

⌨️ 快捷键说明

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