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

📄 testgpsdlg.cpp

📁 这是一个简单的软件开发包(SDK)
💻 CPP
字号:
#include "stdafx.h"
#include "TestGPS.h"
#include "TestGPSDlg.h"


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

CTestGPSDlg::CTestGPSDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CTestGPSDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CTestGPSDlg)
	//}}AFX_DATA_INIT
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CTestGPSDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CTestGPSDlg)
	DDX_Control(pDX, IDC_SPEED, m_ctrlSpeed);
	DDX_Control(pDX, IDC_TIME, m_ctrlTime);
	DDX_Control(pDX, IDC_SATELLITES, m_ctrlSatellites);
	DDX_Control(pDX, IDC_QUALITY, m_ctrlQuality);
	DDX_Control(pDX, IDC_LONGITUDE, m_ctrlLongitude);
	DDX_Control(pDX, IDC_LATITUDE, m_ctrlLatitude);
	DDX_Control(pDX, IDC_BEARING, m_ctrlBearing);
	DDX_Control(pDX, IDC_ALTITUDE, m_ctrlAltitude);
	DDX_Control(pDX, IDC_GPSOPEN, m_ctrlOpen);
	DDX_Control(pDX, IDC_GPSCLOSE, m_ctrlClose);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CTestGPSDlg, CDialog)
	//{{AFX_MSG_MAP(CTestGPSDlg)
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_SHOWSETUP, OnShowSetup)
	ON_BN_CLICKED(IDC_GPSCLOSE, OnGpsClose)
	ON_BN_CLICKED(IDC_GPSOPEN, OnGpsOpen)
	ON_WM_TIMER()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

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

	SetIcon(m_hIcon, TRUE);
	SetIcon(m_hIcon, FALSE);
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

// 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 CTestGPSDlg::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 CTestGPSDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CTestGPSDlg::OnShowSetup() 
{
  GpsShowControlPanel();
}

void CTestGPSDlg::OnGpsClose() 
{
  KillTimer(m_nTimerID);

	m_ctrlOpen.EnableWindow(TRUE);
  m_ctrlClose.EnableWindow(FALSE);

	EnableGpsPositionControl(FALSE);

  if (!GpsClose(m_hGps))
    AfxMessageBox(_T("Failed in Call to GpsClose"));
}

void CTestGPSDlg::OnGpsOpen() 
{
  m_hGps = GpsOpen(NULL);
  if (m_hGps != INVALID_HANDLE_VALUE)
  {
	  m_ctrlOpen.EnableWindow(FALSE);
    m_ctrlClose.EnableWindow(TRUE);	

    EnableGpsPositionControl(TRUE);

    m_nTimerID = SetTimer(1, 2000, NULL);
  }
  else
    AfxMessageBox(_T("Failed in call to GpsOpen"));
}

