📄 gpstestview.cpp
字号:
// GPStestView.cpp : implementation of the CGPStestView class
//
#include "stdafx.h"
#include "GPStest.h"
#include "GPStestDoc.h"
#include "GPStestView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CGPStestView
IMPLEMENT_DYNCREATE(CGPStestView, CView)
BEGIN_MESSAGE_MAP(CGPStestView, CView)
//{{AFX_MSG_MAP(CGPStestView)
ON_COMMAND(ID_MENU_COM1, OnMenuCom1)
ON_COMMAND(ID_MENU_FROMFILE, OnMenuFromfile)
ON_COMMAND(ID_MENU_COM2, OnMenuCom2)
//}}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)
ON_MESSAGE(ON_COM_RECEIVE,DrawPoint)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CGPStestView construction/destruction
CGPStestView::CGPStestView()
{
// TODO: add construction code here
x=0;y=0;bFirst=true;
}
CGPStestView::~CGPStestView()
{
}
BOOL CGPStestView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CGPStestView drawing
void CGPStestView::OnDraw(CDC* pDC)
{
CGPStestDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
// pDC->SetBkColor(RGB(0,0,0));
// CRect rect;
// GetClientRect(rect);
// pDC->FillSolidRect(50,50,200,200,RGB(160,255,0));
// pDC->Rectangle(rect);
CBrush bkBrush(RGB(0,0,0));
CBrush* pOldBrush = pDC->SelectObject(&bkBrush);
CRect rect;
pDC->GetClipBox(&rect); // 擦除所需的区域
pDC->PatBlt(rect.left, rect.top, rect.Width(), rect.Height(), PATCOPY);
CBrush brush(RGB(0,255,255));
pDC->SelectObject(&brush);
pDC->Ellipse(70,70,74,74);
pDC->SelectObject(pOldBrush);
bkBrush.DeleteObject();
}
/////////////////////////////////////////////////////////////////////////////
// CGPStestView printing
BOOL CGPStestView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CGPStestView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CGPStestView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CGPStestView diagnostics
#ifdef _DEBUG
void CGPStestView::AssertValid() const
{
CView::AssertValid();
}
void CGPStestView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CGPStestDoc* CGPStestView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CGPStestDoc)));
return (CGPStestDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CGPStestView message handlers
void CGPStestView::OnMenuCom1()
{
// TODO: Add your command handler code here
CClientDC dc(this);
CPen pen(PS_SOLID,2,RGB(0,255,0));
CPen *pOldPen=dc.SelectObject(&pen);
dc.Ellipse(100,100,103,103);
dc.SelectObject(pOldPen);
}
/*
double x,y;
bool bFirst;
void f( WPARAM wp,LPARAM lp)
{
GPSParam *gps;
gps=(GPSParam *)wp;
HWND hwnd=(HWND)lp;
double X=gps->X,Y=gps->Y;
if (bFirst)
{
x=X;
y=Y;
bFirst=false;
}
CDC *pDC=hwnd->GetDC();
CBrush *pOldBrush , brush(RGB(255,0,0));
pOldBrush=pDC->SelectObject(&brush);
int a=(int)(270.0-(X-x)*20.0),b=(int)(370.0+(Y-y)*20.0);
// pDC->Ellipse(b,a,b+3,a+3);
pDC->SetPixel(b,a,RGB(55,0,255) );
// pDC->Ellipse(count1,count1,count1+5,count1+5);
count1=count1+1;
pDC->SelectObject(pOldBrush);
CString str;
str.Format("%.1f,%.1f,%d,%d,%d",X-x,Y-y,a,b,count1);
pDC->TextOut(10,10,str);
delete gps;
}
*/
void CGPStestView::OnMenuFromfile()
{
// TODO: Add your command handler code here
m_GPS.set_hwnd(GetSafeHwnd());
// void (*f)(WPARAM ,LPARAM);
// f=this->DrawPoint;
// m_GPS.set_func( f );
if (!m_GPS.Open_file("hello.ubx"))
{
MessageBox("error,can't open the file");
}
}
int count1=0;
void CGPStestView::DrawPoint(WPARAM wp, LPARAM lp)
{
GPSParam *gps;
gps=(GPSParam *)wp;
double X=gps->X,Y=gps->Y;
if (bFirst)
{
x=X;
y=Y;
bFirst=false;
}
CDC *pDC=GetDC();
CPen pen(PS_SOLID,3,RGB(255,0,0) ),*pOldPen;
CBrush *pOldBrush , *pBrush=CBrush::FromHandle( (HBRUSH)GetStockObject(NULL_BRUSH) );
pOldPen=pDC->SelectObject(&pen);
pOldBrush=pDC->SelectObject(pBrush);
int a=(int)(270.0-(X-x)*5.0),b=(int)(370.0+(Y-y)*5.0);
pDC->Ellipse(b,a,b+6,a+6);
// pDC->SetPixel(b,a,RGB(55,0,255) );
// pDC->Ellipse(count1,count1,count1+5,count1+5);
count1=count1+1;
pDC->SelectObject( pOldBrush );
pDC->SelectObject( pOldPen );
CString str;
str.Format("%.1f,%.1f,%d,%d,%d",X-x,Y-y,a,b,count1);
pDC->TextOut(10,10,str);
delete gps;
}
void CGPStestView::OnMenuCom2()
{
// TODO: Add your command handler code here
CDC *pDC=GetDC();
CRect rect;
pDC->GetClipBox(rect);
CString str;
str.Format("%d,%d,%d,%d",rect.left,rect.right,rect.Width(),rect.Height());
MessageBox(str);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -