MyStockView.cpp
资源名称:MyStock.rar [点击查看]
上传用户:wenjimin
上传日期:2014-08-12
资源大小:111k
文件大小:18k
源码类别:
金融证券系统
开发平台:
Visual C++
- // MyStockView.cpp : implementation of the CMyStockView class
- //
- #include "stdafx.h"
- #include "MyStock.h"
- #include "MainFrm.h"
- //#include "MyStockDoc.h"
- #include "MyStockView.h"
- #include "GridCtrl.h"
- #include "STKDRV.h"
- CSTKDRV gSTOCKDLL;//数据接口对象
- BOOL m_bFirstWindow=FALSE;//全局变量
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- typedef struct tagMapData:public CObject
- {
- RCV_REPORT_STRUCTEx m_Report;
- }MapData,*pMapData;
- /////////////////////////////////////////////////////////////////////////////
- // CMyStockView
- IMPLEMENT_DYNCREATE(CMyStockView, CView)
- BEGIN_MESSAGE_MAP(CMyStockView, CView)
- //{{AFX_MSG_MAP(CMyStockView)
- ON_WM_CREATE()
- ON_WM_SHOWWINDOW()
- ON_WM_DESTROY()
- ON_WM_SIZE()
- ON_COMMAND(ID_STOCK, OnStock)
- ON_UPDATE_COMMAND_UI(ID_STOCK, OnUpdateStock)
- ON_COMMAND(ID_UNSTOCK, OnUnstock)
- ON_UPDATE_COMMAND_UI(ID_UNSTOCK, OnUpdateUnstock)
- //}}AFX_MSG_MAP
- // Standard printing commands
- ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
- ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
- ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
- ON_MESSAGE(My_Msg_StkData,OnStkDataOK)
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CMyStockView construction/destruction
- CMyStockView::CMyStockView()
- {
- m_bStocker=FALSE;
- m_nToal=0;
- m_FillCell=FALSE;
- m_bSHnumber=FALSE;
- m_bUpdataAllView=FALSE;
- m_wMarket=SH_MARKET_EX;
- m_sType="6";
- if(m_fSHFile.Open(".\SHnumber.txt",CFile::modeReadWrite))
- m_bSHnumber=true;
- }
- CMyStockView::~CMyStockView()
- {
- }
- BOOL CMyStockView::PreCreateWindow(CREATESTRUCT& cs)
- {
- // TODO: Modify the Window class or styles here by modifying
- // the CREATESTRUCT cs
- return CView::PreCreateWindow(cs);
- }
- /////////////////////////////////////////////////////////////////////////////
- // CMyStockView drawing
- void CMyStockView::OnDraw(CDC* pDC)
- {
- CMyStockDoc* pDoc = GetDocument();
- ASSERT_VALID(pDoc);
- if(!m_FillCell)
- SetGridData();
- if(m_bFirstWindow)
- pDC->TextOut(100,100,"蒋小利");
- }
- /////////////////////////////////////////////////////////////////////////////
- // CMyStockView printing
- BOOL CMyStockView::OnPreparePrinting(CPrintInfo* pInfo)
- {
- // default preparation
- return DoPreparePrinting(pInfo);
- }
- void CMyStockView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
- {
- // TODO: add extra initialization before printing
- }
- void CMyStockView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
- {
- // TODO: add cleanup after printing
- }
- /////////////////////////////////////////////////////////////////////////////
- // CMyStockView diagnostics
- #ifdef _DEBUG
- void CMyStockView::AssertValid() const
- {
- CView::AssertValid();
- }
- void CMyStockView::Dump(CDumpContext& dc) const
- {
- CView::Dump(dc);
- }
- CMyStockDoc* CMyStockView::GetDocument() // non-debug version is inline
- {
- ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMyStockDoc)));
- return (CMyStockDoc*)m_pDocument;
- }
- #endif //_DEBUG
- /////////////////////////////////////////////////////////////////////////////
- // CMyStockView message handlers
- int CMyStockView::OnCreate(LPCREATESTRUCT lpCreateStruct)
- {
- if (CView::OnCreate(lpCreateStruct) == -1)
- return -1;
- //创建动态显示牌表格:
- pGridFrame=new CMyGridFrame;
- pGridFrame->Create(NULL,NULL,WS_CHILD|WS_VISIBLE,CRect(0,0,800,600),this,ID_GRIDCTRL1);
- // pGridFrame->m_grid.SetFixedRowCount(1);//固定行(列标头)
- // pGridFrame->m_grid.SetFixedColumnCount(3);//固定列(行标头)
- // pGridFrame->m_grid.SetRowCount(501);//总行数
- // pGridFrame->m_grid.SetColumnCount(15);//总列数
- // pGridFrame->m_grid.SetColumnWidth(0,40);//指定列宽
- // pGridFrame->m_grid.SetHeaderSort(true);//允许排序
- // pGridFrame->m_grid.SetGridBkColor(RGB(255,255,255));
- //以下这些参数都可以用变量代替,以便和用户交互
- // pGridFrame->m_grid.SetFixedBkColor(RGB(255,255,255));
- // pGridFrame->m_grid.SetFixedTextColor(RGB(0,0,0));
- // pGridFrame->m_grid.SetItemText(0,1,"代 码");
- // pGridFrame->m_grid.SetItemText(0,2,"名 称");
- // pGridFrame->m_grid.SetItemText(0,3,"最新价");
- // pGridFrame->m_grid.SetItemText(0,4,"涨 跌");
- // pGridFrame->m_grid.SetItemText(0,5,"涨跌幅");
- // pGridFrame->m_grid.SetItemText(0,6,"总 手");
- // pGridFrame->m_grid.SetItemText(0,7,"最高价");
- // pGridFrame->m_grid.SetItemText(0,8,"最低价");
- // pGridFrame->m_grid.SetItemText(0,9,"今开盘");
- // pGridFrame->m_grid.SetItemText(0,10,"昨收盘");
- // pGridFrame->m_grid.SetItemText(0,11,"总 额");
- return 0;
- }
- void CMyStockView::OnShowWindow(BOOL bShow, UINT nStatus)
- {
- CView::OnShowWindow(bShow, nStatus);
- /* if(!m_bStocker)
- {
- gSTOCKDLL.GetStockDrvInfo(RI_SUPPORTEXTHQ,NULL); //设置 Szn Label6 Receive
- int ok = gSTOCKDLL.Stock_Init(m_hWnd,My_Msg_StkData,RCV_WORK_SENDMSG); // 数据共享引用
- if( ok > 0 )
- {
- //
- DWORD m_TV_Code = 201;
- gSTOCKDLL.GetStockDrvInfo(RI_ENABLETS3FILE,&m_TV_Code);
- m_bStocker=true;
- }
- }*/
- }
- void CMyStockView::OnDestroy()
- {
- CView::OnDestroy();
- gSTOCKDLL.Stock_Quit(m_hWnd);
- m_bStocker=FALSE; //窗口都已经销毁,无所谓了。
- }
- //接口响应函数
- LONG CMyStockView::OnStkDataOK(UINT wFileType,LONG lPara)
- {
- //MessageBox("Data OK!!!");//你可以用它检验接口
- CMyStockDoc* pDoc=GetDocument();
- int i;
- PBYTE pFileBuf = NULL;
- RCV_DATA * pHeader;
- pHeader = (RCV_DATA *) lPara;
- CString string;
- switch( wFileType )
- {
- case RCV_REPORT:
- {
- int nBufSize = pHeader->m_pReport[0].m_cbSize;
- PBYTE pBaseBuf = (PBYTE)&pHeader->m_pReport[0];
- for(i=0; i<pHeader->m_nPacketNum; i++)
- {
- pMapData m_mapdata=new MapData;
- ASSERT(m_mapdata);
- RCV_REPORT_STRUCTEx & Buf = *(PRCV_REPORT_STRUCTEx)(pBaseBuf + nBufSize*i );
- if(Buf.m_wMarket==m_wMarket)//SH_MARKET_EX )//上海市场
- {
- string=Buf.m_szLabel;
- CString cc=string.Left(1);
- if(!strcmp(cc,m_sType))//上海A股
- {
- if(!m_FillCell)
- {
- m_mapdata->m_Report.m_cbSize=Buf.m_cbSize;
- m_mapdata->m_Report.m_fAmount=Buf.m_fAmount;
- m_mapdata->m_Report.m_fBuyPrice[1]=Buf.m_fBuyPrice[1];
- m_mapdata->m_Report.m_fBuyPrice[2]=Buf.m_fBuyPrice[2];
- m_mapdata->m_Report.m_fBuyPrice[3]=Buf.m_fBuyPrice[3];
- m_mapdata->m_Report.m_fBuyPrice4=Buf.m_fBuyPrice4;
- // m_mapdata->m_Report.m_fBuyPrice5=Buf.m_fBuyPrice5;
- m_mapdata->m_Report.m_fBuyVolume[1]=Buf.m_fBuyVolume[1];
- m_mapdata->m_Report.m_fBuyVolume[2]=Buf.m_fBuyVolume[2];
- m_mapdata->m_Report.m_fBuyVolume[3]=Buf.m_fBuyVolume[3];
- m_mapdata->m_Report.m_fBuyVolume4=Buf.m_fBuyVolume4;
- // m_mapdata->m_Report.m_fBuyVolume5=Buf.m_fBuyVolume5;
- m_mapdata->m_Report.m_fHigh=Buf.m_fHigh;
- m_mapdata->m_Report.m_fLastClose=Buf.m_fLastClose;
- m_mapdata->m_Report.m_fLow=Buf.m_fLow;
- m_mapdata->m_Report.m_fNewPrice=Buf.m_fNewPrice;
- m_mapdata->m_Report.m_fOpen=Buf.m_fOpen;
- m_mapdata->m_Report.m_fSellPrice[1]=Buf.m_fSellPrice[1];
- m_mapdata->m_Report.m_fSellPrice[2]=Buf.m_fSellPrice[2];
- m_mapdata->m_Report.m_fSellPrice[3]=Buf.m_fSellPrice[3];
- m_mapdata->m_Report.m_fSellPrice4=Buf.m_fSellPrice4;
- // m_mapdata->m_Report.m_fSellPrice5=Buf.m_fSellPrice5;
- m_mapdata->m_Report.m_fSellVolume[1]=Buf.m_fSellVolume[1];
- m_mapdata->m_Report.m_fSellVolume[2]=Buf.m_fSellVolume[2];
- m_mapdata->m_Report.m_fSellVolume[3]=Buf.m_fSellVolume[3];
- m_mapdata->m_Report.m_fSellVolume4=Buf.m_fSellVolume4;
- // m_mapdata->m_Report.m_fSellVolume5=Buf.m_fSellVolume5;
- m_mapdata->m_Report.m_fVolume=Buf.m_fVolume;
- strcpy(m_mapdata->m_Report.m_szLabel,Buf.m_szLabel);
- strcpy(m_mapdata->m_Report.m_szName,Buf.m_szName);
- m_mapdata->m_Report.m_time=Buf.m_time;
- m_mapdata->m_Report.m_wMarket=Buf.m_wMarket;
- pDoc->m_DataMap.SetAt(string,m_mapdata);
- // pDoc->m_FileName="600198";//测试用
- SetGridData();
- if(m_nToal==pDoc->m_DataMap.GetCount())
- m_FillCell=true;
- m_nToal=pDoc->m_DataMap.GetCount();
- }
- if(m_FillCell)
- {
- for(int p=1;p<pGridFrame->m_grid.GetRowCount();p++)
- {
- CGridCellBase* pCell=pGridFrame->m_grid.GetCell(p,1);
- CString mystr=pCell->GetText();
- if(!mystr.IsEmpty())//如果不是空的
- {
- string.Format("%6s",Buf.m_szLabel);//代码
- if(!strcmp(mystr,string))//如果相等
- {
- pGridFrame->m_grid.SetItemText(p,1,string);
- string.Format("%8s",Buf.m_szName);//名称
- pGridFrame->m_grid.SetItemText(p,2,string);
- string.Format("%8.2f",Buf.m_fNewPrice);//最新
- pGridFrame->m_grid.SetItemText(p,3,string);
- string.Format("%8.2f",Buf.m_fNewPrice-Buf.m_fLastClose);//涨跌
- pGridFrame->m_grid.SetItemText(p,4,string);
- if(Buf.m_fNewPrice-Buf.m_fLastClose>0)
- {
- pGridFrame->m_grid.SetItemFgColor(p,4,RGB(255,0,0));
- pGridFrame->m_grid.SetItemFgColor(p,3,RGB(255,0,0));
- pGridFrame->m_grid.SetItemFgColor(p,5,RGB(255,0,0));
- pGridFrame->m_grid.SetItemFgColor(p,7,RGB(255,0,0));
- }
- if(Buf.m_fNewPrice-Buf.m_fLastClose<0)
- {
- pGridFrame->m_grid.SetItemFgColor(p,4,RGB(10,160,36));
- pGridFrame->m_grid.SetItemFgColor(p,3,RGB(10,160,36));
- pGridFrame->m_grid.SetItemFgColor(p,5,RGB(10,160,36));
- pGridFrame->m_grid.SetItemFgColor(p,7,RGB(10,160,36));
- }
- if(Buf.m_fNewPrice-Buf.m_fLastClose==0.00)
- {
- string.Format("%8.2f",0.00);
- }
- else
- {
- string.Format("%8.2f",(Buf.m_fNewPrice-Buf.m_fLastClose)/Buf.m_fLastClose*100);
- }
- string+="%";
- pGridFrame->m_grid.SetItemText(p,5,string);//涨跌幅
- string.Format("%10.0f",Buf.m_fVolume);//总手
- pGridFrame->m_grid.SetItemText(p,6,string);
- string.Format("%8.2f",Buf.m_fHigh);//最高
- if(Buf.m_fHigh>Buf.m_fLastClose)
- pGridFrame->m_grid.SetItemFgColor(p,7,RGB(255,0,0));
- if(Buf.m_fHigh<Buf.m_fLastClose)
- pGridFrame->m_grid.SetItemFgColor(p,7,RGB(10,160,36));
- pGridFrame->m_grid.SetItemText(p,7,string);
- string.Format("%8.2f",Buf.m_fLow);//最低
- if(Buf.m_fLow>Buf.m_fLastClose)
- pGridFrame->m_grid.SetItemFgColor(p,8,RGB(255,0,0));
- if(Buf.m_fLow<Buf.m_fLastClose)
- pGridFrame->m_grid.SetItemFgColor(p,8,RGB(10,160,36));
- pGridFrame->m_grid.SetItemText(p,8,string);
- string.Format("%8.2f",Buf.m_fOpen);//今开
- if(Buf.m_fOpen>Buf.m_fLastClose)
- pGridFrame->m_grid.SetItemFgColor(p,9,RGB(255,0,0));
- if(Buf.m_fOpen<Buf.m_fLastClose)
- pGridFrame->m_grid.SetItemFgColor(p,9,RGB(10,160,36));
- pGridFrame->m_grid.SetItemText(p,9,string);
- string.Format("%8.2f",Buf.m_fLastClose);//昨收
- pGridFrame->m_grid.SetItemText(p,10,string);
- string.Format("%10.0f",Buf.m_fAmount);//总额
- pGridFrame->m_grid.SetItemText(p,11,string);
- pGridFrame->m_grid.RedrawRow(p);
- //pDoc->m_FileName="600839";//测试用
- if(!(strcmp(string,pDoc->m_FileName)))
- m_bUpdataAllView=true;
- break;
- }
- }
- }
- }
- }
- if(m_bUpdataAllView)
- {
- pDoc->UpdateAllViews(this);
- m_bUpdataAllView=FALSE;
- }
- }
- }
- }
- break;
- case RCV_FILEDATA:
- if( !pHeader->m_pData || pHeader->m_wDataType == FILE_TYPE_RES)
- {
- TRACE("MSG: CStkDemo::OnStkDataOK, Replaced data n");
- break;
- }
- switch(pHeader->m_wDataType)
- {
- case FILE_HISTORY_EX: // 补日线数据
- break;
- case FILE_MINUTE_EX: // 补分钟线数据
- break;
- case FILE_BASE_EX: // 钱龙兼容基本资料文件,m_szFileName仅包含文件名
- break;
- case FILE_NEWS_EX: // 新闻类,其类型由m_szFileName中子目录名来定
- break;
- case FILE_SOFTWARE_EX:
- break;
- case FILE_SHAZQDATA_EX: //h上海国债净价交易
- break;
- default:
- TRACE("Msg: CStkDemo::OnStkDataOK,Unkonw data typen");
- }
- break;
- }
- //RedrawWindow();
- return 0L;
- }
- void CMyStockView::OnSize(UINT nType, int cx, int cy)
- {
- CView::OnSize(nType, cx, cy);
- pGridFrame->SetWindowPos(NULL,0,0,cx,cy,SWP_SHOWWINDOW);//调整表格
- //失能窗口的关闭按钮:
- CWnd* pParen=this->GetParent();
- CMenu* pmenu=pParen->GetSystemMenu(FALSE);
- if(! m_bFirstWindow)
- {
- if(pmenu)
- {
- pmenu->DeleteMenu(SC_CLOSE,MF_BYCOMMAND);
- }
- m_bFirstWindow=true;
- }
- }
- void CMyStockView::OnStock()
- {
- if(!m_bStocker)
- {
- gSTOCKDLL.GetStockDrvInfo(RI_SUPPORTEXTHQ,NULL); //设置 Szn Label6 Receive
- int ok = gSTOCKDLL.Stock_Init(m_hWnd,My_Msg_StkData,RCV_WORK_SENDMSG); // 数据共享引用
- if( ok > 0 )
- {
- //
- DWORD m_TV_Code = 201;
- gSTOCKDLL.GetStockDrvInfo(RI_ENABLETS3FILE,&m_TV_Code);
- m_bStocker=true;
- }
- }
- }
- void CMyStockView::OnUpdateStock(CCmdUI* pCmdUI)
- {
- if(m_bStocker)
- {
- pCmdUI->Enable(FALSE);
- }
- else
- {
- pCmdUI->Enable(true);
- }
- }
- int CMyStockView::SetGridData()
- {
- CMyStockDoc* pDoc = GetDocument();
- ASSERT_VALID(pDoc);
- POSITION pos=pDoc->m_DataMap.GetStartPosition();
- int lines=pDoc->m_DataMap.GetCount();
- if(lines>100)
- pGridFrame->m_grid.SetRowCount(lines+1);
- CString string,string1;
- pMapData m_pMapdata=new MapData;
- int row=1;
- while(pos !=NULL)
- {
- pDoc->m_DataMap.GetNextAssoc(pos,string1,(CObject *&)m_pMapdata);
- string.Format("%6s",m_pMapdata->m_Report.m_szLabel);//代码
- pGridFrame->m_grid.SetItemText(row,1,string);
- string.Format("%8s",m_pMapdata->m_Report.m_szName);//名称
- string1=string;
- pGridFrame->m_grid.SetItemText(row,2,string);
- string.Format("%8.2f",m_pMapdata->m_Report.m_fNewPrice);//最新
- pGridFrame->m_grid.SetItemText(row,3,string);
- string.Format("%8.2f",m_pMapdata->m_Report.m_fNewPrice-m_pMapdata->m_Report.m_fLastClose);//涨跌
- pGridFrame->m_grid.SetItemText(row,4,string);
- if(m_pMapdata->m_Report.m_fNewPrice-m_pMapdata->m_Report.m_fLastClose>0)
- {
- pGridFrame->m_grid.SetItemFgColor(row,4,RGB(255,0,0));
- pGridFrame->m_grid.SetItemFgColor(row,3,RGB(255,0,0));
- pGridFrame->m_grid.SetItemFgColor(row,5,RGB(255,0,0));
- pGridFrame->m_grid.SetItemFgColor(row,7,RGB(255,0,0));
- }
- if(m_pMapdata->m_Report.m_fNewPrice-m_pMapdata->m_Report.m_fLastClose<0)
- {
- pGridFrame->m_grid.SetItemFgColor(row,4,RGB(10,160,36));
- pGridFrame->m_grid.SetItemFgColor(row,3,RGB(10,160,36));
- pGridFrame->m_grid.SetItemFgColor(row,5,RGB(10,160,36));
- pGridFrame->m_grid.SetItemFgColor(row,7,RGB(10,160,36));
- }
- if(m_pMapdata->m_Report.m_fNewPrice-m_pMapdata->m_Report.m_fLastClose==0.00)
- {
- string.Format("%8.2f",0.00);
- }
- else
- {
- string.Format("%8.2f",(m_pMapdata->m_Report.m_fNewPrice-m_pMapdata->m_Report.m_fLastClose)/m_pMapdata->m_Report.m_fLastClose*100);
- }
- string+="%";
- pGridFrame->m_grid.SetItemText(row,5,string);//涨跌幅
- string.Format("%10.0f",m_pMapdata->m_Report.m_fVolume);//总手
- pGridFrame->m_grid.SetItemText(row,6,string);
- string.Format("%8.2f",m_pMapdata->m_Report.m_fHigh);//最高
- if(m_pMapdata->m_Report.m_fHigh>m_pMapdata->m_Report.m_fLastClose)
- pGridFrame->m_grid.SetItemFgColor(row,7,RGB(255,0,0));
- if(m_pMapdata->m_Report.m_fHigh<m_pMapdata->m_Report.m_fLastClose)
- pGridFrame->m_grid.SetItemFgColor(row,7,RGB(10,160,36));
- pGridFrame->m_grid.SetItemText(row,7,string);
- string.Format("%8.2f",m_pMapdata->m_Report.m_fLow);//最低
- if(m_pMapdata->m_Report.m_fLow>m_pMapdata->m_Report.m_fLastClose)
- pGridFrame->m_grid.SetItemFgColor(row,8,RGB(255,0,0));
- if(m_pMapdata->m_Report.m_fLow<m_pMapdata->m_Report.m_fLastClose)
- pGridFrame->m_grid.SetItemFgColor(row,8,RGB(10,160,36));
- pGridFrame->m_grid.SetItemText(row,8,string);
- string.Format("%8.2f",m_pMapdata->m_Report.m_fOpen);//今开
- if(m_pMapdata->m_Report.m_fOpen>m_pMapdata->m_Report.m_fLastClose)
- pGridFrame->m_grid.SetItemFgColor(row,9,RGB(255,0,0));
- if(m_pMapdata->m_Report.m_fOpen<m_pMapdata->m_Report.m_fLastClose)
- pGridFrame->m_grid.SetItemFgColor(row,9,RGB(10,160,36));
- pGridFrame->m_grid.SetItemText(row,9,string);
- string.Format("%8.2f",m_pMapdata->m_Report.m_fLastClose);//昨收
- pGridFrame->m_grid.SetItemText(row,10,string);
- string.Format("%10.0f",m_pMapdata->m_Report.m_fAmount);//总额
- pGridFrame->m_grid.SetItemText(row,11,string);
- row++;
- }
- pGridFrame->m_grid.Refresh();
- return 0;
- }
- void CMyStockView::OnUnstock()
- {
- gSTOCKDLL.Stock_Quit(m_hWnd);
- m_bStocker=FALSE;
- }
- void CMyStockView::OnUpdateUnstock(CCmdUI* pCmdUI)
- {
- if(!m_bStocker)
- {
- pCmdUI->Enable(FALSE);
- }
- else
- {
- pCmdUI->Enable(true);
- }
- }
- int CMyStockView::ONNewFile(CString string)
- {
- CMyStockDoc* pDoc=GetDocument();
- pDoc->m_FileName=string;
- CMainFrame* pFrame=(CMainFrame*)AfxGetMainWnd();
- pFrame->OnNewview();
- return 0;
- }