void CTestGPSDlg::OnTimer(UINT /*nIDEvent*/) 
{
  GPSPOSITION gpsPos;
  if (GpsGetPosition(m_hGps, &gpsPos))
  {
    //display the latitude
    int nDegrees = gpsPos.dwLatitude/360000;
    int nMinutes = (gpsPos.dwLatitude - nDegrees*360000)/6000;
    int nSeconds = (gpsPos.dwLatitude - nDegrees*360000 - nMinutes*6000)/100;
    CString sText;
    if (gpsPos.bNorthing)
      sText.Format(_T("%d,%d,%d N"), nDegrees, nMinutes, nSeconds);
    else
      sText.Format(_T("%d,%d,%d S"), nDegrees, nMinutes, nSeconds);
    m_ctrlLatitude.SetWindowText(sText);

    //display the longitude
    nDegrees = gpsPos.dwLongitude/360000;
    nMinutes = (gpsPos.dwLongitude - nDegrees*360000)/6000;
    nSeconds = (gpsPos.dwLongitude - nDegrees*360000 - nMinutes*6000)/100;
    if (gpsPos.bEasting)
      sText.Format(_T("%d,%d,%d E"), nDegrees, nMinutes, nSeconds);
    else
      sText.Format(_T("%d,%d,%d W"), nDegrees, nMinutes, nSeconds);
    m_ctrlLongitude.SetWindowText(sText);

    //display the number of satellites
    sText.Format(_T("%d"), gpsPos.nSatellites);
    m_ctrlSatellites.SetWindowText(sText);

    //display the altitude
    sText.Format(_T("%d Centimeters"), gpsPos.dwAntennaAltitude);
    m_ctrlAltitude.SetWindowText(sText);

    //display the number of speed
    sText.Format(_T("%d cm/Hour"), gpsPos.dwSpeed);
    m_ctrlSpeed.SetWindowText(sText);

    //display the Quality indicator
    sText.Format(_T("%d"), gpsPos.wQualityIndicator);
    m_ctrlQuality.SetWindowText(sText);

    //display the bearing
    nDegrees = gpsPos.dwBearing/100;
    nMinutes = (gpsPos.dwBearing - nDegrees*100)/100;
    nSeconds = (gpsPos.dwBearing - nDegrees*100 - nMinutes*100/60);
    sText.Format(_T("%d,%d,%d East of North"), nDegrees, nMinutes, nSeconds);
    m_ctrlBearing.SetWindowText(sText);

    //display the time of fix
    SYSTEMTIME st;
    st.wYear         = gpsPos.wFixYear;
    st.wMonth        = gpsPos.wFixMonth;
    st.wDayOfWeek    = 0;
    st.wDay          = gpsPos.wFixDay;
    st.wHour         = gpsPos.wFixHour;
    st.wMinute       = gpsPos.wFixMinute;
    st.wSecond       = gpsPos.wFixSecond;
    st.wMilliseconds = 0;
    COleDateTime t(st);
    sText = t.Format();
    m_ctrlTime.SetWindowText(sText);
  }
}


void CTestGPSDlg::EnableGpsPositionControl(BOOL bEnable)
{
	m_ctrlSpeed.EnableWindow(bEnable);
	m_ctrlTime.EnableWindow(bEnable);
	m_ctrlSatellites.EnableWindow(bEnable);
	m_ctrlQuality.EnableWindow(bEnable);
	m_ctrlLongitude.EnableWindow(bEnable);
	m_ctrlLatitude.EnableWindow(bEnable);
	m_ctrlBearing.EnableWindow(bEnable);
	m_ctrlAltitude.EnableWindow(bEnable);
  GetDlgItem(IDC_PROMPT_SPEED)->EnableWindow(bEnable);
	GetDlgItem(IDC_PROMPT_TIME)->EnableWindow(bEnable);
	GetDlgItem(IDC_PROMPT_SATELLITES)->EnableWindow(bEnable);
	GetDlgItem(IDC_PROMPT_QUALITY)->EnableWindow(bEnable);
	GetDlgItem(IDC_PROMPT_LONGITUDE)->EnableWindow(bEnable);
	GetDlgItem(IDC_PROMPT_LATITUDE)->EnableWindow(bEnable);
	GetDlgItem(IDC_PROMPT_BEARING)->EnableWindow(bEnable);
	GetDlgItem(IDC_PROMPT_ALTITUDE)->EnableWindow(bEnable);

	m_ctrlSpeed.SetWindowText(_T(""));
	m_ctrlTime.SetWindowText(_T(""));
	m_ctrlSatellites.SetWindowText(_T(""));
	m_ctrlQuality.SetWindowText(_T(""));
	m_ctrlLongitude.SetWindowText(_T(""));
	m_ctrlLatitude.SetWindowText(_T(""));
	m_ctrlBearing.SetWindowText(_T(""));
	m_ctrlAltitude.SetWindowText(_T(""));
}

⌨️ 快捷键说明

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