www.pudn.com > gp.rar > gpDlg.cpp
// gpDlg.cpp : implementation file
//
#include "stdafx.h"
#include "gp.h"
#include "gpDlg.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();
CMSComm m_MSComm;
// 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()
/////////////////////////////////////////////////////////////////////////////
// CGpDlg dialog
CGpDlg::CGpDlg(CWnd* pParent /*=NULL*/)
: CDialog(CGpDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CGpDlg)
m_MSEditRXData = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CGpDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CGpDlg)
DDX_Control(pDX, IDC_MSCOMM1, m_MSComm);
DDX_Text(pDX, IDC_EDIT_DATA, m_MSEditRXData);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CGpDlg, CDialog)
//{{AFX_MSG_MAP(CGpDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CGpDlg message handlers
BOOL CGpDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
m_MSComm.SetCommPort(1);//设置串口1
if (!m_MSComm.GetPortOpen())//如果串口关闭,则打开
{ m_MSComm.SetPortOpen(TRUE);
m_MSComm.SetSettings("4800,N,8,1");//设置串口通信参数
m_MSComm.SetInputMode(1);//收发二进制型数据
m_MSComm.SetInputLen(0);//设置初始长度
m_MSComm.SetRThreshold(140);//140 个字符引发一个事件
}
if (m_MSComm.GetPortOpen()) //如果串口打开,则关闭
{
m_MSComm.SetPortOpen(false);
}
// 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 CGpDlg::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 CGpDlg::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 CGpDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
BEGIN_EVENTSINK_MAP(CGpDlg, CDialog)
//{{AFX_EVENTSINK_MAP(CGpDlg)
ON_EVENT(CGpDlg, IDC_MSCOMM1, 1 /* OnComm */, OnOnComm, VTS_NONE)
//}}AFX_EVENTSINK_MAP
END_EVENTSINK_MAP()
void CGpDlg::OnOnComm() //编写事件驱动函数OnComm ( ) ,读取GPS数据:
{
// TODO: Add your control notification handler code here
VARIANT m_varInput;
COleSafeArray m_oleInput;
LONG length,i;
BYTE data[1024];
CString str;
if (m_MSComm.GetCommEvent()==2)//是接收到字符事件,则读取缓冲区数据
{m_varInput=m_MSComm.GetInput();//读取数据
m_oleInput=m_varInput;//类型转换
length=m_oleInput.GetOneDimSize();//得到字符串长度
for(i=0;iendCR)
{ endCR=m_MSEditRXData.Find(0x0d,starLF);
//复制这一句GPS语句,并从接受缓冲区中删除从上一句结束标志LF到本句结束/ /标志CR间的数据
CString msg=m_MSEditRXData.Mid(starLF+1,endCR-starLF-1);
m_MSEditRXData.Delete(0,endCR+1);
//判断是否GPGGA定位语句,若不是则返回,否则删除“$GPGGA”
if (msg.Left(6).Compare("$GPGGA")!=0)
{return;
msg.Delete(0,msg.Find(":")+1);
CString latidegree=msg.Left(2);
CString laticent=msg.Mid(2,7); // mid表示从CString中第二个字符开始copy7个
double latitude=(atof(latidegree)+atof(laticent)/60.0);
msg.Delete(0,msg.Find(',')+1);
msg.Delete(0,msg.Find(',')+1);
//获取经度信息
CString longidegree=msg.Left(3);
CString longicent=msg.Mid(3,7);
double longitude=(atof(longidegree)+atof(longicent)/60.0);
msg.Delete(0,msg.Find(',')+1); //find是找到","所在的位置n, delete从位置0开始删去n+1个字符
msg.Delete(0,msg.Find(',')+1); //返回修改后的字符串长度
msg.Delete(0,msg.Find(',')+1);
msg.Delete(0,msg.Find(',')+1);
msg.Delete(0,msg.Find(',')+1);
//获取高度信息
CString height=msg.Left(7);
double high=atof(height);
/*//对纬度信息进行截取
CString latitude=msg.Left(2);
latitude+="度";
//latitude+=msg.Mid(2,6);
//latitude+="分";
msg.Delete(0,msg.Find(":")+1);
if (msg.GetAt(0)=='N')
{latitude.Insert(0,"北纬");}
if (msg.GetAt(0)=='S')
{latitude.Insert(0,"南纬");}
msg.Delete(0,msg.Find(":")+1);
_RecordsetPtr rst;
IDC_weidu=rst->GetCollect("eno").latitude;*/
}}}}}
}