?? mystockview.cpp
字號:
// 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 + -