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

📄 gpsguider1v0view.cpp

📁 gps信号测试程序
💻 CPP
字号:
// GPSGuider1V0View.cpp : implementation of the CGPSGuider1V0View class
//

#include "stdafx.h"
#include "GPSGuider1V0.h"

#include "GPSGuider1V0Doc.h"
#include "GPSGuider1V0View.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

extern WORD ShowMap;
extern BOOL Fixed;
extern TIMESEUIC Time;
extern DATESEUIC Date;
extern LONGITUDESEUIC Longitude;
extern LATITUDESEUIC Latitude;
extern SATELLITEINFOARRAYSEUIC Satellite;
//extern CRITICAL_SECTION cs;

/////////////////////////////////////////////////////////////////////////////
// CGPSGuider1V0View

IMPLEMENT_DYNCREATE(CGPSGuider1V0View, CView)

BEGIN_MESSAGE_MAP(CGPSGuider1V0View, CView)
	//{{AFX_MSG_MAP(CGPSGuider1V0View)
	ON_WM_TIMER()
	ON_COMMAND(ID_SHOWMAP, OnShowmap)
	ON_UPDATE_COMMAND_UI(ID_SHOWMAP, OnUpdateShowmap)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CGPSGuider1V0View construction/destruction

CGPSGuider1V0View::CGPSGuider1V0View()
{
	// TODO: add construction code here
	m_TimeCounter=0;
	m_TimeFlag=TRUE;
	m_Point.Offset(0,0);
}

CGPSGuider1V0View::~CGPSGuider1V0View()
{
}

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

	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CGPSGuider1V0View drawing

void CGPSGuider1V0View::OnDraw(CDC* pDC)
{
	CGPSGuider1V0Doc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);

	// TODO: add draw code for native data here
	int i,j;
	CRect rect;
	CString show;
	CPoint point;
	CPen pen;
	CPen* pOldPen;

	switch(::ShowMap)
	{
		case 0:
			if(!pen.CreatePen(PS_SOLID,2,RGB(120,120,0)))
				return;
			pOldPen=pDC->SelectObject(&pen);
			rect.SetRect(5,5,130,130);
			pDC->Ellipse(&rect);
			pDC->SelectObject(pOldPen);

			rect.SetRect(135,5,235,20);	//0,0,235,265
			pDC->DrawText(_T("Date:"),&rect,DT_LEFT|DT_TOP);
			rect.SetRect(135,20,235,35);
			show.Format(_T(" 20%s/%s/%s"),::Date.year,::Date.month,::Date.date);
			pDC->DrawText(show,&rect,DT_LEFT|DT_TOP);
			rect.SetRect(135,35,235,50);
			pDC->DrawText(_T("Time:"),&rect,DT_LEFT|DT_TOP);
			rect.SetRect(135,50,235,65);
			show.Format(_T(" %s:%s:%s"),::Time.hour,::Time.minute,::Time.second);
			pDC->DrawText(show,&rect,DT_LEFT|DT_TOP);

			rect.SetRect(135,75,235,90);
			pDC->DrawText(_T("Longitude:"),&rect,DT_LEFT|DT_TOP);	//经度
			rect.SetRect(135,90,235,105);
			show.Format(_T(" %s %3d\'%2d\'%2d.%3d\'\'"),::Longitude.direction,::Longitude.degree,::Longitude.minute,::Longitude.secondinteger,::Longitude.secondportion);
			pDC->DrawText(show,&rect,DT_LEFT|DT_TOP);
			rect.SetRect(135,105,235,120);
			pDC->DrawText(_T("Latitude:"),&rect,DT_LEFT|DT_TOP);	//纬度
			rect.SetRect(135,120,235,135);
			show.Format(_T(" %s %2d\'%2d\'%2d.%3d\'\'"),::Latitude.direction,::Latitude.degree,::Latitude.minute,::Latitude.secondinteger,::Latitude.secondportion);
			pDC->DrawText(show,&rect,DT_LEFT|DT_TOP);

			rect.SetRect(135,145,235,190);
			pDC->DrawText(_T("Acquiring:"),&rect,DT_LEFT|DT_TOP);
			rect.SetRect(135,160,235,215);
			if(::Fixed)
			{
				show.Format(_T("      Fixed "));
			}
			else
			{
				show.Format(_T("      No Fix"));
			}
			pDC->DrawText(show,&rect,DT_LEFT|DT_TOP);

			if(!pen.CreatePen(PS_SOLID,2,RGB(0,120,0)))
				return;
			pOldPen=pDC->SelectObject(&pen);
			for(i=0;i<::Satellite.satellitenum;i++)
			{
				rect.SetRect(5+i*19,242-(65*(::Satellite.satelliteinfoarray[i].snr))/100,21+i*19,242);
				pDC->Rectangle(&rect);

				rect.SetRect(5+i*19,242-(65*(::Satellite.satelliteinfoarray[i].snr))/100-15,21+i*19,242-(65*(::Satellite.satelliteinfoarray[i].snr))/100-2);
				show.Format(_T("%c%c"),(::Satellite.satelliteinfoarray[i].snr/10)+48,(::Satellite.satelliteinfoarray[i].snr%10)+48);
				pDC->DrawText(show,&rect,DT_LEFT|DT_TOP);

				rect.SetRect(5+i*19,245,21+i*19,260);
				show.Format(_T("%c%c"),(::Satellite.satelliteinfoarray[i].id/10)+48,(::Satellite.satelliteinfoarray[i].id%10)+48);
				pDC->DrawText(show,&rect,DT_LEFT|DT_TOP);
			}
			pDC->SelectObject(pOldPen);

			break;
		case 1:
			switch(pDoc->m_BitMapInfo.bmiHeader.biBitCount)
			{
				case 24:
					for(i=0;i<pDoc->m_BitMapInfo.bmiHeader.biHeight;i++)
					{
						for(j=0;j<pDoc->m_BitMapInfo.bmiHeader.biWidth;j++)
						{
							point.y=pDoc->m_BitMapInfo.bmiHeader.biHeight-i-1;
							point.x=j;
							pDC->SetPixel(point,RGB(pDoc->m_pPels[i*pDoc->m_RowNum+3*j+2],pDoc->m_pPels[i*pDoc->m_RowNum+3*j+1],pDoc->m_pPels[i*pDoc->m_RowNum+3*j]));
						}
					}
					break;
				default:
					;
			}
			break;
		case 2:
			rect.SetRect(0,0,235,265);
			pDC->DrawText(_T("Opening the GPS Port...\nPlease wait!"),&rect,DT_LEFT|DT_TOP);
			break;
		default:
			;
	}
}

/////////////////////////////////////////////////////////////////////////////
// CGPSGuider1V0View diagnostics

#ifdef _DEBUG
void CGPSGuider1V0View::AssertValid() const
{
	CView::AssertValid();
}

void CGPSGuider1V0View::Dump(CDumpContext& dc) const
{
	CView::Dump(dc);
}

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

/////////////////////////////////////////////////////////////////////////////
// CGPSGuider1V0View message handlers

void CGPSGuider1V0View::OnInitialUpdate() 
{
	CView::OnInitialUpdate();
	
	// TODO: Add your specialized code here and/or call the base class
	SetTimer(1,1000,NULL);
	m_Point.x=0;	//读入初始坐标值
	m_Point.y=0;
}

void CGPSGuider1V0View::OnTimer(UINT nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default
//	EnterCriticalSection(&cs);

	CGPSGuider1V0Doc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	int i,j;
	CPen pen;
	CPen* pOldPen;
	CRect rect;
	CPoint point;
	CString show;
	CClientDC dc(this);
	m_TimeCounter++;
	if(m_TimeCounter==100)
		m_TimeCounter=0;
	if(::ShowMap)
	{
		m_TimeFlag=!m_TimeFlag;
		if(m_TimeFlag)
		{
			m_Point.x=47+(::Longitude.totalsecond-2769)*(111-47)/(2853-2769);	//读入新坐标值
			m_Point.y=157+(::Latitude.totalsecond-77)*(28-157)/(210-77);

			CBrush Brush;
			CBrush* pOldBrush;
			if(!Brush.CreateSolidBrush(RGB(255,0,0)))
				return;
			pOldBrush=dc.SelectObject(&Brush);
			CPen Pen;
			CPen* pOldPen;
			if(!Pen.CreatePen(PS_SOLID,2,RGB(0,0,0)))
				return;
			pOldPen=dc.SelectObject(&Pen);
			rect.SetRect(m_Point.x-3,m_Point.y-3,m_Point.x+3,m_Point.y+3);
			dc.Ellipse(&rect);
			dc.SelectObject(pOldBrush);
			dc.SelectObject(pOldPen);
		}
		else
		{
			if(m_Point.y>2&&m_Point.y<(pDoc->m_BitMapInfo.bmiHeader.biHeight-3)&&m_Point.x>2&&m_Point.x<(pDoc->m_BitMapInfo.bmiHeader.biWidth-3))
			{
				for(i=m_Point.y-3;i<m_Point.y+3;i++)
				{
					for(j=m_Point.x-3;j<m_Point.x+3;j++)
					{
						point.y=i;;
						point.x=j;
						if(!pDoc->m_PelsNew)
						{
							dc.SetPixel(point,RGB(pDoc->m_pPels[(pDoc->m_BitMapInfo.bmiHeader.biHeight-i-1)*pDoc->m_RowNum+3*j+2],pDoc->m_pPels[(pDoc->m_BitMapInfo.bmiHeader.biHeight-i-1)*pDoc->m_RowNum+3*j+1],pDoc->m_pPels[(pDoc->m_BitMapInfo.bmiHeader.biHeight-i-1)*pDoc->m_RowNum+3*j]));
						}
					}
				}
			}
		}
	}
	else
	{
		rect.SetRect(135,20,235,35);
		show.Format(_T(" 20%s/%s/%s"),::Date.year,::Date.month,::Date.date);
		dc.DrawText(show,&rect,DT_LEFT|DT_TOP);
		rect.SetRect(135,50,235,65);
		show.Format(_T(" %s:%s:%s"),::Time.hour,::Time.minute,::Time.second);
		dc.DrawText(show,&rect,DT_LEFT|DT_TOP);
		rect.SetRect(135,90,235,105);
		show.Format(_T(" %s %3d\'%2d\'%2d.%3d\'\'"),::Longitude.direction,::Longitude.degree,::Longitude.minute,::Longitude.secondinteger,::Longitude.secondportion);
		dc.DrawText(show,&rect,DT_LEFT|DT_TOP);
		rect.SetRect(135,120,235,135);
		show.Format(_T(" %s %2d\'%2d\'%2d.%3d\'\'"),::Latitude.direction,::Latitude.degree,::Latitude.minute,::Latitude.secondinteger,::Latitude.secondportion);
		dc.DrawText(show,&rect,DT_LEFT|DT_TOP);
		rect.SetRect(135,160,235,215);
		if(::Fixed)
		{
			show.Format(_T("      Fixed "));
		}
		else
		{
			show.Format(_T("      No Fix"));
		}
		dc.DrawText(show,&rect,DT_LEFT|DT_TOP);

		if(!pen.CreatePen(PS_SOLID,2,RGB(0,120,0)))
			return;
		pOldPen=dc.SelectObject(&pen);
		for(i=0;i<::Satellite.satellitenum;i++)
		{
			rect.SetRect(5+i*19,242-(65*(::Satellite.satelliteinfoarray[i].snr))/100,21+i*19,242);
			dc.Rectangle(&rect);
			
			rect.SetRect(5+i*19,242-(65*(::Satellite.satelliteinfoarray[i].snr))/100-15,21+i*19,242-(65*(::Satellite.satelliteinfoarray[i].snr))/100-2);
			show.Format(_T("%c%c"),(::Satellite.satelliteinfoarray[i].snr/10)+48,(::Satellite.satelliteinfoarray[i].snr%10)+48);
			dc.DrawText(show,&rect,DT_LEFT|DT_TOP);
			
			rect.SetRect(5+i*19,245,21+i*19,260);
			show.Format(_T("%c%c"),(::Satellite.satelliteinfoarray[i].id/10)+48,(::Satellite.satelliteinfoarray[i].id%10)+48);
			dc.DrawText(show,&rect,DT_LEFT|DT_TOP);
		}
		dc.SelectObject(pOldPen);
	}

//	LeaveCriticalSection(&cs);
	
	CView::OnTimer(nIDEvent);
}

void CGPSGuider1V0View::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint) 
{
	// TODO: Add your specialized code here and/or call the base class
	Invalidate(TRUE);
	return;
}

void CGPSGuider1V0View::OnShowmap() 
{
	// TODO: Add your command handler code here
	::ShowMap=!::ShowMap;
	Invalidate(TRUE);	
}

void CGPSGuider1V0View::OnUpdateShowmap(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->SetCheck(::ShowMap);	
}

⌨️ 快捷键说明

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