Stock.cpp
上传用户:gkp168
上传日期:2015-03-14
资源大小:334k
文件大小:26k
- #include <afxwin.h>
- #include <Windows.h>
- #include <afxtempl.h>
- #include "Stock.h"
- #define WM_IRQSTOCK (WM_USER+1000)
- #define WM_DrawDayLine 0x0400 + 100
- #define WM_DrawKLine 0x0400 + 101
- #define WM_DrawCommon 0x0400 + 102
- CMyApp theApp;
- BOOL CMyApp::InitInstance()
- {
- m_pMainWnd = new CMyFrame;
- m_pMainWnd->ShowWindow(m_nCmdShow);
- m_pMainWnd->UpdateWindow();
- return TRUE;
- }
- CMyApp::CMyApp()
- {
- }
- BEGIN_MESSAGE_MAP(CMyFrame, CWnd)
- ON_WM_CREATE()
- ON_WM_PAINT()
- ON_WM_KEYDOWN()
- ON_WM_KEYUP()
- ON_WM_LBUTTONDOWN()
- ON_MESSAGE(WM_IRQSTOCK, OnIRQSTOCK)
- ON_MESSAGE(WM_DrawDayLine, OnDrawDayLine)
- ON_MESSAGE(WM_DrawKLine, OnDrawKLine)
- ON_MESSAGE(WM_DrawCommon, OnDrawCommon)
- ON_COMMAND(4001,OnDayLine)
- ON_COMMAND(4002,OnKLine)
- END_MESSAGE_MAP()
- CMyFrame::CMyFrame()
- {
- ReStart();
- bReStart = FALSE; //默认是今天新打开的
- bKLine = FALSE; //默认是分时线
- DWORD size=0,ksize=0,asize=0;
- KBegine = 0;
- bCtrl = FALSE;
- KAmountMax = 1;
-
- CString strWndClass=AfxRegisterWndClass(CS_HREDRAW | CS_VREDRAW,
- AfxGetApp()->LoadStandardCursor(IDC_ARROW),
- (HBRUSH) GetStockObject (BLACK_BRUSH),
- AfxGetApp()->LoadStandardIcon(IDI_WINLOGO));
-
- CreateEx(0, strWndClass,_T("MFC股市软件"),
- WS_OVERLAPPED|WS_SYSMENU|WS_CAPTION|WS_MINIMIZEBOX,
- CW_USEDEFAULT,CW_USEDEFAULT,900,620,
- NULL,NULL);
- CMenu menuMain;
- menuMain.CreateMenu();
- menuMain.AppendMenu(MF_STRING,4001,"* 分时线 *");
- menuMain.AppendMenu(MF_POPUP,4002,"* K线 *"); //(UINT)menuPopup.Detach()
- SetMenu(&menuMain);
- menuMain.Detach();
-
- memset(&m_Stock,0, sizeof(m_Stock));//&m_Stock是指向m_Stock结构的指针,此时设定空间是0
- memset(&m_Data,0,sizeof(m_Data));//&m_Data是指向m_Data结构的指针,此时设定空间是0
-
-
- size=ReadDayLine(); //读入分时价格数据,及是否正常退出
- ksize=ReadKLine(); //读入K线价格数据
- asize=ReadKAmount(); //读入K线成交金额数据
- ExchangeK();
- if (size!=0)
- {
- Invalidate();
- }
- }
- CMyFrame::~CMyFrame()
- {
-
- }
- void CMyFrame::ReStart() //新一天开始
- {
- m=0;
- M=0;
- VolMax=1;
- VolLast=0;
- //VolLastDay=m_Stock.fVolume; //昨天总成交量
- //KAmountLastDay=m_Stock.fAmount; //昨日成交金额
- bNExit=FALSE; //非正常退出
- KHighMax = 0;
- KLowMin = 100;
- KDay = 60;
- KM = KHighMax - KLowMin;
- }
- LRESULT CMyFrame::OnIRQSTOCK(WPARAM wParam,LPARAM lParam)//是回调函数自定义消息的实现
- {
- (*m_EnableMessage)(0);//停止发送数据,
- long liMsgCounter = (*m_ReceiveInfo)();//返回:接收到的包数
-
- for(int i = 0; i < liMsgCounter; i++)
- {
- (*m_DataAcquisition)(&m_Data, i);
- ExpandPackage(m_Data);// 拆包并将数据存入相应的结构体中
- SendMessage(WM_DrawCommon,NULL,NULL);
- StoreDayLine();
- if( m>=240 ) //一天结束,存K线数据
- {
- KLine thisKLine;
- thisKLine.fOpen=m_Stock.fOpen;
- thisKLine.fClose=m_Stock.fNew;
- thisKLine.fHigh=m_Stock.fHigh;
- thisKLine.fLow=m_Stock.fLow;
- KLineArray.Add(thisKLine);
- StoreKLine();
- KAmount thisKAmout;
- thisKAmout.Amount = m_Stock.fAmount;
- KAmountArray.Add(thisKAmout);
- StoreKAmount();
-
- bReStart=TRUE; //新一天开始
- ReStart();
- Invalidate();
- }
- if(bKLine == FALSE)
- SendMessage(WM_DrawDayLine,NULL,NULL);
- }
-
- (*m_EnableMessage)(1); //允许发送数据
-
- return 1;
- }
- void CMyFrame::ExpandPackage(MAINSTRUCT Data)//---------------拆包
- {
- if(Data.Type == 0x10||Data.Type == 0x11||Data.Type == 0x20||Data.Type == 0x21)
- {
- //将Data的数据存储在m_Stock中
- sprintf(m_Stock.StockCode,"%.8s",Data.AllStruct.IndexAndStock.Code);//股票 代码
- sprintf(m_Stock.StockName,"%.10s", Data.AllStruct.IndexAndStock.Name);//股票名称
- m_Stock.fClose = (float)(Data.AllStruct.IndexAndStock.Close)/1000;//收盘价
- m_Stock.fOpen = (float)(Data.AllStruct.IndexAndStock.Open)/1000;//开盘价
- m_Stock.fNew = (float)(Data.AllStruct.IndexAndStock.New)/1000;// 最新价
- m_Stock.fHigh = (float)(Data.AllStruct.IndexAndStock.High)/1000;//最高价
- m_Stock.fLow = (float)(Data.AllStruct.IndexAndStock.Low)/1000;//最低价
- m_Stock.fVolume = (Data.AllStruct.IndexAndStock.Volume);// 总成交量 单位:股
- m_Stock.fAmount = (Data.AllStruct.IndexAndStock.Amount)/1000;;// 成交金额 单位:元
- m_Stock.Pbuy1 = (Data.AllStruct.IndexAndStock.Pbuy1);//买一
- m_Stock.Pbuy2 = (Data.AllStruct.IndexAndStock.Pbuy2);//买二
- m_Stock.Pbuy3 = (Data.AllStruct.IndexAndStock.Pbuy3);//买三
- m_Stock.Vbuy1 = (Data.AllStruct.IndexAndStock.Vbuy1);//买一
- m_Stock.Vbuy2 = (Data.AllStruct.IndexAndStock.Vbuy2);//买二
- m_Stock.Vbuy3 = (Data.AllStruct.IndexAndStock.Vbuy3);//买三
-
- m_Stock.Psell1 = (Data.AllStruct.IndexAndStock.Psell1);//卖一
- m_Stock.Psell2 = (Data.AllStruct.IndexAndStock.Psell2);//卖二
- m_Stock.Psell3 = (Data.AllStruct.IndexAndStock.Psell3);//卖三
- m_Stock.Vsell1 = (Data.AllStruct.IndexAndStock.Vsell1);//卖一
- m_Stock.Vsell2 = (Data.AllStruct.IndexAndStock.Vsell2);//卖二
- m_Stock.Vsell3 = (Data.AllStruct.IndexAndStock.Vsell3);//卖三
-
- M = ((m_Stock.fHigh-m_Stock.fClose) > (m_Stock.fClose-m_Stock.fLow)) ? (m_Stock.fHigh-m_Stock.fClose) * 1.1 : (m_Stock.fClose-m_Stock.fLow) * 1.1;
- if ( M < (m_Stock.fClose*0.07) )
- {
- M = m_Stock.fClose*0.07;
- }
- else
- {
- Invalidate();
- }
-
- Price[m]=m_Stock.fNew;
-
- //if(!bReStart)//不是重新开始
- //{
- if (m==0)
- {
- VolThis = m_Stock.fVolume;
- Vol[m] = VolThis;
- VolMax = VolThis;
- }
- else
- {
- VolThis=m_Stock.fVolume-VolLast;
- Vol[m] = VolThis;
- if( VolThis>VolMax )
- {
- VolMax = VolThis;
- }
- }
- VolLast = m_Stock.fVolume;
- //}
- /*else
- {
- if (m==0)
- {
- VolThis = m_Stock.fVolume-VolLastDay;
- Vol[m] = VolThis;
- VolMax = VolThis;
- }
- else
- {
- VolThis=m_Stock.fVolume-VolLast-VolLastDay;
- Vol[m] = VolThis;
- if( VolThis>VolMax )
- {
- VolMax = VolThis;
- }
- }
- VolLast = m_Stock.fVolume-VolLastDay;
- }*/
- m++;
-
- Exchange();
- ExchangeA(m);
- ExchangeV();
- }
- }
- void CMyFrame::StoreDayLine()
- {
- int i=0;
- try
- {
- CFile file(_T("dayline.txt"), CFile::modeReadWrite);
- CArchive ar(&file,CArchive::store);
- ar<<bNExit<<m<<M<<VolMax<<m_Stock.fClose;
- for ( i=0; i<m; i++ )
- {
- ar<<Price[i];
- ar<<Vol[i];
- }
- }
- catch(CFileException* e)
- {
- e->ReportError();
- e->Delete();
- }
- }
- DWORD CMyFrame::ReadDayLine() //返回文件大小
- {
- int i=0;
- DWORD size=0;
- try
- {
- CFile file(_T("dayline.txt"), CFile::modeReadWrite);
- CArchive ar(&file,CArchive::load);
-
- size = file.GetLength();
- if (size==0)
- {
- return 0;
- }
-
- ar>>bNExit>>m>>M>>VolMax>>m_Stock.fClose;
- for( i=0; i<m; i++ )
- {
- ar>>Price[i];
- ar>>Vol[i];
- }
-
- for( i=0; i<m; i++ )
- {
- ExchangeA(i+1);
- }
-
- return size;
- }
- catch(CFileException* e)
- {
- e->ReportError();
- e->Delete();
- }
- return size;
- }
- void CMyFrame::StoreKLine()
- {
- int i=0;
- try
- {
- CFile file(_T("kline.txt"), CFile::modeReadWrite);
- CArchive ar(&file,CArchive::store);
- for ( i=0; i<KLineArray.GetSize(); i++ )
- {
- ar<<KLineArray[i].fOpen<<KLineArray[i].fClose<<KLineArray[i].fHigh<<KLineArray[i].fLow;
- }
-
- }
- catch(CFileException* e)
- {
- e->ReportError();
- e->Delete();
- }
- }
- DWORD CMyFrame::ReadKLine()
- {
- DWORD size=0;
- int i=0;
- float myArray[1][4];
- KLine aKLine;
- try
- {
- CFile file(_T("kline.txt"), CFile::modeReadWrite);
- CArchive ar(&file,CArchive::load);
-
- size=file.GetLength();
- if (size==0)
- {
- return 0;
- }
- int n=size/(4*4);
- for ( i=0; i<n; i++ )
- {
- ar>>myArray[0][0]>>myArray[0][1]>>myArray[0][2]>>myArray[0][3];
- aKLine.fOpen = myArray[0][0];
- aKLine.fClose = myArray[0][1];
- aKLine.fHigh = myArray[0][2];
- aKLine.fLow = myArray[0][3];
- KLineArray.SetAtGrow(i,aKLine);
- }
-
- return size;
- }
- catch(CFileException* e)
- {
- e->ReportError();
- e->Delete();
- }
- return size;
- }
- void CMyFrame::StoreKAmount()
- {
- int i=0;
- try
- {
- CFile file(_T("kamount.txt"), CFile::modeReadWrite);
- CArchive ar(&file,CArchive::store);
- for ( i=0; i<KAmountArray.GetSize(); i++ )
- {
- ar<<KAmountArray[i].Amount;
- }
- }
- catch(CFileException* e)
- {
- e->ReportError();
- e->Delete();
- }
- }
- DWORD CMyFrame::ReadKAmount()
- {
- DWORD size=0;
- int i=0;
- float Amount=0;
- KAmount aKAmount;
- try
- {
- CFile file(_T("kamount.txt"), CFile::modeReadWrite);
- CArchive ar(&file,CArchive::load);
-
- size=file.GetLength();
- if (size==0)
- {
- return 0;
- }
- int n=size/4;
- for ( i=0; i<n; i++ )
- {
- ar>>Amount;
- aKAmount.Amount=Amount;
- KAmountArray.SetAtGrow(i,aKAmount);
- }
-
- return size;
- }
- catch(CFileException* e)
- {
- e->ReportError();
- e->Delete();
- }
- return size;
- }
- //////////////////////////////////////////////////////////////////////////
- //转换函数
- //
- void CMyFrame::Exchange()
- {
- int x=0,i=0;
-
- for ( i=0; i<m; i++ )
- {
- x = (int)(150 * ( Price[i] - m_Stock.fClose ) / M );
- Point[i][0]=80+i*2;
- Point[i][1]=40+150-x;
- }
- }
- void CMyFrame::ExchangeA(int m)
- {
- int x=0,i=0;
- float total1;
- float total2;
- float aver=0;
-
- total1=0;
- total2=0;
-
- for (i=0;i<m;i++)
- {
- total1=total1+Price[i]*Vol[i];
- total2=total2+Vol[i];
- }
-
- aver=total1/total2;
-
- x = (int)(150 * ( aver - m_Stock.fClose ) / M );
- PointAver[m-1][0]=80+i*2;
- PointAver[m-1][1]=40+150-x;
- }
- void CMyFrame::ExchangeV()
- {
- int x=0,i=0;
-
- for ( i=0; i<m; i++ )
- {
- x = (int)(150 * ( Vol[i] ) / VolMax );
- VPoint[i][0]=80+i*2;
- VPoint[i][1]=40+150*3-x;
- }
- }
- void CMyFrame::ExchangeK()
- {
- int x=0,i=0;
- float a=0,b=0,lw=0;
- CRect rect;
- POINT client;
- POINT high,low,open,close;
- KPoint aKPoint;
- GetClientRect(&rect);
- client.x = rect.Width();
- client.y = rect.Height();
- int n = KLineArray.GetSize();
- for ( i=0; i<n; i++ )
- {
- if (KLineArray[i].fHigh > KHighMax)
- {
- KHighMax = KLineArray[i].fHigh;
- }
- if (KLineArray[i].fLow < KLowMin)
- {
- KLowMin = KLineArray[i].fLow;
- }
- }
- KM = KHighMax - KLowMin;
- a = (client.y-120)/2 -20;//垂直高度
- b = client.x - 220 - 80;//水平高度
- lw = b/(KDay*5);//每个K线中每个小格的水平宽度
- for ( i=0; i<n; i++ )
- {
- high.x = 80 + (i*5+3)*lw ;
- high.y = 70+a-(KLineArray[i].fHigh - KLowMin)*a/KM;
-
- low.x = 80 + (i*5+3)*lw ;
- low.y = 70+a-(KLineArray[i].fLow - KLowMin)*a/KM;
- open.x = 80 + (i*5+1)*lw ;
- open.y = 70+a-(KLineArray[i].fOpen - KLowMin)*a/KM;
-
- close.x = 80 + (i*5+5)*lw ;
- close.y = 70+a-(KLineArray[i].fClose - KLowMin)*a/KM;
- aKPoint.high = high;
- aKPoint.low = low;
- aKPoint.open = open;
- aKPoint.close = close;
- KPointArray.SetAtGrow(i,aKPoint);
- }
- }
- void CMyFrame::ExchangeKAmount()
- {
- int i=0;
- float c=0,b=0,lw=0;
- CRect rect;
- POINT client;
- float high;
- POINT top,bottom;
- KAmountPoint aKAmountPoint;
-
- GetClientRect(&rect);
- client.x = rect.Width();
- client.y = rect.Height();
-
- c = (client.y-120)/4 -20; //垂直高度
- b = client.x - 220 - 80; //水平宽度
-
- lw = b/(KDay*5);//每个K线中每个小格的水平宽度
-
- int n = KAmountArray.GetSize();
- for ( i=0; i<n; i++ )
- {
- float temp = KAmountArray[i].Amount;
- if (KAmountArray[i].Amount > KAmountMax)
- {
- KAmountMax = KAmountArray[i].Amount;
- }
- }
-
- for ( i=0; i<n; i++ )
- {
- float temp1 = KAmountArray[i].Amount;
- top.x = 80 + (i*5+1)*lw ;
- top.y = 50+(c+20)*3-KAmountArray[i].Amount*c/KAmountMax;
-
- bottom.x = 80 + (i*5+5)*lw ;
- bottom.y = 50+(c+20)*3;
-
- aKAmountPoint.top = top;
- aKAmountPoint.bottom = bottom;
-
- KAmountPointArray.SetAtGrow(i,aKAmountPoint);
- }
- }
- void CMyFrame::OnKeyDown( UINT nChar, UINT nRepCnt, UINT nFlags )
- {
- switch(nChar)
- {
- case VK_F11:
- M=M*0.5;
- Exchange();
- Invalidate();
- break;
- case VK_F12:
- M=M*1.5;
- Exchange();
- Invalidate();
- break;
- case VK_F5:
- bKLine = (bKLine == FALSE) ? TRUE:FALSE;
- Invalidate();
- break;
- case VK_RIGHT:
- if (bCtrl)
- {
- KBegine+=5;
- }
- else
- {
- KBegine++;
- }
- if (bKLine==TRUE)
- {
- Invalidate();
- }
- break;
- case VK_LEFT:
- if (bCtrl)
- {
- KBegine-=5;
- }
- else
- {
- KBegine--;
- }
- if (bKLine==TRUE)
- {
- Invalidate();
- }
- break;
- case VK_UP:
- KDay+=10;
- if (bKLine==TRUE)
- {
- Invalidate();
- }
- break;
- case VK_DOWN:
- if (KDay>1)
- {
- KDay-=10;
- }
- if (bKLine==TRUE)
- {
- Invalidate();
- }
- break;
- case VK_CONTROL:
- bCtrl=TRUE;
- break;
- default:
- break;
- }
- }
- void CMyFrame::OnKeyUp( UINT nChar, UINT nRepCnt, UINT nFlags )
- {
- switch(nChar)
- {
- case VK_CONTROL:
- bCtrl=FALSE;
- break;
- default:
- break;
- }
- }
- void CMyFrame::OnDayLine()
- {
- bKLine = FALSE;
- Invalidate();
- }
- void CMyFrame::OnKLine()
- {
- bKLine = TRUE;
- ExchangeK();
- Invalidate();
- }
- void CMyFrame::OnLButtonDown(UINT nFlags, CPoint point)
- {
- static int lx=0,ly=0;
- int x=0,y=0,i;
- char chName[100];
- CClientDC dc(this);
- CPen dashpen(PS_DOT,1,RGB(200,200,0));
- CPen blackpen(PS_DOT,1,RGB(0,0,0));
-
- dc.SetBkMode(TRANSPARENT);
- dc.SelectObject(&dashpen);
-
- x = point.x;
- y = point.y;
-
- if ( x>80 && x < 80+480 )
- {
- dc.SelectObject(&dashpen);
- dc.MoveTo(x,40+2);
- dc.LineTo(x,40+300-2);
- dc.SelectObject(&blackpen);
- dc.MoveTo(lx,40+2);
- dc.LineTo(lx,40+300-2);
- }
-
- /*for(i=0;i<=m;i++)//有问题
- {
- if(Point[i][0]==x||Point[i][1]==y)
- {
- sprintf(chName, "%8s%6.2f", "价格",Price[i]);
- dc.TextOut(800, 530, chName, lstrlen(chName)-1);
- }
- }*/
-
- lx = point.x;
- ly = point.y;
- }
- void CMyFrame::OnCreate()
- {
- m_hLibrary = ::LoadLibrary("..\Fstrcv\Debug\fstrcv.dll");//装库
- INITCARD* lpfunction = (INITCARD*)::GetProcAddress(m_hLibrary, "InitCard");
- unsigned int uiCardNumber = (*lpfunction)((this->m_hWnd), WM_IRQSTOCK);
-
- m_EnableMessage = (ENABLEMESSAGE*)::GetProcAddress(m_hLibrary, "EnableMessage");
- //m_MyCount = (READMYCOUNT*)::GetProcAddress(m_hLibrary, "ReadMyCount");
- m_ReceiveInfo = (RECEIVEINFO*)::GetProcAddress(m_hLibrary, "ReceiveInfo");
- m_DataAcquisition = (DATAACQUISITION*)::GetProcAddress(m_hLibrary, "DataAcquisition");
- }
- ///////////////////////////////////////////////////
- /// 画图消息
- ///
- void CMyFrame::OnDrawCommon(WPARAM wParam,LPARAM lParam)//画公共动态数据
- {
- CClientDC dc(this);
- CRect rect;
- char chName[300];
- CPoint client;
- GetClientRect (&rect);
- client.x=rect.right;
- client.y=rect.bottom;
- dc.SetBkMode(OPAQUE);
- dc.SetBkColor(RGB(0,0,0));
- dc.SetTextColor(RGB(255,255,255));
- //卖
- rect.left = client.x-199;
- rect.top = 60;
- rect.right = client.x-11;
- rect.bottom = 60+60;
-
- dc.SelectStockObject(BLACK_BRUSH);
- dc.Rectangle(&rect);
- sprintf(chName, "%8s%10.2f%10.2fn", "卖一",(float)m_Stock.Psell1,(float)m_Stock.Vsell1);
- dc.TextOut(client.x-198, 60, chName, lstrlen(chName)-1);
- sprintf(chName, "%8s%10.2f%10.2fn", "卖二",(float)m_Stock.Psell2,(float)m_Stock.Vsell2);
- dc.TextOut(client.x-198, 60+20, chName, lstrlen(chName)-1);
- sprintf(chName, "%8s%10.2f%10.2fn", "卖三",(float)m_Stock.Psell3,(float)m_Stock.Vsell3);
- dc.TextOut(client.x-198, 60+40, chName, lstrlen(chName)-1);
-
- //买
- rect.left = client.x-199;
- rect.top = 140;
- rect.right = client.x-11;
- rect.bottom = 140+60;
-
- dc.SelectStockObject(BLACK_BRUSH);
- dc.Rectangle(&rect);
- sprintf(chName, "%8s%10.2f%10.2fn", "买一",(float)m_Stock.Pbuy1,(float)m_Stock.Vbuy1);
- dc.TextOut(client.x-198, 140, chName, lstrlen(chName)-1);
- sprintf(chName, "%8s%10.2f%10.2fn", "买二",(float)m_Stock.Pbuy2,(float)m_Stock.Vbuy2);
- dc.TextOut(client.x-198, 140+20, chName, lstrlen(chName)-1);
- sprintf(chName, "%8s%10.2f%10.2fn", "买三",(float)m_Stock.Pbuy3,(float)m_Stock.Vbuy3);
- dc.TextOut(client.x-198, 140+40, chName, lstrlen(chName)-1);
- //动态信息
- rect.left = client.x-199;
- rect.top = 220;
- rect.right = client.x-11;
- rect.bottom = 220+120;
-
- dc.SelectStockObject(BLACK_BRUSH);
- dc.Rectangle(&rect);
- dc.SetBkMode(TRANSPARENT);
-
- sprintf(chName, "%8s%6.2f%8s%6.2fn", "开盘价",m_Stock.fOpen,"最新价",m_Stock.fNew);
- dc.TextOut(client.x-205, 220, chName, lstrlen(chName)-1);
- sprintf(chName, "%8s%6.2f%8s%6.2fn", "最高价",m_Stock.fHigh,"最低价",m_Stock.fLow);
- dc.TextOut(client.x-205, 220+20, chName, lstrlen(chName)-1);
- sprintf(chName, "%8s%6d%10s%6.2fn", "笔 数",m,"价格增量",M);
- dc.TextOut(client.x-205, 220+40, chName, lstrlen(chName)-1);
- sprintf(chName, "%12s%6.0fn","最大成交量",VolMax);
- dc.TextOut(client.x-205, 220+60, chName, lstrlen(chName)-1);
- if (bKLine)
- {
- sprintf(chName, "%18s%8.0fn","最大天成交(万元)",KAmountMax/10000);
- dc.TextOut(client.x-205, 220+80, chName, lstrlen(chName)-1);
- }
- /*int temp = (*m_MyCount)();
- sprintf(chName, "%10s%5dn","发送数量",temp);
- dc.TextOut(client.x-205, 220+100, chName, lstrlen(chName)-1);*/
- }
- void CMyFrame::OnDrawDayLine(WPARAM wParam,LPARAM lParam)
- {
- int i=0;
- float M6=0,price=0;
- float percent=0;
- int V6=0;
- int voly=0;
- CClientDC dc(this);
- CRect rect;
- char chName[300];
- CPoint client;
- CPen whitepen(PS_SOLID,1,RGB(255,255,255));
- CPen yellowpen(PS_SOLID,1,RGB(255,255,0));
- CPen blackpen(PS_SOLID,1,RGB(0,0,0));
-
- dc.SetBkMode(OPAQUE);
- dc.SetBkColor(RGB(0,0,0));
- dc.SetTextColor(RGB(255,255,255));
-
- //画坐标值
- M6=M/6;
- if ( m>0 )
- {
- for ( i=0; i<13; i++ )
- {
- //左边
- price=M6*(6-i)+m_Stock.fClose;
- sprintf(chName, "%10.2f", price);
- dc.TextOut(15, 33+i*25, chName, lstrlen(chName));
-
- //右边
- percent=(M6*(6-i)/m_Stock.fClose)*100;
- sprintf(chName, "%10.2f%%", percent);
- dc.TextOut(560, 33+i*25, chName, lstrlen(chName));
- }
- }
- //画分时线
- dc.SetBkMode(TRANSPARENT);
- dc.SelectObject(&whitepen);
-
- dc.MoveTo(Point[0][0],Point[0][1]);
- for( i=1; i<m; i++ )
- {
- dc.LineTo(Point[i][0],Point[i][1]);
- }
- //加权平均线
- dc.SelectObject(&yellowpen);
- dc.MoveTo(PointAver[0][0],PointAver[0][1]);
- for( i=1; i<m; i++ )
- dc.LineTo(PointAver[i][0],PointAver[i][1]);
-
- //画成交量线
- dc.SelectObject(&yellowpen);
- for( i=0; i<m; i++ )
- {
- dc.MoveTo(80+i*2,487);
- dc.LineTo(VPoint[i][0],VPoint[i][1]);
- }
-
- //画成交量坐标值
- V6 = VolMax/6;
- if ( m>0 )
- {
- dc.SelectObject(&blackpen);
- rect.top = 57+300;
- rect.bottom = 57+300+5*25;
- rect.left = 15;
- rect.right = 75;
- dc.SelectStockObject(BLACK_BRUSH);
- dc.Rectangle(&rect);
- for ( i=0; i<5; i++ )
- {
- voly=VolMax-V6*(i+1);
- sprintf(chName, "%10.2d", voly);
- dc.TextOut(10, 57+300+i*25, chName, lstrlen(chName));
- }
- }
- }
- void CMyFrame::OnDrawKLine(WPARAM wParam,LPARAM lParam)
- {
- int i=0;
- int a=0,b=0;
- CClientDC dc(this);
- CRect rect;
- RECT kRect,kaRect;
- CPoint client;
- CPen whitepen(PS_SOLID,1,RGB(255,255,255));
- CPen blackpen(PS_SOLID,1,RGB(0,0,0));
-
- CPen cyanPen(PS_SOLID,1,RGB(116,245,240));
- CBrush cyanBrush(RGB(116,245,240));
-
- CPen redPen(PS_SOLID,1,RGB(220,112,116));
- CBrush blackBrush(RGB(0,0,0));
-
- char chName[200];
-
- GetClientRect(&rect);
- client.x = rect.Width();
- client.y = rect.Height();
- a = (client.y-120)/2 -20;//垂直高度
- b = client.x - 220 - 80;//水平宽度
-
- //画K线
- ExchangeK();
- ExchangeKAmount();
- dc.SetBkMode(OPAQUE);
- int n = KPointArray.GetSize();
- //for( i=KBegine; (i<KBegine+KDay) && (i<n) ; i++ )
- for( i=0; i<n ; i++ )
- {
- if (KPointArray[i].close.y<KPointArray[i].open.y) //升了,用红色线
- {
- dc.SelectObject(&redPen);
- dc.SelectObject(&blackBrush);
- }
- else //降了,用青色线
- {
- dc.SelectObject(&cyanPen);
- dc.SelectObject(&cyanBrush);
- }
- if ( KPointArray[i].high.x + KBegine*(b/KDay) > 80 && KPointArray[i].high.x + KBegine*(b/KDay) < 80+b )
- {
- dc.MoveTo(KPointArray[i].high.x + KBegine*(b/KDay), KPointArray[i].high.y ); //画最高价与最底价
- dc.LineTo(KPointArray[i].low.x + KBegine*(b/KDay), KPointArray[i].low.y );
- kRect.left = KPointArray[i].open.x + KBegine*(b/KDay);
- kRect.top = KPointArray[i].open.y ;
- kRect.right = KPointArray[i].close.x + KBegine*(b/KDay);
- kRect.bottom = KPointArray[i].close.y ;
- dc.Rectangle(&kRect); //画矩形
-
- kaRect.left = KAmountPointArray[i].top.x + KBegine*(b/KDay);
- kaRect.top = KAmountPointArray[i].top.y ;
- kaRect.right = KAmountPointArray[i].bottom.x + KBegine*(b/KDay);
- kaRect.bottom = KAmountPointArray[i].bottom.y ;
- dc.Rectangle(&kaRect); //画矩形
- }
- }
-
- dc.SetBkMode(TRANSPARENT);
- dc.SetTextColor(RGB(255,255,255));
-
- //画K线坐标值
- for ( i=0; i<6; i++ )
- {
- sprintf(chName, "%10.2f", KHighMax-(KM/5)*i);
- dc.TextOut(18, 65+i*(a/5-2), chName, lstrlen(chName));
- }
-
- //画K线成交金额坐标值
- dc.SetBkMode(OPAQUE);
- dc.SetBkColor(RGB(0,0,0));
- dc.SetTextColor(RGB(255,255,255));
- for ( i=0; i<3; i++ )
- {
- sprintf(chName, "%8.0f", (KAmountMax-(KAmountMax/2)*i)/10000);
- dc.TextOut(18, 290+i*43, chName, lstrlen(chName));
- }
- }
- void CMyFrame::OnPaint()//画静态信息
- {
- int i=0;
- CPaintDC dc(this);
- CRect rect;
- char chName[300];
- CPoint client;
- CPen redpen(PS_SOLID,2,RGB(153,0,0));
- CPen dashpen(PS_DOT,1,RGB(255,255,255));
-
- if ( bKLine == FALSE ) //分时线状态,画分时线的静态数据
- {
- dc.SetBkMode(TRANSPARENT);
- dc.SetTextColor(RGB(255,255,255));
-
- GetClientRect (&rect);
- client.x=rect.right;
- client.y=rect.bottom;
- rect.bottom = 40;
- rect.top = 20;
- rect.left = client.x-200;
- rect.right = client.x-10;
- dc.DrawText(_T("G浦发 600000"),-1,&rect,DT_SINGLELINE|DT_CENTER|DT_VCENTER);
- rect.bottom = 40;
- rect.top = 20;
- rect.left = client.x-220;
- rect.right = 20;
- dc.DrawText(_T("G浦发 600000.sh"),-1,&rect,DT_SINGLELINE|DT_CENTER|DT_VCENTER);
-
- //右外边框
- dc.SelectObject(&redpen);
- dc.MoveTo (client.x-200, 50);
- dc.LineTo (client.x-10, 50);
- dc.LineTo (client.x-10, client.y-50);
- dc.LineTo (client.x-200, client.y-50);
- dc.LineTo (client.x-200, 50);
- //左外边框
- dc.MoveTo (10, 10);
- dc.LineTo (client.x-220, 10);
- dc.LineTo (client.x-220, client.y-50);
- dc.LineTo (10, client.y-50);
- dc.LineTo (10, 10);
- //右外边框中的横线
- /*for(i=0;i<4;i++)
- {
- dc.MoveTo (client.x-200, (i+1)*(client.y-100)/4+50);
- dc.LineTo (client.x-10, (i+1)*(client.y-100)/4+50);
- }*/
- dc.MoveTo (client.x-200, 130);
- dc.LineTo (client.x-10, 130);
- dc.MoveTo (client.x-200, 210);
- dc.LineTo (client.x-10, 210);
- dc.MoveTo (client.x-200, 350);
- dc.LineTo (client.x-10, 350);
-
- //背景虚线
- dc.SelectObject(&dashpen);
- for ( i=0; i<17; i++ )
- {
- dc.MoveTo( 80, 40+(i+1)*25 );
- dc.LineTo( 80+120*4, 40+(i+1)*25 );
- }
-
- //画左边框日线边框
- dc.SelectObject(&redpen);
- rect.left = 80;
- rect.top = 40;
- rect.right = 560;
- rect.bottom = 490;
- dc.SelectStockObject(NULL_BRUSH);
- dc.Rectangle(&rect);
- //画下边框
- rect.left = 10;
- rect.top = 525;
- rect.right = client.x-10;
- rect.bottom = client.y-5;
- dc.Rectangle(&rect);
-
- //画下边框内文字
- sprintf(chName, "%8s", "◆金花股份收购西商行面临两大法律障碍");
- dc.TextOut(15, 535, chName, lstrlen(chName));
-
- //画横中间实线
- for ( i =0; i<2; i++ )
- {
- dc.MoveTo( 80, 40+(i+1)*150 );
- dc.LineTo( 80+120*4, 40+(i+1)*150 );
- }
-
- //画中间竖实线
- for ( i =0; i<3; i++ )
- {
- dc.MoveTo( 80+(i+1)*120, 40 );
- dc.LineTo( 80+(i+1)*120, 40+150*3 );
- }
-
- //画时间信息
- sprintf(chName, "%s%26s%26s%26s%26s", "09:30","10:30","13:00","14:00","15:00");
- dc.TextOut(62, 490, chName, lstrlen(chName));
-
-
- //画动态分时线
- SendMessage(WM_DrawCommon,NULL,NULL);
- SendMessage(WM_DrawDayLine,NULL,NULL); //画动态信息
- }
- else //画K线
- {
- dc.SetBkMode(TRANSPARENT);
- dc.SetTextColor(RGB(255,255,255));
-
- GetClientRect (&rect);
- client.x=rect.right;
- client.y=rect.bottom;
- rect.bottom = 40;
- rect.top = 20;
- rect.left = client.x-200;
- rect.right = client.x-10;
- dc.DrawText(_T("G浦发 600000"),-1,&rect,DT_SINGLELINE|DT_CENTER|DT_VCENTER);
-
-
- /////////////////右外边框
- dc.SelectObject(&redpen);
- dc.MoveTo (client.x-200, 50);
- dc.LineTo (client.x-10, 50);
- dc.LineTo (client.x-10, client.y-50);
- dc.LineTo (client.x-200, client.y-50);
- dc.LineTo (client.x-200, 50);
- //右外边框中的横线
- dc.MoveTo (client.x-200, 130);
- dc.LineTo (client.x-10, 130);
- dc.MoveTo (client.x-200, 210);
- dc.LineTo (client.x-10, 210);
-
- dc.MoveTo (client.x-200, 350);
- dc.LineTo (client.x-10, 350);
- //////////////////////////////左边
- //左外边框
- dc.MoveTo (10, 10);
- dc.LineTo (client.x-220, 10);
- dc.LineTo (client.x-220, client.y-50);
- dc.LineTo (10, client.y-50);
- dc.LineTo (10, 10);
-
- //画所有横线
- //上第一横线
- dc.MoveTo (10,50);
- dc.LineTo (client.x-220, 50);
- //上短线
- dc.MoveTo (80,70);
- dc.LineTo (client.x-220, 70);
- //中间第一横线
- dc.MoveTo (10,client.y-70);
- dc.LineTo (client.x-220,client.y-70);
- //下边横线
- dc.MoveTo (10, 50+(client.y-120)/2);
- dc.LineTo (client.x-220, 50+(client.y-120)/2);
- //下短线1
- dc.MoveTo (80,50+(client.y-120)/2+20);
- dc.LineTo (client.x-220,50+(client.y-120)/2+20);
- //下短线2
- dc.MoveTo (80, 50+(client.y-120)*3/4);
- dc.LineTo (client.x-220, 50+(client.y-120)*3/4);
- //下短线3
- dc.MoveTo (80,50+(client.y-120)*3/4+20);
- dc.LineTo (client.x-220, 50+(client.y-120)*3/4+20);
-
- //竖红线
- dc.MoveTo( 80, 50 );
- dc.LineTo( 80, client.y-70 );
-
-
- //背景虚线
- dc.SelectObject(&dashpen);
- for ( i=0; i<4; i++ )
- {
- dc.MoveTo( 80, 70+(i+1)*( ( (client.y-120)/2-20 )/5 ) );
- dc.LineTo( client.x-220, 70+(i+1)*( ( (client.y-120)/2-20 )/5 ) );
- }
- //下方虚线
- dc.MoveTo (80, 50+(client.y-120)/2+20+( (client.y-120)/4-20 )/2 + (client.y-120)/4 );
- dc.LineTo (client.x-220, 50+(client.y-120)/2+20+( (client.y-120)/4-20 )/2 + (client.y-120)/4 );
- dc.MoveTo (80, 50+(client.y-120)/2+20+( (client.y-120)/4-20 )/2 );
- dc.LineTo (client.x-220, 50+(client.y-120)/2+20+( (client.y-120)/4-20)/2 );
-
- //画下边框
- dc.SelectStockObject(NULL_BRUSH);
- dc.SelectObject(&redpen);
- rect.left = 10;
- rect.top = 525;
- rect.right = client.x-10;
- rect.bottom = client.y-5;
- dc.Rectangle(&rect);
-
- //画下边框内文字
- sprintf(chName, "%8s", "◆金花股份收购西商行面临两大法律障碍");
- dc.TextOut(15, 535, chName, lstrlen(chName));
-
- //画动态分时线
- SendMessage(WM_DrawCommon,NULL,NULL);
- SendMessage(WM_DrawKLine,NULL,NULL);
- }
- }