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

📄 gpsdlg.cpp

📁 对于给定的GPS接收信号
💻 CPP
字号:
// GPSDlg.cpp : implementation file
//

#include "stdafx.h"
#include "GPS.h"
#include "GPSDlg.h"
#include "iostream.h"
#include "SplitStr.h"
#include <windows.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
		// No message handlers
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CGPSDlg dialog

CGPSDlg::CGPSDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CGPSDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CGPSDlg)
	m_Message = _T("");
	m_State = _T("");
	m_Time = _T("");
	m_Vate = _T("");
	m_Long = _T("");
	m_Direction = _T("");
	m_Lat = _T("");
	m_Date = _T("");
	m_InfoStyle = _T("");
	m_LatState = _T("");
	m_LongState = _T("");
	m_Nmea = _T("");
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CGPSDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CGPSDlg)
	DDX_Text(pDX, IDC_EDIT2, m_Message);
	DDX_Text(pDX, IDC_EDIT4, m_State);
	DDX_Text(pDX, IDC_EDIT3, m_Time);
	DDX_Text(pDX, IDC_EDIT5, m_Vate);
	DDX_Text(pDX, IDC_EDIT6, m_Long);
	DDX_Text(pDX, IDC_EDIT7, m_Direction);
	DDX_Text(pDX, IDC_EDIT8, m_Lat);
	DDX_Text(pDX, IDC_EDIT9, m_Date);
	DDX_Text(pDX, IDC_info, m_InfoStyle);
	DDX_Text(pDX, IDC_LATSTATE, m_LatState);
	DDX_Text(pDX, IDC_LongState, m_LongState);
	DDX_Text(pDX, IDC_NMEA, m_Nmea);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CGPSDlg, CDialog)
	//{{AFX_MSG_MAP(CGPSDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_EN_CHANGE(IDC_EDIT2, OnMessage)
	ON_EN_CHANGE(IDC_EDIT3, OnTime)
	ON_EN_CHANGE(IDC_EDIT4, OnState)
	ON_EN_CHANGE(IDC_EDIT8, OnLat)
	ON_EN_CHANGE(IDC_EDIT6, OnLong)
	ON_BN_CLICKED(IDC_LOCATION, OnLocation)
	ON_BN_CLICKED(IDC_Reset, OnReset)
	ON_BN_CLICKED(IDC_CANCLE2, OnCancle2)
	ON_WM_TIMER()
	ON_BN_CLICKED(IDC_BUTTON1, OnStop)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CGPSDlg message handlers

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

	// Add "About..." menu item to system menu.

	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// 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
	
	// TODO: Add extra initialization here
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CGPSDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CGPSDlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CGPSDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CGPSDlg::OnMessage() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
//	m_Message="12";
	UpdateWindow();
}

/*void CGPSDlg::OnEditchangeCombo1() 
{
	// TODO: Add your control notification handler code here
	
}
*/
void CGPSDlg::OnTime() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
//	m_Time=123.8;
	UpdateData(FALSE);	
}

void CGPSDlg::OnState() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here

}

void CGPSDlg::OnLat() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	
}

void CGPSDlg::OnLong() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	
}

void CGPSDlg::OnLocation() 
{
	// TODO: Add your control notification handler code here
//	SetTimer(1,1000,NULL);
//	CStdioFile F("fakegpsdata.txt",CFile::modeReadWrite| CFile::modeWrite );
	SetTimer(1,1000,NULL);
	File.Open("fakegpsdata.txt",CFile::modeReadWrite|CFile::modeNoTruncate);
/*	m_Nmea="$GPRMC";
	m_Message="$GPRMC,191934.767,A,4738.0173,N,12211.1874,W,0.109623,12.14,291004,,*21";
	m_Time="19时19分34.767秒";
	m_State="有效";
	m_Lat="北纬47度38分0.0173秒";
	m_Long="西经122度11分0.1874秒";
	m_Vate="0.109632节";
	m_Direction="北方12.14度";
	m_Date="04年10月29日";
	UpdateData(FALSE);*/
}


/*void CGPSDlg::OnCancle() 
{
	// TODO: Add your control notification handler code here
	UpdateData(true);
}
*/
void CGPSDlg::OnReset() 
{
	// TODO: Add your control notification handler code here
	m_Nmea="";
	m_Message="";
	m_Time="";
	m_State="";
	m_LatState="";
	m_LongState="";
	m_Lat="";
	m_Long="";
	m_Vate="";
	m_Direction="";
	m_Date="";
	UpdateData(FALSE);	
}

