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

📄 gpsview.cpp

📁 接受GPGGA语句的VC程序
💻 CPP
字号:
// GPSView.cpp : implementation of the CGPSView class
//

#include "stdafx.h"
#include "GPS.h"

#include "GPSSet.h"
#include "GPSDoc.h"
#include "GPSView.h"
#include "Winio.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CGPSView

IMPLEMENT_DYNCREATE(CGPSView, CRecordView)

BEGIN_MESSAGE_MAP(CGPSView, CRecordView)
	//{{AFX_MSG_MAP(CGPSView)
	ON_BN_CLICKED(IDC_BUTTON_WRITESTATEPORT, OnButtonWritestateport)
	ON_BN_CLICKED(IDC_BUTTON_READSTATEPORT, OnButtonReadstateport)
	ON_WM_TIMER()
	//}}AFX_MSG_MAP
	// Standard printing commands
	ON_COMMAND(ID_FILE_PRINT, CRecordView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_DIRECT, CRecordView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, CRecordView::OnFilePrintPreview)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CGPSView construction/destruction

CGPSView::CGPSView()
	: CRecordView(CGPSView::IDD)
{
	//{{AFX_DATA_INIT(CGPSView)
	m_pSet = NULL;
//	m_CANdata = _T("");
	//}}AFX_DATA_INIT
	// TODO: add construction code here

}

CGPSView::~CGPSView()
{
}

void CGPSView::DoDataExchange(CDataExchange* pDX)
{
	CRecordView::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CGPSView)
	DDX_Control(pDX, IDC_DBGRID1, m_dbGrid);
	DDX_Control(pDX, IDC_REMOTEDATACTL1, m_Rdc);
	DDX_FieldText(pDX, IDC_POSLAT, m_pSet->m_latitude, m_pSet);
	DDX_FieldText(pDX, IDC_POSLONG, m_pSet->m_longitude, m_pSet);
	DDX_FieldText(pDX, IDC_TIME,m_pSet->m_time,m_pSet);
	DDX_FieldText(pDX, IDC_NID, m_pSet->m_ID, m_pSet);
	DDX_FieldText(pDX, IDC_SatellitesUsed, m_pSet->m_SatellitesUsed, m_pSet);
	DDX_FieldText(pDX, IDC_hdop, m_pSet->m_hdop, m_pSet);
    DDX_FieldText(pDX, IDC_Altitude, m_pSet->m_Altitude, m_pSet);
	DDX_FieldText(pDX, IDC_TOUYINGX, m_pSet->m_TX, m_pSet);
	DDX_FieldText(pDX, IDC_TOUYINGY, m_pSet->m_TY, m_pSet);
	DDX_FieldText(pDX, IDC_EDIT2, m_pSet->m_CANdata,m_pSet);
	//}}AFX_DATA_MAP
}

BOOL CGPSView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CRecordView::PreCreateWindow(cs);
}

void CGPSView::OnInitialUpdate()
{
	m_pSet = &GetDocument()->m_GPSSet;
	CRecordView::OnInitialUpdate();
	GetParentFrame()->RecalcLayout();
	ResizeParentToFit();
    InitializeWinIo();
	if(!InitializeWinIo())
	{
		MessageBox("Init fail!");
	}
	//SetIcon(m_hIcon, TRUE);			// Set big icon
	//SetIcon(m_hIcon, FALSE);		// Set small icon
	SetDlgItemText(IDC_EDIT1,"280h");
	SetDlgItemText(IDC_EDIT3,"280h");
	//return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}


/////////////////////////////////////////////////////////////////////////////
// CGPSView printing

BOOL CGPSView::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default preparation
	return DoPreparePrinting(pInfo);
}

void CGPSView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add extra initialization before printing
}

void CGPSView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add cleanup after printing
}

/////////////////////////////////////////////////////////////////////////////
// CGPSView diagnostics

#ifdef _DEBUG
void CGPSView::AssertValid() const
{
	CRecordView::AssertValid();
}

void CGPSView::Dump(CDumpContext& dc) const
{
	CRecordView::Dump(dc);
}

CGPSDoc* CGPSView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CGPSDoc)));
	return (CGPSDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CGPSView database support
CRecordset* CGPSView::OnGetRecordset()
{
	return m_pSet;
}


/////////////////////////////////////////////////////////////////////////////
// CGPSView message handlers

BOOL CGPSView::OnMove(UINT nIDMoveCommand) 
{
	// TODO: Add your specialized code here and/or call the base class
	switch (nIDMoveCommand)
	{
	case ID_RECORD_PREV:
		if (!m_pSet->IsBOF())
		{
			m_pSet->MovePrev();
			
		}
		break;

	case ID_RECORD_FIRST:
		m_pSet->MoveFirst();
		break;

	case ID_RECORD_NEXT:
		if (!m_pSet->IsEOF())
			m_pSet->MoveNext();
		break;
	
		if (!m_pSet->CanScroll())
		{
		// Clear out screen since we're sitting on EOF
			m_pSet->SetFieldNull(NULL);
			break;
		}

	case ID_RECORD_LAST:
		m_pSet->MoveLast();
		break;

	default:
	// unexpected case value
	ASSERT(FALSE);
	}
	
	// show results of move operation
	UpdateData(FALSE);
	return TRUE;	
}

void CGPSView::OnButtonWritestateport() 
{
	// TODO: Add your control notification handler code here
	m_nTimer = SetTimer(1, 3000, 0);
    char ss[10];
	DWORD            dwPortVal;
    unsigned int     ValueGet=0;
    GetDlgItem(IDC_EDIT1)->GetWindowText(ss, 10);
    sscanf(ss, "%x", &ValueGet);
    WORD   m_nport=(WORD)ValueGet;
    GetPortVal(m_nport, &dwPortVal, 1);
    ValueGet=dwPortVal;
	SetDlgItemInt(IDC_EDIT2,ValueGet,true);		
}

void CGPSView::OnButtonReadstateport() 
{
	// TODO: Add your control notification handler code here
    char s[10];
    unsigned int  WriValue=0;

    GetDlgItem(IDC_EDIT3)->GetWindowText(s, 10);
    sscanf(s, "%x", &WriValue);
    WORD  m_nport=(WORD)WriValue;
	
	GetDlgItem(IDC_EDIT4)->GetWindowText(s, 10);
    sscanf(s, "%d", &WriValue);
	DWORD   m_nValue=(DWORD)WriValue;
	
	SetPortVal(m_nport, m_nValue, 1);//write a BYTE value to an I/O port	
}

void CGPSView::OnTimer(UINT nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default
		if(nIDEvent!=1)
		return ;
char ss[10];
	DWORD            dwPortVal;
    unsigned int     ValueGet=0;
    GetDlgItem(IDC_EDIT1)->GetWindowText(ss, 10);
    sscanf(ss, "%x", &ValueGet);
    WORD   m_nport=(WORD)ValueGet;
    GetPortVal(m_nport, &dwPortVal, 1);
    ValueGet=dwPortVal;
	SetDlgItemInt(IDC_EDIT2,ValueGet,true);	
	CRecordView::OnTimer(nIDEvent);
}

⌨️ 快捷键说明

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