⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mystockview.cpp

📁 一种简单的股票软件源代码,编译后可以实时显示证券行情
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// 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))//如果相等
										  {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -