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

📄 gps_famdlg.cpp

📁 EVC下
💻 CPP
📖 第 1 页 / 共 3 页
字号:
// GPS_FAMDlg.cpp : implementation file
//

#include "stdafx.h"
#include "GPS_FAM.h"
#include "GPS_FAMDlg.h"
#include "math.h"

#define Pi 3.1415926
#define R 6371116

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

/////////////////////////////////////////////////////////////////////////////
// CGPS_FAMDlg dialog

CGPS_FAMDlg::CGPS_FAMDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CGPS_FAMDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CGPS_FAMDlg)
	m_Info_3 = _T("");
	m_Info_2 = _T("");
	m_Info_1 = _T("");
	m_Info_4 = _T("");
	m_PointNum = _T("");
	m_text = _T("");
	m_Area = _T("");
	m_Girth = _T("");
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CGPS_FAMDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CGPS_FAMDlg)
	DDX_Control(pDX, IDC_BT_BKGND_1, m_Button_BKGND_1);
	DDX_Control(pDX, IDC_BT_BKGND, m_Button_BKGND);
	DDX_Control(pDX, IDC_SUB, m_Bt_Sub);
	DDX_Control(pDX, IDC_ADD, m_Bt_Add);
	DDX_Control(pDX, IDC_RE_MEASURE, m_Bt_Re_Measure);
	DDX_Control(pDX, IDC_GIRTH, m_Bt_Girth);
	DDX_Control(pDX, IDC_DISPLAY, m_Bt_Display);
	DDX_Control(pDX, IDC_AREA, m_Bt_Area);
	DDX_Control(pDX, IDC_RESTART, m_Bt_Restart);
	DDX_Control(pDX, IDC_STOP, m_Bt_Stop);
	DDX_Control(pDX, IDC_MANUAL_START, m_Bt_Manual_Start);
	DDX_Control(pDX, IDC_AUTO_START, m_Bt_Auto_Start);
	DDX_Control(pDX, IDC_AUTO_MODE, m_Bt_Auto_Mode);
	DDX_Control(pDX, IDC_MANUAL_MODE, m_Bt_Manual_Mode);
	DDX_Control(pDX, IDC_EXIT, m_Exit);
	DDX_Text(pDX, IDC_STATIC_INFO_3, m_Info_3);
	DDX_Text(pDX, IDC_STATIC_INFO_2, m_Info_2);
	DDX_Text(pDX, IDC_STATIC_INFO_1, m_Info_1);
	DDX_Text(pDX, IDC_STATIC_INFO_4, m_Info_4);
	DDX_Text(pDX, IDC_STATIC_POINT_NUM, m_PointNum);
	DDX_Text(pDX, IDC_STATIC_TEXT, m_text);
	DDX_Text(pDX, IDC_STATIC_AREA, m_Area);
	DDX_Text(pDX, IDC_STATIC_GIRTH, m_Girth);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CGPS_FAMDlg, CDialog)
	//{{AFX_MSG_MAP(CGPS_FAMDlg)
	ON_WM_ERASEBKGND()
	ON_BN_CLICKED(IDC_EXIT, OnExit)
	ON_BN_CLICKED(IDC_AUTO_MODE, OnAutoMode)
	ON_BN_CLICKED(IDC_MANUAL_MODE, OnManualMode)
	ON_BN_CLICKED(IDC_AUTO_START, OnAutoStart)
	ON_BN_CLICKED(IDC_MANUAL_START, OnManualStart)
	ON_BN_CLICKED(IDC_STOP, OnStop)
	ON_BN_CLICKED(IDC_RESTART, OnRestart)
	ON_BN_CLICKED(IDC_AREA, OnArea)
	ON_BN_CLICKED(IDC_GIRTH, OnGirth)
	ON_BN_CLICKED(IDC_DISPLAY, OnDisplay)
	ON_BN_CLICKED(IDC_RE_MEASURE, OnReMeasure)
	ON_WM_TIMER()
	ON_WM_CTLCOLOR()
	ON_BN_CLICKED(IDC_ADD, OnAdd)
	ON_BN_CLICKED(IDC_SUB, OnSub)
	ON_WM_PAINT()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CGPS_FAMDlg message handlers

BOOL CGPS_FAMDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	CenterWindow(GetDesktopWindow());	// center to the hpc screen
	
	::SetWindowPos(this->GetSafeHwnd(),HWND_TOP,0, 0,320, 240,SWP_SHOWWINDOW);
	
	m_BackScreenBitmap.LoadBitmap(IDB_BKGND);
	// TODO: Add extra initialization here

	m_Exit.LoadBitmaps(IDB_EXIT_UP,IDB_EXIT_DN);
	m_Bt_Auto_Mode.LoadBitmaps(IDB_AUTO_MODE_UP);
	m_Bt_Manual_Mode.LoadBitmaps(IDB_MANUAL_MODE_UP);
	m_Bt_Manual_Start.LoadBitmaps(IDB_START_UP,IDB_START_DN);
	m_Bt_Auto_Start.LoadBitmaps(IDB_START_UP);
	m_Bt_Stop.LoadBitmaps(IDB_STOP_UP,IDB_STOP_DN);
	m_Bt_Restart.LoadBitmaps(IDB_RESTART_UP,IDB_RESTART_DN);
	m_Bt_Area.LoadBitmaps(IDB_AREA_UP,IDB_AREA_DN);
	m_Bt_Girth.LoadBitmaps(IDB_GIRTH_UP,IDB_GIRTH_DN);
	m_Bt_Display.LoadBitmaps(IDB_DISPLAY_UP,IDB_DISPLAY_DN);
	m_Bt_Re_Measure.LoadBitmaps(IDB_RE_MEASURE_UP,IDB_RE_MEASURE_DN);
	m_Bt_Add.LoadBitmaps(IDB_ADD_UP,IDB_ADD_DN);
	m_Bt_Sub.LoadBitmaps(IDB_SUB_UP,IDB_SUB_DN);
	
	m_Button_BKGND.ShowWindow(SW_SHOW);

	m_Exit.MoveWindow(280,197,27,27);
	m_Bt_Auto_Mode.MoveWindow(271,33,15,15);
	m_Bt_Manual_Mode.MoveWindow(288,33,15,15);
	m_Bt_Auto_Start.MoveWindow(208,96,50,18);
	m_Bt_Manual_Start.MoveWindow(208,96,50,18);
	m_Bt_Stop.MoveWindow(208,118,50,18);
	m_Bt_Restart.MoveWindow(208,140,50,18);
	m_Bt_Area.MoveWindow(262,96,50,18);
	m_Bt_Girth.MoveWindow(262,118,50,18);
	m_Bt_Display.MoveWindow(262,140,50,18);
	m_Bt_Re_Measure.MoveWindow(208,162,50,18);
	m_Bt_Add.MoveWindow(288,54,15,15);
	m_Bt_Sub.MoveWindow(271,54,15,15);
	m_Button_BKGND.MoveWindow(268,31,39,20);
	m_Button_BKGND_1.MoveWindow(268,52,39,20);
	
	GetDlgItem(IDC_STATIC_INFO_1)->MoveWindow(15,50,180,15);
	GetDlgItem(IDC_STATIC_INFO_2)->MoveWindow(15,80,180,15);
	GetDlgItem(IDC_STATIC_INFO_3)->MoveWindow(15,110,180,15);
	GetDlgItem(IDC_STATIC_INFO_4)->MoveWindow(15,140,180,15);
	GetDlgItem(IDC_STATIC_POINT_NUM)->MoveWindow(270,77,33,12);

//		GetDlgItem(IDC_STATIC_INFO_1)->ShowWindow(SW_HIDE);
//		GetDlgItem(IDC_STATIC_INFO_2)->ShowWindow(SW_HIDE);
//		GetDlgItem(IDC_STATIC_INFO_3)->ShowWindow(SW_HIDE);
//		GetDlgItem(IDC_STATIC_INFO_4)->ShowWindow(SW_HIDE);
		GetDlgItem(IDC_STATIC_TEXT)->ShowWindow(SW_HIDE);

	GetDlgItem(IDC_STATIC_AREA)->MoveWindow(55,176,140,15);
	GetDlgItem(IDC_STATIC_GIRTH)->MoveWindow(55,194,140,15);

	SetTime[1][0]="3 秒";
	SetTime[1][1]="5 秒";
	SetTime[1][2]="10秒";
	SetTime[1][3]="30秒";
	SetTime[1][4]="1 分";
	SetTime[1][5]="2 分";
	SetTime[1][6]="5 分";

	state=0;
	count=0;
	PointCountDisplay=0;

	space_time=SetTime[1][0];

	i=1;

	return TRUE;  // return TRUE  unless you set the focus to a control
}



BOOL CGPS_FAMDlg::OnEraseBkgnd(CDC* pDC) 
{
	// TODO: Add your message handler code here and/or call default
	BITMAP bmpInfo;
	m_BackScreenBitmap.GetBitmap(&bmpInfo);
	CDC dcMemory;
	dcMemory.CreateCompatibleDC(pDC);
	CBitmap* pOldBitmap = dcMemory.SelectObject(&m_BackScreenBitmap);
	CRect rect;
	GetClientRect(&rect);
	pDC->BitBlt(0, 0, bmpInfo.bmWidth, bmpInfo.bmHeight, &dcMemory, 0, 0, SRCCOPY);
	dcMemory.SelectObject(pOldBitmap);
	return TRUE;
}

void CGPS_FAMDlg::OnExit()
{
	// TODO: Add your control notification handler code here
	CloseHandle(hCom);
	CloseHandle(hFileAuto);
	CloseHandle(hFileManual);

//	DeleteFile(TEXT("\\ResidentFlash\\Coordinate.txt"));
	
	KillTimer(1);
	KillTimer(2);
	KillTimer(3);
	KillTimer(4);

	delete [] ptr3;

	CDialog::OnOK();
}

BOOL CGPS_FAMDlg::OnOpenCom()
{
		hCom = CreateFile (TEXT("COM1:"), // Pointer to the name of the port
		GENERIC_READ | GENERIC_WRITE,// Access (read-write) mode
		0,            // Share mode
		NULL,         // Pointer to the security attribute
		OPEN_EXISTING,// How to open the serial port
		0,            // Port attributes
		NULL);        // Handle to port with attribute to copy
	
	if(hCom==INVALID_HANDLE_VALUE)
	{
		AfxMessageBox(L"打开失败");
		return false;
	}
	
	SetupComm(hCom,100,100); //输入缓冲区和输出缓冲区的大小都是100
	
	COMMTIMEOUTS TimeOuts;
	//设定读超时
	TimeOuts.ReadIntervalTimeout=MAXDWORD;
	TimeOuts.ReadTotalTimeoutMultiplier=0;
	TimeOuts.ReadTotalTimeoutConstant=0;
	//在读一次输入缓冲区的内容后读操作就立即返回,
	//而不管是否读入了要求的字符。
	
	
	//设定写超时
	TimeOuts.WriteTotalTimeoutMultiplier=100;
	TimeOuts.WriteTotalTimeoutConstant=500;
	SetCommTimeouts(hCom,&TimeOuts); //设置超时
	
	DCB dcb;                                                                                  
	GetCommState(hCom,&dcb);
	dcb.BaudRate = 9600; //波特率为9600
	dcb.ByteSize=4; //每个字节有8位
	dcb.Parity=NOPARITY; //无奇偶校验位
	dcb.StopBits=TWOSTOPBITS; //两个停止位
	SetCommState(hCom,&dcb);
	
	PurgeComm(hCom,PURGE_TXCLEAR|PURGE_RXCLEAR);
	
	return true;
}

void CGPS_FAMDlg::OnAutoMode() 
{
	// TODO: Add your control notification handler code here	
	CloseHandle(hCom);
	
	m_Bt_Auto_Mode.LoadBitmaps(IDB_AUTO_MODE_DN);
	m_Bt_Manual_Mode.LoadBitmaps(IDB_MANUAL_MODE_UP);
	
	m_Bt_Auto_Mode.EnableWindow(false);
	m_Bt_Manual_Mode.EnableWindow(true);
	m_Bt_Manual_Start.EnableWindow(false);
//	m_Bt_Auto_Start.EnableWindow(true);
	
	m_Bt_Manual_Start.ShowWindow(SW_HIDE);
	m_Bt_Auto_Start.ShowWindow(SW_SHOW);

	if (OnOpenCom()==1)
	{
	 //	AfxMessageBox(L"COM口打开成功");
		state=1;

		SetTimer(1,1000,NULL);
	}
	
	else
	{
		AfxMessageBox(L"COM口打开失败");

		return;
	}

	CloseHandle(hFileManual);
	
	KillTimer(2);
}

void CGPS_FAMDlg::OnManualMode() 
{
	// TODO: Add your control notification handler code here	
	CloseHandle(hCom);
	
	m_Bt_Manual_Mode.LoadBitmaps(IDB_MANUAL_MODE_DN);
	m_Bt_Auto_Mode.LoadBitmaps(IDB_AUTO_MODE_UP);
 	
	m_Bt_Manual_Mode.EnableWindow(false);
	m_Bt_Auto_Mode.EnableWindow(true);
	m_Bt_Auto_Start.EnableWindow(false);
//	m_Bt_Manual_Start.EnableWindow(true);

	m_Bt_Auto_Start.ShowWindow(SW_HIDE);
 	m_Bt_Manual_Start.ShowWindow(SW_SHOW);
	
	if (OnOpenCom()==1)
	{	 	
	//	AfxMessageBox(L"COM口打开成功");
		state=2;

		SetTimer (2,1000,NULL);		
	}

	else
	{
		AfxMessageBox(L"COM口打开失败");

		return;
	}

	CloseHandle(hFileAuto);
	
	KillTimer(1);
}