void CGPSDlg::OnCancle2() 
{
	// TODO: Add your control notification handler code here
	CDialog::OnCancel();
}

void CGPSDlg::OnTimer(UINT nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default
	CSplitStr split;
	CString buffString;
	File.ReadString(buffString);
	split.SetSplitFlag(",");
	split.SetSequenceAsOne(TRUE);
	split.SetData(buffString);
	CStringArray array;
	split.GetSplitStrArray(array);
	UpdateData(TRUE);
	m_InfoStyle=m_Lat=m_LatState=m_Long=m_LongState=m_Time=
		m_InfoStyle=m_Time=m_State=m_Lat=m_Long=m_LatState=
		m_LongState=m_Direction=m_InfoStyle=buffString;//=m_Model=m_LocStyle=m_StatNum=m_PDOP=
		//m_HDOP=m_VDOP=m_InfoStyle=m_SatTotalNum=m_TotalNum=m_GSVIndex=m_PRN=m_SatAngle=m_Azimuth=m_SNR="";
//	m_GPSInfo=buffString;
	//////////////////////////////////////////////////////////////////////////
	if (array[0]=="$GPRMC") 
	{
		m_InfoStyle="推荐定位信息";
		m_Nmea="$GPRMC";
		m_Message=buffString;
		m_Time=array[1];
		if (array[2]=="A")
		{
			m_State="定位有效";
		}
		else
		{
			m_State="定位无效";
		}
		m_Lat=array[3];
		if (array[4]=="N")
		{
			m_LatState="北纬";
		}
		else
		{
			m_LatState="南纬";
		}
		m_Long=array[5];
		if (array[6]=="W")
		{
			m_LongState="西经";
		}
		else
		{
			m_LongState="东经";
		}
		m_Vate=array[7];
		m_Direction=array[8];
		m_Date=array[9];
			
		UpdateData(FALSE);
	}
	//////////////////////////////////////////////////////////////////////////
	if (array[0]=="$GPGLL")
	{
		m_InfoStyle="定位地理信息";
		m_Nmea="$GPGLL";
		m_Message=buffString;
		m_Lat=array[1];
		m_State="无";
		m_Direction="无";
		if (array[2]=="N")
		{
			m_LatState="北纬";
		}
		else
		{
			m_LatState="南纬";
		}
		m_Long=array[3];
		if (array[4]=="W")
		{
			m_LongState="西经";
		}
		else
		{
			m_LongState="东经";
		}
		m_Time=array[5];
		m_Vate="无";
		m_Date="无";
		UpdateData(FALSE);
		SetTimer(1,1000,NULL);
	}
	//////////////////////////////////////////////////////////////////////////
/*	if (array[0]=="$GPGSA") 
	{
//		m_InfoStyle="当前卫星信息";
		if (array[1]=="A")
		{
			m_Model="自动";
		}
		else
		{
			m_Model="手动";
		}
		if (array[2]=="1")
		{
			m_LocStyle="没有定位";
		}
		if (array[2]=="2") 
		{
			m_LocStyle="2D定位";
		}
		else
		{
			m_LocStyle="3D定位";
		}
		CString SatNum=array[3]+","+array[4]+","+array[5]+","+array[6]+","+array[7]+","+array[8];
		m_StatNum=SatNum;
		m_PDOP=array[9];
		m_HDOP=array[10];
		m_VDOP=array[11];
		UpdateData(FALSE);		
	}*/
	//////////////////////////////////////////////////////////////////////////
/*	if (array[0]=="$GPGSV")
	{
//		m_InfoStyle="可见卫星信息";
		m_TotalNum=array[1];
		m_GSVIndex=array[2];
		m_SatTotalNum=array[3];
		m_PRN=array[4];
		m_SatAngle=array[5];
		m_Azimuth=array[6];
		m_SNR=array[7];
		UpdateData(FALSE);	 	
	}*/
	CDialog::OnTimer(nIDEvent);

}

void CGPSDlg::OnStop() 
{
	// TODO: Add your control notification handler code here
	KillTimer(1);
}

⌨️ 快捷键说明

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