ProjectView.cpp
上传用户:wangdan
上传日期:2022-06-30
资源大小:739k
文件大小:5k
源码类别:

3D图形编程

开发平台:

Visual C++

  1. // ProjectView.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "Test1.h"
  5. #include "ProjectView.h"
  6. #include "MainFrm.h"
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #undef THIS_FILE
  10. static char THIS_FILE[] = __FILE__;
  11. #endif
  12. extern GLfloat Databuf[ArrayOne][ArrayTwo];
  13. extern bool gbIsGetData;
  14. extern GLfloat  xrof,yrof,zrof;//各坐标轴倾角
  15. /////////////////////////////////////////////////////////////////////////////
  16. // CProjectView
  17. IMPLEMENT_DYNCREATE(CProjectView, CView)
  18. CProjectView::CProjectView()
  19. {
  20. m_WitchPro = 0;
  21. this->m_ProName = "";
  22. m_pDC = NULL;
  23. m_bShowBmp = false;
  24. }
  25. CProjectView::~CProjectView()
  26. {
  27. if (m_pDC)
  28. {
  29. delete m_pDC;
  30. m_pDC = NULL;
  31. }
  32. }
  33. BEGIN_MESSAGE_MAP(CProjectView, CView)
  34. //{{AFX_MSG_MAP(CProjectView)
  35. ON_WM_ERASEBKGND()
  36. ON_WM_MOUSEMOVE()
  37. //}}AFX_MSG_MAP
  38. ON_MESSAGE(MESSAGE_ANGLECHANGING,AngleChanging)
  39. ON_MESSAGE(MESSAGE_BMPHASBECOPIED,ShowBmpMessageFun)
  40. END_MESSAGE_MAP()
  41. /////////////////////////////////////////////////////////////////////////////
  42. // CProjectView drawing
  43. void CProjectView::OnDraw(CDC* pDC)
  44. {
  45. CDocument* pDoc = GetDocument();
  46. // TODO: add draw code here
  47. CFont *OldFont = pDC->SelectObject(&this->m_pfr->m_13Font);
  48. this->DrawCoordinate(pDC);
  49. // this->DrawRect(pDC);
  50. if (this->m_bShowBmp)
  51. {
  52. HBITMAP hBmp = this->m_pfr->m_pView->m_hBmp;
  53. this->ShowSelArear(hBmp,pDC);
  54. }
  55. pDC->SelectObject(OldFont);
  56. }
  57. /////////////////////////////////////////////////////////////////////////////
  58. // CProjectView diagnostics
  59. #ifdef _DEBUG
  60. void CProjectView::AssertValid() const
  61. {
  62. CView::AssertValid();
  63. }
  64. void CProjectView::Dump(CDumpContext& dc) const
  65. {
  66. CView::Dump(dc);
  67. }
  68. #endif //_DEBUG
  69. /////////////////////////////////////////////////////////////////////////////
  70. // CProjectView message handlers
  71. void CProjectView::OnInitialUpdate() 
  72. {
  73. CView::OnInitialUpdate();
  74. m_pfr = (CMainFrame*)AfxGetApp()->m_pMainWnd;
  75. }
  76. BOOL CProjectView::OnEraseBkgnd(CDC* pDC) 
  77. {
  78. TEXTMETRIC tm;
  79. pDC->GetTextMetrics(&tm);
  80. CBrush Brush (BLACK); 
  81.     CBrush* pOldBrush = pDC->SelectObject(&Brush);     
  82. CRect ViewClip; 
  83. pDC->GetClipBox(&ViewClip);     
  84. pDC->PatBlt(ViewClip.left,ViewClip.top,ViewClip.Width(),ViewClip.Height(),PATCOPY);    
  85. pDC->SelectObject (pOldBrush );
  86. return TRUE;
  87. }
  88. void CProjectView::DrawRect(CDC *pDC)
  89. {
  90. CRect rc;
  91. this->GetClientRect(&rc);
  92. int cx = rc.right;
  93. int cy = rc.bottom;
  94. TEXTMETRIC tm;
  95. pDC->GetTextMetrics(&tm);
  96. int yStart = 10;
  97. int nCharWith = tm.tmHeight;
  98. CPen Brightpen(PS_SOLID, 1, RED);
  99. CPen *pOldPen = pDC->SelectObject(&Brightpen);
  100. pDC->SetTextAlign(TA_RIGHT);
  101. pDC->MoveTo(cx - nCharWith*5 - 2, 0);
  102. pDC->LineTo(cx - nCharWith*5 - 2, rc.bottom-30);
  103. pDC->TextOut(cx ,10, "成图参数表");
  104. pDC->SetTextColor(BLUE);
  105. pDC->MoveTo(cx - nCharWith*5 - 1, 10 + nCharWith + 1);
  106. pDC->LineTo(cx , 10 + nCharWith + 1);
  107. pDC->MoveTo(cx - nCharWith*5 - 1, rc.bottom-30);
  108. pDC->LineTo(cx , rc.bottom-30);
  109. pDC->SetTextAlign(TA_LEFT);
  110. pDC->TextOut(cx - nCharWith*5, 10 + nCharWith + 2, "○X轴倾角");
  111. pDC->TextOut(cx - nCharWith*5, 10 + nCharWith*3 + 4, "○Y轴倾角");
  112. pDC->TextOut(cx - nCharWith*5, 10 + nCharWith*5 + 6, "○Z轴倾角");
  113. pDC->SetTextColor(BRIGHT);
  114. pDC->TextOut(cx - nCharWith*5, 10 + nCharWith*2 + 2, this->GetAngle(xrof));
  115. pDC->TextOut(cx - nCharWith*5, 10 + nCharWith*4 + 4, this->GetAngle(yrof));
  116. pDC->TextOut(cx - nCharWith*5, 10 + nCharWith*6 + 6, this->GetAngle(zrof));
  117. pDC->SelectObject(pOldPen);
  118. }
  119. void CProjectView::DrawCoordinate(CDC *pDC)
  120. {
  121. CRect rc;
  122. GetClientRect(&rc);
  123. pDC->SetTextAlign(TA_CENTER);
  124. pDC->SetTextColor(YELLOW);
  125. pDC->SetBkMode(1);
  126. CPen Greenpen(PS_SOLID,1,GREEN);
  127. CPen *pOldPen = pDC->SelectObject(&Greenpen);
  128. CString Show = "选取部位投影窗口" + m_ProName;
  129. pDC->TextOut(rc.right/2,2,Show);
  130. //x轴
  131. pDC->MoveTo(10,rc.bottom-20);
  132. pDC->LineTo(rc.right-30,rc.bottom-20);
  133. pDC->MoveTo(rc.right-30,rc.bottom-20);
  134. pDC->LineTo(rc.right-30-5,rc.bottom-20-5);
  135. pDC->MoveTo(rc.right-30,rc.bottom-20);
  136. pDC->LineTo(rc.right-30-5,rc.bottom-20+5);
  137. //y轴
  138. pDC->MoveTo(10,rc.bottom-20);
  139. pDC->LineTo(10,25);
  140. pDC->MoveTo(10,25);
  141. pDC->LineTo(5,30);
  142. pDC->MoveTo(10,25);
  143. pDC->LineTo(15,30);
  144. if (::gbIsGetData)
  145. return;
  146. pDC->SelectObject(pOldPen);
  147. }
  148. CString CProjectView::GetAngle(int Angle)
  149. {
  150. CString strAngle = "0";
  151. if (Angle > -360 && Angle < 360)
  152. strAngle.Format("%d度", Angle);
  153. else
  154. strAngle.Format("%d度",Angle%360);
  155. return strAngle;
  156. }
  157. void CProjectView::AngleChanging(LPARAM lp, WPARAM wp)
  158. {
  159. this->InvalidatethisRect();
  160. }
  161. void CProjectView::InvalidatethisRect()
  162. {
  163. CRect rc;
  164. GetClientRect(&rc);
  165. int cx = rc.right;
  166. int cy = rc.bottom;
  167. this->InvalidateRect(CRect(15,21,cx-15,cy-30));
  168. }
  169. void CProjectView::OnMouseMove(UINT nFlags, CPoint point) 
  170. {
  171. this->SetFocus();
  172. CView::OnMouseMove(nFlags, point);
  173. }
  174. void CProjectView::ShowSelArear(HBITMAP hBmp, CDC *pDC)
  175. {
  176. HBITMAP OldBitmap;
  177. CDC MemDC;
  178. MemDC.CreateCompatibleDC(pDC);
  179. CRect rect;
  180. GetClientRect(rect);
  181. OldBitmap=(HBITMAP)MemDC.SelectObject(hBmp);
  182. pDC->BitBlt(20,20,rect.right,rect.bottom,&MemDC,0,0,SRCCOPY);
  183. MemDC.SelectObject(OldBitmap);
  184. }
  185. void CProjectView::ShowBmpMessageFun(LPARAM lp, WPARAM wp)
  186. {
  187. m_bShowBmp = true;
  188. this->InvalidatethisRect();
  189. }