void CGPS_FAMDlg::OnAutoStart() 
{
	// TODO: Add your control notification handler code here
	m_Bt_Auto_Start.LoadBitmaps(IDB_START_DN);
	
	m_Bt_Manual_Mode.EnableWindow(false);
	m_Bt_Stop.EnableWindow(true);
	m_Bt_Auto_Start.EnableWindow(false);

	m_Bt_Add.EnableWindow(false);
	m_Bt_Sub.EnableWindow(false);
	
 	m_Bt_Manual_Start.ShowWindow(SW_HIDE);
	
	if(space_time==SetTime[1][0])
	{
		t=3;
	}
	if(space_time==SetTime[1][1])
	{
		t=5;
	}
	if(space_time==SetTime[1][2])
	{
		t=10;
	}
	if(space_time==SetTime[1][3])
	{
		t=30;
	}
	if(space_time==SetTime[1][4])
	{
		t=60;
	}
	if(space_time==SetTime[1][5])
	{
		t=120;
	}
	if(space_time==SetTime[1][6])
	{
		t=300;
	}

	state=3;

	SetTimer (3,1000*t,NULL);
	
}

void CGPS_FAMDlg::OnManualStart() 
{
	// TODO: Add your control notification handler code here
 	m_Bt_Auto_Mode.EnableWindow(false);
	m_Bt_Stop.EnableWindow(true);

 	m_Bt_Auto_Start.ShowWindow(SW_HIDE);
	
	state=4;
	
	GetGPSinfo();
}

void CGPS_FAMDlg::OnStop() 
{
	// TODO: Add your control notification handler code here
	CloseHandle(hCom);
	CloseHandle(hFileAuto);
	CloseHandle(hFileManual);
	
	m_Bt_Auto_Start.EnableWindow(true);
	m_Bt_Auto_Start.LoadBitmaps(IDB_START_UP);
		
	m_Bt_Restart.EnableWindow(true);
	m_Bt_Auto_Start.EnableWindow(false);
	m_Bt_Manual_Start.EnableWindow(false);
	m_Bt_Stop.EnableWindow(false);

	if(count>2)
	{
		m_Bt_Area.EnableWindow(true);
		m_Bt_Girth.EnableWindow(true);
		m_Bt_Display.EnableWindow(true);
	}

	KillTimer(3);
	KillTimer(4);

}

void CGPS_FAMDlg::OnRestart() 
{
	// TODO: Add your control notification handler code here
	DeleteFile(TEXT("\\ResidentFlash\\Coordinate.txt"));

	m_Bt_Auto_Mode.LoadBitmaps(IDB_AUTO_MODE_UP);
	m_Bt_Manual_Mode.LoadBitmaps(IDB_MANUAL_MODE_UP);
	
	m_Bt_Manual_Mode.EnableWindow(true);
	m_Bt_Auto_Mode.EnableWindow(true);
	m_Bt_Restart.EnableWindow(false);
	m_Bt_Stop.EnableWindow(false);

	m_Bt_Area.EnableWindow(false);
	m_Bt_Girth.EnableWindow(false);
	m_Bt_Display.EnableWindow(false);

	state=0;
	count=0;

	space_time=SetTime[1][0];

	i=1;
	
	m_PointNum="";
	m_Info_1="";
	m_Info_2="";
	m_Info_3="";
	m_Info_4="";

	UpdateData(false);

}

void CGPS_FAMDlg::OnArea() 
{
	// TODO: Add your control notification handler code here
	m_Bt_Restart.EnableWindow(false);
	
	TCHAR *Buffer;
	HANDLE hOpenFile;
	
	hOpenFile=CreateFile(TEXT("\\ResidentFlash\\Coordinate.txt"),GENERIC_READ,0,NULL,OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
	
	if(hOpenFile!=INVALID_HANDLE_VALUE)
	{
		int FileLen=GetFileSize(hOpenFile,NULL);
		
		Buffer=(TCHAR*)calloc(FileLen,sizeof(TCHAR));
		
		DWORD readLen;
		
		ReadFile(hOpenFile,Buffer,FileLen,&readLen,NULL);
	}
		CString GPS_info=Buffer;

		int PointCountArea=0;
	
		for(int i=0;i<GPS_info.GetLength();i++)
		{
			if(GPS_info.GetAt(i)=='P')
			{
				PointCountArea=PointCountArea+1;	
			}
		}
		
		CStringArray strArrayLonDegree;
		CStringArray strArrayLatDegree;
		CStringArray strArrayLonMinute;
		CStringArray strArrayLatMinute;
		CString strLat,LatDegree,LatMinute;
		
		for(int y1=1;y1<GPS_info.GetLength();y1=y1+24)
		{
			strArrayLonDegree.Add(GPS_info.Mid(y1,3));
		}
		
		for(int x1=12;x1<GPS_info.GetLength();x1=x1+24)

⌨️ 快捷键说明

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