📄 gpsview.cpp
字号:
// GPSView.cpp : implementation of the CGPSView class
//
#include "stdafx.h"
#include "GPS.h"
#include "GPSDoc.h"
#include "GPSView.h"
#include "mscomm.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CGPSView
IMPLEMENT_DYNCREATE(CGPSView, CView)
BEGIN_MESSAGE_MAP(CGPSView, CView)
//{{AFX_MSG_MAP(CGPSView)
ON_COMMAND(ID_BUTGPS, OnButgps)
ON_WM_PAINT()
ON_WM_CREATE()
ON_COMMAND(ID_BUTCLOSE, OnButclose)
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CGPSView construction/destruction
CGPSView::CGPSView()
{
// TODO: add construction code here
}
CGPSView::~CGPSView()
{
}
BOOL CGPSView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CGPSView drawing
void CGPSView::OnDraw(CDC* pDC)
{
CGPSDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
}
/////////////////////////////////////////////////////////////////////////////
// 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
{
CView::AssertValid();
}
void CGPSView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CGPSDoc* CGPSView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CGPSDoc)));
return (CGPSDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CGPSView message handlers
void CGPSView::OnButgps()
{
// TODO: Add your command handler code here
m_comm.Create(NULL,0,CRect(0,0,0,0),this,IDC_MSCOMM1);
if(m_comm.GetPortOpen()) //????????,??????
m_comm.SetPortOpen(FALSE);
m_comm.SetCommPort(4); //??COM4
m_comm.SetInBufferSize(1024); //?????
m_comm.SetOutBufferSize(1024);//?????
m_comm.SetInputLen(0);//????????????0,??????
m_comm.SetInputMode(1);//??????????
m_comm.SetRThreshold(1);//??????1??1??????,????????OnComm??
m_comm.SetSettings("38400,n,8,1");//???9600????,8????,1????
if(!m_comm.GetPortOpen())//???????????
m_comm.SetPortOpen(TRUE);//????
else
AfxMessageBox("Open Serial Port Failure!");
m_comm.GetInput(); //?????????????
}
BEGIN_EVENTSINK_MAP(CGPSView, CView)
//{{AFX_EVENTSINK_MAP(CGPSView)
ON_EVENT(CGPSView, IDC_MSCOMM1, 1 /* OnComm */, OnCommMscomm1, VTS_NONE)
//}}AFX_EVENTSINK_MAP
END_EVENTSINK_MAP()
void CGPSView::OnCommMscomm1()
{
// TODO: Add your control notification handler code here
Sleep(500); //视各厂家modem而定。不加则数据接受不全
VARIANT m_input;
char *str,*str1;
int k,nEvent,i,len,m;
CString str2;
m_ReceiveData="";
int MaxL = 100;
nEvent=m_comm.GetCommEvent();
switch(nEvent) {
case 1://数据发送事件
break;
case 2: //收到大于RTHresshold个字符
k=m_comm.GetInBufferCount(); //接收缓冲区的字符数目
if(k>0) {
m_input=m_comm.GetInput();
str=(char*)(unsigned char*)m_input.parray->pvData;
}
i=0; str1=str;
while(i<k) {
i++; str1++;
}
*str1='\0';
str2=(const char*)str; //清除字符串中的不必要字符
m = str2.Find("$GPRMC");
if(m <0 ) break;
m_ReceiveData.Insert(0,"$GPRMC");
i =6;
m = m + 6;
do{
m_ReceiveData.Insert(i,str2[m++]);
}while(m_ReceiveData[i++]!='$' && i < MaxL);
m_ReceiveData.Insert(i,'\n');
//m_ReceiveData=str3;
InvalidateRect(NULL);
break;
case 3: //CTS线状态发生变化
break;
case 4: //DSR线状态发生变化
break;
case 5: //CD线状态发生变化
break;
case 6: //Ring Indicator发生变化
break;
}//switch(nEvent)
}
void CGPSView::OnPaint()
{
CPaintDC dc(this); // device context for painting
// TODO: Add your message handler code here
dc.TextOut(0,0,m_ReceiveData);
// Do not call CView::OnPaint() for painting messages
}
int CGPSView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CView::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: Add your specialized creation code here
return 0;
}
void CGPSView::OnButclose()
{
// TODO: Add your command handler code here
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -