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

📄 mygpsdlg.cpp

📁 Visual C++编写的串口GPS数据采集软件
💻 CPP
字号:
// myGPSDlg.cpp : implementation file
//

#include "stdafx.h"
#include "myGPS.h"
#include "myGPSDlg.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()

/////////////////////////////////////////////////////////////////////////////
// CMyGPSDlg dialog

CMyGPSDlg::CMyGPSDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CMyGPSDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CMyGPSDlg)
	m_year = _T("");
	m_month = _T("");
	m_date = _T("");
	m_minute = _T("");
	m_second = _T("");
	m_hour = _T("");
	m_comdata = _T("");
	m_jd = _T("");
	m_wd = _T("");
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CMyGPSDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CMyGPSDlg)
	DDX_Control(pDX, IDC_MSCOMM1, m_com);
	DDX_Text(pDX, IDC_EDIT1, m_year);
	DDX_Text(pDX, IDC_EDIT2, m_month);
	DDX_Text(pDX, IDC_EDIT3, m_date);
	DDX_Text(pDX, IDC_EDIT5, m_minute);
	DDX_Text(pDX, IDC_EDIT6, m_second);
	DDX_Text(pDX, IDC_EDIT4, m_hour);
	DDX_Text(pDX, IDC_EDIT7, m_comdata);
	DDX_Text(pDX, IDC_EDIT8, m_jd);
	DDX_Text(pDX, IDC_EDIT9, m_wd);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CMyGPSDlg, CDialog)
	//{{AFX_MSG_MAP(CMyGPSDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMyGPSDlg message handlers

BOOL CMyGPSDlg::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
	if( !m_com.GetPortOpen())
		m_com.SetPortOpen(TRUE);//打开串口
	

	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

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

BEGIN_EVENTSINK_MAP(CMyGPSDlg, CDialog)
    //{{AFX_EVENTSINK_MAP(CMyGPSDlg)
	ON_EVENT(CMyGPSDlg, IDC_MSCOMM1, 1 /* OnComm */, OnComm, VTS_NONE)
	//}}AFX_EVENTSINK_MAP
END_EVENTSINK_MAP()
 
CString str1;
void CMyGPSDlg::OnComm() 
{
	// TODO: Add your control notification handler code here
	VARIANT m_input1;
	COleSafeArray m_input2;
	LONG length,i;
	BYTE data[100]; 
	char chr;
	CString str;
	
	//接受缓冲区内字符
	if(m_com.GetCommEvent()==2)
	{
		m_input1=m_com.GetInput();
		m_input2=m_input1;
		length=m_input2.GetOneDimSize();
		
		for(i=0;i<length;i++)
		{
			m_input2.GetElement(&i,data+i);
     		chr=*(char*)(data+i);
		    str+=chr;
			
		}
		str1+=str;
		UpdateData(FALSE);
		int s2=str1.Find("$PRWIZCH,");
		int s1=str1.Find("$GPRMC,");
		
		if(((s2-s1)==68))
		{
			m_comdata.Empty();
            m_comdata=str1.Mid(s1,68);
			CString m_gps;
		    m_gps=str1.Mid(s1,68);//将信号赋给m_gps
			

			hhh=m_gps.Mid(7,2);//
			temp=atoi(hhh);
			//temp=(temp+8)%24;
			hour=temp;
			
            mmm=m_gps.Mid(9,2);//
			minute=atoi(mmm);

            sss=m_gps.Mid(11,2);//
			second=atoi(sss);

			yy=m_gps.Mid(55,2);
		    year=atoi(yy);
			year=2000+year;
			
			mm=m_gps.Mid(53,2);//
			month=atoi(mm);

		    dd=m_gps.Mid(51,2);//
			date=atoi(dd);

			m_wd="北纬"+m_gps.Mid(16,2)+"度"+m_gps.Mid(18,2)+"分"+m_gps.Mid(21,4)+"秒";//
			m_jd="东经"+m_gps.Mid(28,3)+"度"+m_gps.Mid(31,2)+"分"+m_gps.Mid(34,4)+"秒";//
				
			m_hour.Format("%d",hour);
	        m_minute.Format("%d",minute);
	        m_second.Format("%d",second);
			    
	        m_year.Format("%d",year);
	        m_month.Format("%d",month);
	        m_date.Format("%d",date);

			//设定本地时钟
			SYSTEMTIME td;
			GetSystemTime(&td);
			td.wYear=(WORD)year;
			td.wMonth=(WORD)month;
			td.wDay=(WORD)date;
			td.wDayOfWeek=6;
			td.wHour=(WORD)hour;
			td.wMinute=(WORD)minute;
			td.wSecond=(WORD)second;
			SystemTimeToTzSpecificLocalTime(NULL,&td,&td);
			SetLocalTime(&td);
			
			str1.Empty();
	        UpdateData(FALSE);
		}		 		      
	}	
}




⌨️ 快捷键说明

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