MyGridFrame.cpp
上传用户:wenjimin
上传日期:2014-08-12
资源大小:111k
文件大小:5k
源码类别:

金融证券系统

开发平台:

Visual C++

  1. // MyGridFrame.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "MyStock.h"
  5. #include "MyGridFrame.h"
  6. #include "MyStockView.h"
  7. #include "MainFrm.h"
  8. #ifdef _DEBUG
  9. #define new DEBUG_NEW
  10. #undef THIS_FILE
  11. static char THIS_FILE[] = __FILE__;
  12. #endif
  13. /////////////////////////////////////////////////////////////////////////////
  14. // CMyGridFrame
  15. CMyGridFrame::CMyGridFrame()
  16. {
  17. }
  18. CMyGridFrame::~CMyGridFrame()
  19. {
  20. }
  21. CScrollBar* CMyGridFrame::GetScrollBar(int nBar) const
  22. {
  23. return nBar==SB_HORZ ? const_cast<CScrollBar*>(&m_wndSBHorz)
  24. : nBar==SB_VERT ? const_cast<CScrollBar*>(&m_wndSBVert) : NULL;
  25. }
  26. BEGIN_MESSAGE_MAP(CMyGridFrame, CWnd)
  27. //{{AFX_MSG_MAP(CMyGridFrame)
  28. ON_WM_CREATE()
  29. ON_WM_SIZE()
  30. ON_WM_HSCROLL()
  31. ON_WM_VSCROLL()
  32. //}}AFX_MSG_MAP
  33. END_MESSAGE_MAP()
  34. /////////////////////////////////////////////////////////////////////////////
  35. // CMyGridFrame message handlers
  36. int CMyGridFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) 
  37. {
  38. if (CWnd::OnCreate(lpCreateStruct) == -1)
  39. return -1;
  40. m_grid.Create(NULL,NULL,WS_CHILD|WS_VISIBLE,CRect(1,1,600,500),this,1);
  41. m_grid.SetRowCount(105);
  42. m_grid.SetFixedRowCount(1);
  43. m_grid.SetFixedBkColor(RGB(255,255,255));
  44. m_grid.SetFixedColumnCount(3);
  45. m_grid.SetColumnCount(16);
  46. m_grid.SetHeaderSort(TRUE);
  47. m_grid.SetFixedRowCount(1);//固定行(列标头)
  48. m_grid.SetFixedColumnCount(3);//固定列(行标头)
  49. m_grid.SetRowCount(501);//总行数
  50. m_grid.SetColumnCount(15);//总列数
  51. m_grid.SetColumnWidth(0,40);//指定列宽
  52. m_grid.SetColumnWidth(1,80);
  53. m_grid.SetHeaderSort(true);//允许排序
  54. m_grid.SetGridBkColor(RGB(255,255,255));
  55. //以下这些参数都可以用变量代替,以便和用户交互
  56. m_grid.SetFixedBkColor(RGB(255,255,255));
  57. m_grid.SetFixedTextColor(RGB(0,0,0));
  58. m_grid.SetItemText(0,1,"代  码");
  59.     m_grid.SetItemText(0,2,"名  称");
  60.     m_grid.SetItemText(0,3,"最新价");
  61.    m_grid.SetItemText(0,4,"涨  跌");
  62.     m_grid.SetItemText(0,5,"涨跌幅");
  63.     m_grid.SetItemText(0,6,"总  手");
  64.     m_grid.SetItemText(0,7,"最高价");
  65.     m_grid.SetItemText(0,8,"最低价");
  66.     m_grid.SetItemText(0,9,"今开盘");
  67.     m_grid.SetItemText(0,10,"昨收盘");
  68.     m_grid.SetItemText(0,11,"总  额");
  69. m_tab.Create(WS_CHILD|WS_VISIBLE,CRect(0,0,200,20),this,IDC_FOLDERTAB);
  70. m_tab.Load(IDS_FOLDERTAB);
  71.    CRect rc(0,0,0,0);
  72. VERIFY(m_wndSBHorz.Create(WS_VISIBLE|WS_CHILD|SBS_HORZ,
  73. rc, this, AFX_IDW_HSCROLL_FIRST));
  74. VERIFY(m_wndSBVert.Create(WS_VISIBLE|WS_CHILD|SBS_VERT,
  75. rc, this, AFX_IDW_HSCROLL_FIRST+1));
  76. VERIFY(m_wndSBBox.Create(WS_VISIBLE|WS_CHILD|SBS_SIZEBOX,
  77. rc, this,-1));
  78. return 0;
  79. }
  80. void CMyGridFrame::OnSize(UINT nType, int cx, int cy) 
  81. {
  82. CWnd::OnSize(nType, cx, cy);
  83. CRect rc(0,cy-20,cx,cy);
  84. m_grid.MoveWindow(&CRect(0,0,cx-20,cy-20));
  85. m_wndSBVert.MoveWindow(&CRect(cx-20,0,cx,cy-19));
  86. int width=m_tab.GetDesiredWidth();
  87. rc.left=0;
  88. rc.right=width;
  89. m_tab.MoveWindow(&rc);
  90. rc.left=width;
  91. rc.right=cx-19;
  92. m_wndSBHorz.MoveWindow(&rc);
  93. rc.left=cx-21;
  94. rc.right=cx;
  95. m_wndSBBox.MoveWindow(&rc);
  96. m_wndSBBox.EnableWindow(FALSE);//不响应事件(只是为了美观)
  97. }
  98. void CMyGridFrame::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) 
  99. {
  100. m_grid.SendMessage(WM_HSCROLL,
  101. MAKELONG(nSBCode, nPos), (LPARAM)pScrollBar->m_hWnd);
  102. // CWnd::OnHScroll(nSBCode, nPos, pScrollBar);
  103. }
  104. void CMyGridFrame::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) 
  105. {
  106. m_grid.SendMessage(WM_VSCROLL,
  107. MAKELONG(nSBCode, nPos), (LPARAM)pScrollBar->m_hWnd);
  108. // CWnd::OnVScroll(nSBCode, nPos, pScrollBar);
  109. }
  110. BOOL CMyGridFrame::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult) 
  111. {
  112. //使用的是第二个参数
  113. CString s;
  114. NMFOLDERTAB* nmtab=(NMFOLDERTAB*)lParam;
  115. // s.Format(_T("选中 %d: %s"), nmtab->iItem,
  116. // nmtab->pItem->GetText());
  117. // s.Format(_T("%s"),nmtab->pItem->GetText());
  118. s.Format(_T("%s"),nmtab->lpText);
  119. CMyStockView* pView=(CMyStockView*)GetParent();
  120. if(strcmp(s,"上海A股")==0)
  121. {
  122. pView->m_wMarket=SH_MARKET_EX;
  123. pView->m_sType="6";
  124. pView->m_FillCell=false;
  125. m_grid.SetRowCount(100);
  126. m_grid.ClearCells();
  127. pView->GetDocument()->m_DataMap.RemoveAll();
  128. }
  129. if(strcmp(s,"深圳A股")==0)
  130. {
  131. pView->m_wMarket=SZ_MARKET_EX;
  132. pView->m_sType="0";
  133. pView->m_FillCell=false;
  134. m_grid.SetRowCount(100);
  135. m_grid.ClearCells();
  136. pView->GetDocument()->m_DataMap.RemoveAll();
  137. }
  138. if(strcmp(s,"板块指数")==0)
  139. {
  140. MessageBox("未实现");
  141. m_grid.ClearCells();
  142. }
  143. if(strcmp(s,"自选股")==0)
  144. {
  145. MessageBox("未实现");
  146. m_grid.ClearCells();
  147. }
  148. if(strcmp(s,"条件选股")==0)
  149. {
  150. MessageBox("未实现");
  151. m_grid.ClearCells();
  152. }
  153. //MessageBox(s);
  154. //  m_grid.SetRowCount(100);
  155. // m_grid.SetSortColumn(5);
  156. return CWnd::OnNotify(wParam, lParam, pResult);
  157. }
  158. void CMyGridFrame::OnStringChange()
  159. {
  160. CMyStockView* pView=(CMyStockView*)GetParent();
  161. pView->GetDocument()->m_FileName=m_szLabel;
  162. CMainFrame* pFrame=(CMainFrame*)AfxGetMainWnd();
  163. pFrame->OnNewview();
  164. }