RTForm.cpp
上传用户:mgf822
上传日期:2013-10-03
资源大小:133k
文件大小:5k
源码类别:

对话框与窗口

开发平台:

Visual C++

  1. // RTForm.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "RTDemo.h"
  5. #include "RTForm.h"
  6. #include "RTDemoDoc.h"
  7. #include "RTDemoView.h"
  8. #ifdef _DEBUG
  9. #define new DEBUG_NEW
  10. #undef THIS_FILE
  11. static char THIS_FILE[] = __FILE__;
  12. #endif
  13. #define TipsPerPixel 15
  14. static CString m_ColHead[] = 
  15. {
  16. "Color", 
  17. "name", 
  18. "Description", 
  19. "Unit", 
  20. "Value", 
  21. "Minimum", 
  22. "Maximum", 
  23. "Scaled Min", 
  24. "Scaled Max"
  25. };
  26. /////////////////////////////////////////////////////////////////////////////
  27. // CRTForm
  28. IMPLEMENT_DYNCREATE(CRTForm, CFormView)
  29. CRTForm::CRTForm()
  30. : CFormView(CRTForm::IDD)
  31. {
  32. //{{AFX_DATA_INIT(CRTForm)
  33. // NOTE: the ClassWizard will add member initialization here
  34. //}}AFX_DATA_INIT
  35. }
  36. CRTForm::~CRTForm()
  37. {
  38. }
  39. void CRTForm::DoDataExchange(CDataExchange* pDX)
  40. {
  41. CFormView::DoDataExchange(pDX);
  42. //{{AFX_DATA_MAP(CRTForm)
  43. DDX_Control(pDX, IDC_SLIDERPAGE, m_SliderPage);
  44. DDX_Control(pDX, IDC_RTGRID, m_RTGrid);
  45. //}}AFX_DATA_MAP
  46. }
  47. BEGIN_MESSAGE_MAP(CRTForm, CFormView)
  48. //{{AFX_MSG_MAP(CRTForm)
  49. ON_WM_SIZE()
  50. //}}AFX_MSG_MAP
  51. END_MESSAGE_MAP()
  52. /////////////////////////////////////////////////////////////////////////////
  53. // CRTForm diagnostics
  54. #ifdef _DEBUG
  55. void CRTForm::AssertValid() const
  56. {
  57. CFormView::AssertValid();
  58. }
  59. void CRTForm::Dump(CDumpContext& dc) const
  60. {
  61. CFormView::Dump(dc);
  62. }
  63. #endif //_DEBUG
  64. CWnd* CRTForm::GetRTDemoView()
  65. {
  66. CSplitterWnd* pWnd = (CSplitterWnd*)GetParent();
  67. return pWnd->GetPane(0, 0);
  68. }
  69. void CRTForm::MoveWindows()
  70. {
  71. CRect rect;
  72. GetClientRect(rect);
  73. CWnd* pView = GetRTDemoView();
  74. RECT& plotRect = ((CRTDemoView*)pView)->GetGraphRect();
  75. if (plotRect.right - plotRect.left > 0)
  76. {
  77. m_sRect.left = plotRect.left - 10;
  78. m_sRect.right = plotRect.right + 10;
  79. m_SliderPage.MoveWindow(m_sRect);
  80. }
  81. else
  82. {
  83. m_sRect.left = rect.left;
  84. m_sRect.right = rect.right;
  85. m_SliderPage.MoveWindow(m_sRect);
  86. }
  87. rect.top = m_sRect.top + m_sRect.Height();
  88. m_RTGrid.MoveWindow(rect);
  89. }
  90. void CRTForm::InitialSlider(int nMin, int nMax, int nPage, int nPos, BOOL nFlag)
  91. {
  92. m_SliderPage.SetRange(nMin, nMax, TRUE);
  93. //m_SliderPage.SetTic(nMax - nMin);
  94. m_SliderPage.SetPageSize(nPage);
  95. m_SliderPage.SetPos(m_SliderPage.GetPos() + 1);
  96. m_SliderPage.EnableWindow(TRUE);
  97. }
  98. void CRTForm::RedrawGrid()
  99. {
  100. CRTDemoView* pView = (CRTDemoView*)GetRTDemoView();
  101. long Rows = pView->m_Graph.m_LineArray.GetSize() + 1;
  102. m_RTGrid.SetRows(Rows);
  103. CString str;
  104. m_RTGrid.SetCol(1);
  105. for(long row = 1; row <Rows; row ++)
  106. {
  107. m_RTGrid.SetRow(row);
  108. // column 0 : index
  109. str.Format("%d", row);
  110. m_RTGrid.SetTextMatrix(row, 0, str);
  111. // column 1 : color
  112. m_RTGrid.SetCellBackColor(pView->m_Graph.m_LineArray[row - 1].m_nColor);
  113. // column 2 : name
  114. m_RTGrid.SetTextMatrix(row, 2, pView->m_Graph.m_LineArray[row - 1].m_sName.GetChar());
  115. // column 3 : description
  116. m_RTGrid.SetTextMatrix(row, 3, pView->m_Graph.m_LineArray[row - 1].m_sDescription.GetChar());
  117. // column 4 : unit
  118. m_RTGrid.SetTextMatrix(row, 4, pView->m_Graph.m_LineArray[row - 1].m_sUnit.GetChar());
  119. // column 6 : minimum value
  120. str.Format("%.f", pView->m_Graph.m_LineArray[row - 1].m_dMin);
  121. m_RTGrid.SetTextMatrix(row, 6, str);
  122. // column 7 : maximum value
  123. str.Format("%.f", pView->m_Graph.m_LineArray[row - 1].m_dMax);
  124. m_RTGrid.SetTextMatrix(row, 7, str);
  125. // column 8 : scaled minimum value
  126. str.Format("%.f", pView->m_Graph.m_LineArray[row - 1].m_dScaleLow);
  127. m_RTGrid.SetTextMatrix(row, 8, str);
  128. // column 9 : scaled maximum value
  129. str.Format("%.f", pView->m_Graph.m_LineArray[row - 1].m_dScaleHigh);
  130. m_RTGrid.SetTextMatrix(row, 9, str);
  131. }
  132. }
  133. /////////////////////////////////////////////////////////////////////////////
  134. // CRTForm message handlers
  135. void CRTForm::OnSize(UINT nType, int cx, int cy) 
  136. {
  137. CFormView::OnSize(nType, cx, cy);
  138. if(::IsWindow(m_RTGrid.m_hWnd) && ::IsWindow(m_SliderPage.m_hWnd))
  139. MoveWindows();
  140. }
  141. void CRTForm::OnInitialUpdate() 
  142. {
  143. CFormView::OnInitialUpdate();
  144. m_SliderPage.SetType(m_SliderPage.sType::PAGE);
  145. m_SliderPage.GetClientRect(m_sRect);
  146. m_SliderPage.SetRange(0, 1, TRUE);
  147. //m_SliderPage.SetTic(1);
  148. m_SliderPage.SetPos(1);
  149. m_SliderPage.SetPageSize(1);
  150. m_SliderPage.EnableWindow(FALSE);
  151. MoveWindows();
  152. m_RTGrid.SetColWidth(0, 30  * TipsPerPixel);
  153. m_RTGrid.SetColWidth(1, 70  * TipsPerPixel);
  154. m_RTGrid.SetColWidth(2, 100 * TipsPerPixel);
  155. m_RTGrid.SetColWidth(3, 150 * TipsPerPixel);
  156. m_RTGrid.SetColWidth(4, 70  * TipsPerPixel);
  157. m_RTGrid.SetColWidth(5, 70  * TipsPerPixel);
  158. m_RTGrid.SetColWidth(6, 70  * TipsPerPixel);
  159. m_RTGrid.SetColWidth(7, 70  * TipsPerPixel);
  160. m_RTGrid.SetColWidth(8, 70  * TipsPerPixel);
  161. m_RTGrid.SetColWidth(9, 70  * TipsPerPixel);
  162. long Cols = m_RTGrid.GetCols();
  163. m_RTGrid.SetColAlignment(0, 4); // center alignment
  164. for(long col = 1; col <Cols; col ++)
  165. {
  166. m_RTGrid.SetColAlignment(col, 4);
  167. m_RTGrid.SetTextMatrix(0, col, m_ColHead[col-1]);
  168. }
  169. RedrawGrid();
  170. }