GPStestView.cpp
上传用户:fudaml
上传日期:2013-05-28
资源大小:211k
文件大小:5k
源码类别:

GPS编程

开发平台:

Visual C++

  1. // GPStestView.cpp : implementation of the CGPStestView class
  2. //
  3. #include "stdafx.h"
  4. #include "GPStest.h"
  5. #include "GPStestDoc.h"
  6. #include "GPStestView.h"
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #undef THIS_FILE
  10. static char THIS_FILE[] = __FILE__;
  11. #endif
  12. /////////////////////////////////////////////////////////////////////////////
  13. // CGPStestView
  14. IMPLEMENT_DYNCREATE(CGPStestView, CView)
  15. BEGIN_MESSAGE_MAP(CGPStestView, CView)
  16. //{{AFX_MSG_MAP(CGPStestView)
  17. ON_COMMAND(ID_MENU_COM1, OnMenuCom1)
  18. ON_COMMAND(ID_MENU_FROMFILE, OnMenuFromfile)
  19. ON_COMMAND(ID_MENU_COM2, OnMenuCom2)
  20. //}}AFX_MSG_MAP
  21. // Standard printing commands
  22. ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
  23. ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
  24. ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
  25. ON_MESSAGE(ON_COM_RECEIVE,DrawPoint)
  26. END_MESSAGE_MAP()
  27. /////////////////////////////////////////////////////////////////////////////
  28. // CGPStestView construction/destruction
  29. CGPStestView::CGPStestView()
  30. {
  31. // TODO: add construction code here
  32. x=0;y=0;bFirst=true;
  33. }
  34. CGPStestView::~CGPStestView()
  35. {
  36. }
  37. BOOL CGPStestView::PreCreateWindow(CREATESTRUCT& cs)
  38. {
  39. // TODO: Modify the Window class or styles here by modifying
  40. //  the CREATESTRUCT cs
  41. return CView::PreCreateWindow(cs);
  42. }
  43. /////////////////////////////////////////////////////////////////////////////
  44. // CGPStestView drawing
  45. void CGPStestView::OnDraw(CDC* pDC)
  46. {
  47. CGPStestDoc* pDoc = GetDocument();
  48. ASSERT_VALID(pDoc);
  49. // TODO: add draw code for native data here
  50. // pDC->SetBkColor(RGB(0,0,0));
  51. // CRect rect;
  52. // GetClientRect(rect);
  53. // pDC->FillSolidRect(50,50,200,200,RGB(160,255,0));
  54. // pDC->Rectangle(rect);
  55. CBrush bkBrush(RGB(0,0,0));
  56. CBrush* pOldBrush = pDC->SelectObject(&bkBrush);
  57. CRect rect;
  58. pDC->GetClipBox(&rect);     // 擦除所需的区域
  59. pDC->PatBlt(rect.left, rect.top, rect.Width(), rect.Height(), PATCOPY);
  60. CBrush brush(RGB(0,255,255));
  61. pDC->SelectObject(&brush);
  62. pDC->Ellipse(70,70,74,74);
  63. pDC->SelectObject(pOldBrush);
  64. bkBrush.DeleteObject();
  65. }
  66. /////////////////////////////////////////////////////////////////////////////
  67. // CGPStestView printing
  68. BOOL CGPStestView::OnPreparePrinting(CPrintInfo* pInfo)
  69. {
  70. // default preparation
  71. return DoPreparePrinting(pInfo);
  72. }
  73. void CGPStestView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  74. {
  75. // TODO: add extra initialization before printing
  76. }
  77. void CGPStestView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  78. {
  79. // TODO: add cleanup after printing
  80. }
  81. /////////////////////////////////////////////////////////////////////////////
  82. // CGPStestView diagnostics
  83. #ifdef _DEBUG
  84. void CGPStestView::AssertValid() const
  85. {
  86. CView::AssertValid();
  87. }
  88. void CGPStestView::Dump(CDumpContext& dc) const
  89. {
  90. CView::Dump(dc);
  91. }
  92. CGPStestDoc* CGPStestView::GetDocument() // non-debug version is inline
  93. {
  94. ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CGPStestDoc)));
  95. return (CGPStestDoc*)m_pDocument;
  96. }
  97. #endif //_DEBUG
  98. /////////////////////////////////////////////////////////////////////////////
  99. // CGPStestView message handlers
  100. void CGPStestView::OnMenuCom1() 
  101. {
  102. // TODO: Add your command handler code here
  103. CClientDC dc(this);
  104. CPen pen(PS_SOLID,2,RGB(0,255,0));
  105. CPen *pOldPen=dc.SelectObject(&pen);
  106. dc.Ellipse(100,100,103,103);
  107. dc.SelectObject(pOldPen);
  108. }
  109. /*
  110. double x,y;
  111. bool bFirst;
  112. void f( WPARAM wp,LPARAM lp)
  113. {
  114. GPSParam *gps;
  115. gps=(GPSParam *)wp;
  116. HWND hwnd=(HWND)lp;
  117. double X=gps->X,Y=gps->Y;
  118. if (bFirst) 
  119. {
  120. x=X;
  121. y=Y;
  122. bFirst=false;
  123. }
  124. CDC *pDC=hwnd->GetDC();
  125. CBrush *pOldBrush  , brush(RGB(255,0,0));
  126. pOldBrush=pDC->SelectObject(&brush);
  127. int a=(int)(270.0-(X-x)*20.0),b=(int)(370.0+(Y-y)*20.0);
  128. // pDC->Ellipse(b,a,b+3,a+3);
  129. pDC->SetPixel(b,a,RGB(55,0,255) );
  130. // pDC->Ellipse(count1,count1,count1+5,count1+5);
  131. count1=count1+1;
  132. pDC->SelectObject(pOldBrush);
  133. CString str;
  134. str.Format("%.1f,%.1f,%d,%d,%d",X-x,Y-y,a,b,count1);
  135. pDC->TextOut(10,10,str);
  136. delete gps;
  137. }
  138. */
  139. void CGPStestView::OnMenuFromfile() 
  140. {
  141. // TODO: Add your command handler code here
  142. m_GPS.set_hwnd(GetSafeHwnd());
  143. // void (*f)(WPARAM ,LPARAM);
  144. // f=this->DrawPoint;
  145. // m_GPS.set_func( f );
  146. if (!m_GPS.Open_file("hello.ubx")) 
  147. {
  148. MessageBox("error,can't open the file");
  149. }
  150. }
  151. int count1=0;
  152. void CGPStestView::DrawPoint(WPARAM wp, LPARAM lp)
  153. {
  154. GPSParam *gps;
  155. gps=(GPSParam *)wp;
  156. double X=gps->X,Y=gps->Y;
  157. if (bFirst) 
  158. {
  159. x=X;
  160. y=Y;
  161. bFirst=false;
  162. }
  163. CDC *pDC=GetDC();
  164. CPen pen(PS_SOLID,3,RGB(255,0,0) ),*pOldPen;
  165. CBrush *pOldBrush  , *pBrush=CBrush::FromHandle( (HBRUSH)GetStockObject(NULL_BRUSH) );
  166. pOldPen=pDC->SelectObject(&pen);
  167. pOldBrush=pDC->SelectObject(pBrush);
  168. int a=(int)(270.0-(X-x)*5.0),b=(int)(370.0+(Y-y)*5.0);
  169. pDC->Ellipse(b,a,b+6,a+6);
  170. // pDC->SetPixel(b,a,RGB(55,0,255) );
  171. // pDC->Ellipse(count1,count1,count1+5,count1+5);
  172. count1=count1+1;
  173. pDC->SelectObject( pOldBrush );
  174. pDC->SelectObject( pOldPen );
  175. CString str;
  176. str.Format("%.1f,%.1f,%d,%d,%d",X-x,Y-y,a,b,count1);
  177. pDC->TextOut(10,10,str);
  178. delete gps;
  179. }
  180. void CGPStestView::OnMenuCom2() 
  181. {
  182. // TODO: Add your command handler code here
  183. CDC *pDC=GetDC();
  184. CRect rect;
  185. pDC->GetClipBox(rect);
  186. CString str;
  187. str.Format("%d,%d,%d,%d",rect.left,rect.right,rect.Width(),rect.Height());
  188. MessageBox(str);
  189. }