MyGridFrame.cpp
资源名称:MyStock.rar [点击查看]
上传用户:wenjimin
上传日期:2014-08-12
资源大小:111k
文件大小:5k
源码类别:
金融证券系统
开发平台:
Visual C++
- // MyGridFrame.cpp : implementation file
- //
- #include "stdafx.h"
- #include "MyStock.h"
- #include "MyGridFrame.h"
- #include "MyStockView.h"
- #include "MainFrm.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CMyGridFrame
- CMyGridFrame::CMyGridFrame()
- {
- }
- CMyGridFrame::~CMyGridFrame()
- {
- }
- CScrollBar* CMyGridFrame::GetScrollBar(int nBar) const
- {
- return nBar==SB_HORZ ? const_cast<CScrollBar*>(&m_wndSBHorz)
- : nBar==SB_VERT ? const_cast<CScrollBar*>(&m_wndSBVert) : NULL;
- }
- BEGIN_MESSAGE_MAP(CMyGridFrame, CWnd)
- //{{AFX_MSG_MAP(CMyGridFrame)
- ON_WM_CREATE()
- ON_WM_SIZE()
- ON_WM_HSCROLL()
- ON_WM_VSCROLL()
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CMyGridFrame message handlers
- int CMyGridFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
- {
- if (CWnd::OnCreate(lpCreateStruct) == -1)
- return -1;
- m_grid.Create(NULL,NULL,WS_CHILD|WS_VISIBLE,CRect(1,1,600,500),this,1);
- m_grid.SetRowCount(105);
- m_grid.SetFixedRowCount(1);
- m_grid.SetFixedBkColor(RGB(255,255,255));
- m_grid.SetFixedColumnCount(3);
- m_grid.SetColumnCount(16);
- m_grid.SetHeaderSort(TRUE);
- m_grid.SetFixedRowCount(1);//固定行(列标头)
- m_grid.SetFixedColumnCount(3);//固定列(行标头)
- m_grid.SetRowCount(501);//总行数
- m_grid.SetColumnCount(15);//总列数
- m_grid.SetColumnWidth(0,40);//指定列宽
- m_grid.SetColumnWidth(1,80);
- m_grid.SetHeaderSort(true);//允许排序
- m_grid.SetGridBkColor(RGB(255,255,255));
- //以下这些参数都可以用变量代替,以便和用户交互
- m_grid.SetFixedBkColor(RGB(255,255,255));
- m_grid.SetFixedTextColor(RGB(0,0,0));
- m_grid.SetItemText(0,1,"代 码");
- m_grid.SetItemText(0,2,"名 称");
- m_grid.SetItemText(0,3,"最新价");
- m_grid.SetItemText(0,4,"涨 跌");
- m_grid.SetItemText(0,5,"涨跌幅");
- m_grid.SetItemText(0,6,"总 手");
- m_grid.SetItemText(0,7,"最高价");
- m_grid.SetItemText(0,8,"最低价");
- m_grid.SetItemText(0,9,"今开盘");
- m_grid.SetItemText(0,10,"昨收盘");
- m_grid.SetItemText(0,11,"总 额");
- m_tab.Create(WS_CHILD|WS_VISIBLE,CRect(0,0,200,20),this,IDC_FOLDERTAB);
- m_tab.Load(IDS_FOLDERTAB);
- CRect rc(0,0,0,0);
- VERIFY(m_wndSBHorz.Create(WS_VISIBLE|WS_CHILD|SBS_HORZ,
- rc, this, AFX_IDW_HSCROLL_FIRST));
- VERIFY(m_wndSBVert.Create(WS_VISIBLE|WS_CHILD|SBS_VERT,
- rc, this, AFX_IDW_HSCROLL_FIRST+1));
- VERIFY(m_wndSBBox.Create(WS_VISIBLE|WS_CHILD|SBS_SIZEBOX,
- rc, this,-1));
- return 0;
- }
- void CMyGridFrame::OnSize(UINT nType, int cx, int cy)
- {
- CWnd::OnSize(nType, cx, cy);
- CRect rc(0,cy-20,cx,cy);
- m_grid.MoveWindow(&CRect(0,0,cx-20,cy-20));
- m_wndSBVert.MoveWindow(&CRect(cx-20,0,cx,cy-19));
- int width=m_tab.GetDesiredWidth();
- rc.left=0;
- rc.right=width;
- m_tab.MoveWindow(&rc);
- rc.left=width;
- rc.right=cx-19;
- m_wndSBHorz.MoveWindow(&rc);
- rc.left=cx-21;
- rc.right=cx;
- m_wndSBBox.MoveWindow(&rc);
- m_wndSBBox.EnableWindow(FALSE);//不响应事件(只是为了美观)
- }
- void CMyGridFrame::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
- {
- m_grid.SendMessage(WM_HSCROLL,
- MAKELONG(nSBCode, nPos), (LPARAM)pScrollBar->m_hWnd);
- // CWnd::OnHScroll(nSBCode, nPos, pScrollBar);
- }
- void CMyGridFrame::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
- {
- m_grid.SendMessage(WM_VSCROLL,
- MAKELONG(nSBCode, nPos), (LPARAM)pScrollBar->m_hWnd);
- // CWnd::OnVScroll(nSBCode, nPos, pScrollBar);
- }
- BOOL CMyGridFrame::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult)
- {
- //使用的是第二个参数
- CString s;
- NMFOLDERTAB* nmtab=(NMFOLDERTAB*)lParam;
- // s.Format(_T("选中 %d: %s"), nmtab->iItem,
- // nmtab->pItem->GetText());
- // s.Format(_T("%s"),nmtab->pItem->GetText());
- s.Format(_T("%s"),nmtab->lpText);
- CMyStockView* pView=(CMyStockView*)GetParent();
- if(strcmp(s,"上海A股")==0)
- {
- pView->m_wMarket=SH_MARKET_EX;
- pView->m_sType="6";
- pView->m_FillCell=false;
- m_grid.SetRowCount(100);
- m_grid.ClearCells();
- pView->GetDocument()->m_DataMap.RemoveAll();
- }
- if(strcmp(s,"深圳A股")==0)
- {
- pView->m_wMarket=SZ_MARKET_EX;
- pView->m_sType="0";
- pView->m_FillCell=false;
- m_grid.SetRowCount(100);
- m_grid.ClearCells();
- pView->GetDocument()->m_DataMap.RemoveAll();
- }
- if(strcmp(s,"板块指数")==0)
- {
- MessageBox("未实现");
- m_grid.ClearCells();
- }
- if(strcmp(s,"自选股")==0)
- {
- MessageBox("未实现");
- m_grid.ClearCells();
- }
- if(strcmp(s,"条件选股")==0)
- {
- MessageBox("未实现");
- m_grid.ClearCells();
- }
- //MessageBox(s);
- // m_grid.SetRowCount(100);
- // m_grid.SetSortColumn(5);
- return CWnd::OnNotify(wParam, lParam, pResult);
- }
- void CMyGridFrame::OnStringChange()
- {
- CMyStockView* pView=(CMyStockView*)GetParent();
- pView->GetDocument()->m_FileName=m_szLabel;
- CMainFrame* pFrame=(CMainFrame*)AfxGetMainWnd();
- pFrame->OnNewview();
- }