📄 gpsdlg.cpp
字号:
// GPSDlg.cpp : implementation file
//
#include "stdafx.h"
#include "GPS.h"
#include "GPSDlg.h"
#include "stdlib.h"
//#include "string.h"
#include "GPS_Parsor.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)
// NOTE: the ClassWizard will add member initialization here
//}}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)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CGPSDlg, CDialog)
//{{AFX_MSG_MAP(CGPSDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_FILE, OnFile)
ON_BN_CLICKED(IDC_PROCESS, OnProcess)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CGPSDlg message handlers
const char* buf;
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::OnFile()
{
// TODO: Add your control notification handler code here
CString ss;
/* BYTE buffer[0x1000];
try
{
CFile file(_T("File.txt"),CFile::modeReadWrite|CFile::shareDenyNone);
DWORD dwBytesRemaining=file.GetLength();
while(dwBytesRemaining)
{
DWORD dwPosition=file.GetPosition(); //文件中的偏移值
UINT nBytesRead=file.Read(buffer,sizeof(buffer));
::CharLowerBuff((LPTSTR)buffer,nBytesRead);
file.Seek(dwPosition,CFile::begin); //相对于文件起始,的偏移。
file.Write(buffer,nBytesRead);
dwBytesRemaining-=nBytesRead;
}
}
catch(CFileException *e)
{
e->ReportError();
e->Delete();
}*/
try
{
CStdioFile file(_T("GPS.txt"),CFile::modeReadWrite|CFile::shareDenyNone);
while(file.ReadString(ss)) //接口是char *dat;怎么转过去。
{ //TRACE(_T("%s\n"),ss);
buf=(LPSTR)(LPCTSTR)ss;//此buf并不连贯,只能保存单行信息。
if(*(buf+4)=='G')
break;
}
}
catch(CFileException *e)
{
e->ReportError();
e->Delete();
}
TRACE(_T("%s\n"),buf);
GPS_Parsor my_parsor;
TRACE(_T("%s\n"),buf); //为什么到这个函数里面来就没有值了。在哪丢失的。
my_parsor.parse(buf);//buf信息丢失,全局量啊~ 还是const
double l=my_parsor.longitude();
double e=my_parsor.latitude();
double h=my_parsor.height();
double v=my_parsor.velocity();
TRACE(_T("%9.4f\n"),l);
TRACE(_T("%9.4f\n"),e);
TRACE(_T("%5.2f\n"),h);
TRACE(_T("%5.2f\n"),v);
}
void CGPSDlg::OnProcess()
{
// TODO: Add your control notification handler code here
/*GPS_Parsor my_parsor;
TRACE(_T("%s\n"),buf); //为什么到这个函数里面来就没有值了。在哪丢失的。
my_parsor.parse(buf);//buf信息丢失,全局量啊~ 还是const
double l=my_parsor.longitude();
TRACE(_T("%d\n"),l);*/
char *s="3080.0755";
double d=atof(s);
//CString s("abcdefg");
//TRACE(_T("%s\n"),s.Left(2));
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -