Stock.cpp
上传用户:gkp168
上传日期:2015-03-14
资源大小:334k
文件大小:26k
源码类别:

金融证券系统

开发平台:

Visual C++

  1. #include <afxwin.h>
  2. #include <Windows.h>
  3. #include <afxtempl.h>
  4. #include "Stock.h"
  5. #define WM_IRQSTOCK (WM_USER+1000)
  6. #define WM_DrawDayLine  0x0400 + 100
  7. #define WM_DrawKLine  0x0400 + 101
  8. #define WM_DrawCommon  0x0400 + 102
  9. CMyApp theApp;
  10. BOOL CMyApp::InitInstance()      
  11. {
  12. m_pMainWnd = new CMyFrame;
  13.     m_pMainWnd->ShowWindow(m_nCmdShow);
  14.     m_pMainWnd->UpdateWindow();
  15. return TRUE;
  16. }
  17. CMyApp::CMyApp()
  18. {
  19. }
  20. BEGIN_MESSAGE_MAP(CMyFrame, CWnd)
  21. ON_WM_CREATE()                      
  22. ON_WM_PAINT()
  23. ON_WM_KEYDOWN()
  24. ON_WM_KEYUP()
  25. ON_WM_LBUTTONDOWN()
  26. ON_MESSAGE(WM_IRQSTOCK, OnIRQSTOCK)
  27. ON_MESSAGE(WM_DrawDayLine, OnDrawDayLine)
  28. ON_MESSAGE(WM_DrawKLine, OnDrawKLine)
  29. ON_MESSAGE(WM_DrawCommon, OnDrawCommon)
  30. ON_COMMAND(4001,OnDayLine)
  31. ON_COMMAND(4002,OnKLine)
  32. END_MESSAGE_MAP()
  33. CMyFrame::CMyFrame()
  34. {
  35. ReStart();
  36. bReStart = FALSE; //默认是今天新打开的
  37. bKLine = FALSE; //默认是分时线 
  38. DWORD size=0,ksize=0,asize=0;
  39. KBegine = 0;
  40. bCtrl = FALSE;
  41. KAmountMax = 1;
  42.     CString strWndClass=AfxRegisterWndClass(CS_HREDRAW | CS_VREDRAW,
  43. AfxGetApp()->LoadStandardCursor(IDC_ARROW),
  44. (HBRUSH) GetStockObject (BLACK_BRUSH),
  45. AfxGetApp()->LoadStandardIcon(IDI_WINLOGO));
  46. CreateEx(0, strWndClass,_T("MFC股市软件"),
  47. WS_OVERLAPPED|WS_SYSMENU|WS_CAPTION|WS_MINIMIZEBOX,
  48. CW_USEDEFAULT,CW_USEDEFAULT,900,620,
  49. NULL,NULL);
  50. CMenu menuMain;
  51. menuMain.CreateMenu();
  52.     menuMain.AppendMenu(MF_STRING,4001,"* 分时线 *");
  53. menuMain.AppendMenu(MF_POPUP,4002,"* K线 *");   //(UINT)menuPopup.Detach()
  54. SetMenu(&menuMain);
  55. menuMain.Detach();
  56. memset(&m_Stock,0, sizeof(m_Stock));//&m_Stock是指向m_Stock结构的指针,此时设定空间是0
  57. memset(&m_Data,0,sizeof(m_Data));//&m_Data是指向m_Data结构的指针,此时设定空间是0
  58. size=ReadDayLine(); //读入分时价格数据,及是否正常退出
  59. ksize=ReadKLine(); //读入K线价格数据
  60. asize=ReadKAmount(); //读入K线成交金额数据
  61. ExchangeK();
  62. if (size!=0)
  63. {
  64. Invalidate();
  65. }
  66. }
  67. CMyFrame::~CMyFrame()
  68. {
  69. }
  70. void CMyFrame::ReStart() //新一天开始
  71. {
  72. m=0;
  73. M=0;
  74. VolMax=1;
  75. VolLast=0;
  76. //VolLastDay=m_Stock.fVolume; //昨天总成交量
  77. //KAmountLastDay=m_Stock.fAmount; //昨日成交金额
  78. bNExit=FALSE; //非正常退出
  79. KHighMax = 0;
  80. KLowMin = 100;
  81. KDay  = 60;
  82. KM = KHighMax - KLowMin;
  83. }
  84. LRESULT CMyFrame::OnIRQSTOCK(WPARAM wParam,LPARAM lParam)//是回调函数自定义消息的实现
  85. {
  86. (*m_EnableMessage)(0);//停止发送数据,
  87. long liMsgCounter = (*m_ReceiveInfo)();//返回:接收到的包数
  88. for(int i = 0; i < liMsgCounter; i++)
  89. {
  90. (*m_DataAcquisition)(&m_Data, i); 
  91. ExpandPackage(m_Data);// 拆包并将数据存入相应的结构体中
  92. SendMessage(WM_DrawCommon,NULL,NULL);
  93. StoreDayLine();
  94. if( m>=240 ) //一天结束,存K线数据
  95. {
  96. KLine thisKLine;
  97. thisKLine.fOpen=m_Stock.fOpen;
  98. thisKLine.fClose=m_Stock.fNew;
  99. thisKLine.fHigh=m_Stock.fHigh;
  100. thisKLine.fLow=m_Stock.fLow;
  101. KLineArray.Add(thisKLine);
  102. StoreKLine();
  103. KAmount thisKAmout;
  104. thisKAmout.Amount = m_Stock.fAmount;
  105. KAmountArray.Add(thisKAmout);
  106. StoreKAmount();
  107. bReStart=TRUE; //新一天开始
  108. ReStart();
  109. Invalidate();
  110. }
  111. if(bKLine == FALSE)
  112. SendMessage(WM_DrawDayLine,NULL,NULL); 
  113. }
  114. (*m_EnableMessage)(1); //允许发送数据
  115. return 1;
  116. }
  117. void CMyFrame::ExpandPackage(MAINSTRUCT Data)//---------------拆包
  118. {
  119. if(Data.Type == 0x10||Data.Type == 0x11||Data.Type == 0x20||Data.Type == 0x21)
  120. {   
  121. //将Data的数据存储在m_Stock中
  122. sprintf(m_Stock.StockCode,"%.8s",Data.AllStruct.IndexAndStock.Code);//股票 代码                      
  123. sprintf(m_Stock.StockName,"%.10s", Data.AllStruct.IndexAndStock.Name);//股票名称
  124. m_Stock.fClose = (float)(Data.AllStruct.IndexAndStock.Close)/1000;//收盘价 
  125. m_Stock.fOpen = (float)(Data.AllStruct.IndexAndStock.Open)/1000;//开盘价
  126. m_Stock.fNew = (float)(Data.AllStruct.IndexAndStock.New)/1000;// 最新价
  127. m_Stock.fHigh  = (float)(Data.AllStruct.IndexAndStock.High)/1000;//最高价
  128. m_Stock.fLow = (float)(Data.AllStruct.IndexAndStock.Low)/1000;//最低价
  129. m_Stock.fVolume = (Data.AllStruct.IndexAndStock.Volume);// 总成交量  单位:股
  130. m_Stock.fAmount = (Data.AllStruct.IndexAndStock.Amount)/1000;;// 成交金额  单位:元
  131. m_Stock.Pbuy1 = (Data.AllStruct.IndexAndStock.Pbuy1);//买一
  132. m_Stock.Pbuy2 = (Data.AllStruct.IndexAndStock.Pbuy2);//买二
  133. m_Stock.Pbuy3 = (Data.AllStruct.IndexAndStock.Pbuy3);//买三
  134. m_Stock.Vbuy1 = (Data.AllStruct.IndexAndStock.Vbuy1);//买一
  135. m_Stock.Vbuy2 = (Data.AllStruct.IndexAndStock.Vbuy2);//买二
  136. m_Stock.Vbuy3 = (Data.AllStruct.IndexAndStock.Vbuy3);//买三
  137. m_Stock.Psell1 = (Data.AllStruct.IndexAndStock.Psell1);//卖一
  138. m_Stock.Psell2 = (Data.AllStruct.IndexAndStock.Psell2);//卖二
  139. m_Stock.Psell3 = (Data.AllStruct.IndexAndStock.Psell3);//卖三
  140. m_Stock.Vsell1 = (Data.AllStruct.IndexAndStock.Vsell1);//卖一
  141. m_Stock.Vsell2 = (Data.AllStruct.IndexAndStock.Vsell2);//卖二
  142. m_Stock.Vsell3 = (Data.AllStruct.IndexAndStock.Vsell3);//卖三
  143. 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;
  144. if ( M < (m_Stock.fClose*0.07) )
  145. {
  146. M = m_Stock.fClose*0.07;
  147. }
  148. else
  149. {
  150. Invalidate();
  151. }
  152. Price[m]=m_Stock.fNew;
  153. //if(!bReStart)//不是重新开始
  154. //{
  155. if (m==0)
  156. {
  157. VolThis = m_Stock.fVolume;
  158. Vol[m] = VolThis;
  159. VolMax = VolThis;
  160. }
  161. else
  162. {
  163. VolThis=m_Stock.fVolume-VolLast;
  164. Vol[m] = VolThis;
  165. if( VolThis>VolMax ) 
  166. {
  167. VolMax = VolThis;
  168. }
  169. }
  170. VolLast = m_Stock.fVolume;
  171. //}
  172. /*else
  173. {
  174. if (m==0)
  175. {
  176. VolThis = m_Stock.fVolume-VolLastDay;
  177. Vol[m] = VolThis;
  178. VolMax = VolThis;
  179. }
  180. else
  181. {
  182. VolThis=m_Stock.fVolume-VolLast-VolLastDay;
  183. Vol[m] = VolThis;
  184. if( VolThis>VolMax ) 
  185. {
  186. VolMax = VolThis;
  187. }
  188. }
  189. VolLast = m_Stock.fVolume-VolLastDay;
  190. }*/
  191. m++;
  192. Exchange();
  193. ExchangeA(m);
  194. ExchangeV();
  195. }
  196. }
  197. void CMyFrame::StoreDayLine()
  198. {
  199. int i=0;
  200. try
  201. {
  202. CFile file(_T("dayline.txt"), CFile::modeReadWrite);
  203. CArchive ar(&file,CArchive::store);
  204. ar<<bNExit<<m<<M<<VolMax<<m_Stock.fClose;
  205. for ( i=0; i<m; i++ )
  206. {
  207. ar<<Price[i];
  208. ar<<Vol[i];
  209. }
  210. }
  211. catch(CFileException* e)
  212. {
  213. e->ReportError();
  214. e->Delete();
  215. }
  216. }
  217. DWORD CMyFrame::ReadDayLine() //返回文件大小
  218. {
  219. int i=0;
  220. DWORD size=0;
  221. try
  222. CFile file(_T("dayline.txt"), CFile::modeReadWrite);
  223. CArchive ar(&file,CArchive::load);
  224. size = file.GetLength();
  225. if (size==0)
  226. {
  227. return 0;
  228. }
  229. ar>>bNExit>>m>>M>>VolMax>>m_Stock.fClose;
  230. for( i=0; i<m; i++ )
  231. {
  232. ar>>Price[i];
  233. ar>>Vol[i];
  234. }
  235. for( i=0; i<m; i++ )
  236. {
  237. ExchangeA(i+1); 
  238. }
  239. return size;
  240. }
  241. catch(CFileException* e)
  242. {
  243. e->ReportError();
  244. e->Delete();
  245. }
  246. return size;
  247. }
  248. void CMyFrame::StoreKLine()
  249. {
  250. int i=0;
  251. try
  252. CFile file(_T("kline.txt"), CFile::modeReadWrite);
  253. CArchive ar(&file,CArchive::store);
  254. for ( i=0; i<KLineArray.GetSize(); i++ )
  255. {
  256. ar<<KLineArray[i].fOpen<<KLineArray[i].fClose<<KLineArray[i].fHigh<<KLineArray[i].fLow;
  257. }
  258. }
  259. catch(CFileException* e)
  260. {
  261. e->ReportError();
  262. e->Delete();
  263. }
  264. }
  265. DWORD CMyFrame::ReadKLine()
  266. {
  267. DWORD size=0;
  268. int i=0;
  269. float myArray[1][4];
  270. KLine aKLine;
  271. try
  272. CFile file(_T("kline.txt"), CFile::modeReadWrite);
  273. CArchive ar(&file,CArchive::load);
  274. size=file.GetLength();
  275. if (size==0)
  276. {
  277. return 0;
  278. }
  279. int n=size/(4*4);
  280. for ( i=0; i<n; i++ )
  281. {
  282. ar>>myArray[0][0]>>myArray[0][1]>>myArray[0][2]>>myArray[0][3];
  283. aKLine.fOpen = myArray[0][0];
  284. aKLine.fClose = myArray[0][1];
  285. aKLine.fHigh = myArray[0][2];
  286. aKLine.fLow = myArray[0][3];
  287. KLineArray.SetAtGrow(i,aKLine);
  288. }
  289. return size;
  290. }
  291. catch(CFileException* e)
  292. {
  293. e->ReportError();
  294. e->Delete();
  295. }
  296. return size;
  297. }
  298. void CMyFrame::StoreKAmount()
  299. {
  300. int i=0;
  301. try
  302. CFile file(_T("kamount.txt"), CFile::modeReadWrite);
  303. CArchive ar(&file,CArchive::store);
  304. for ( i=0; i<KAmountArray.GetSize(); i++ )
  305. {
  306. ar<<KAmountArray[i].Amount;
  307. }
  308. }
  309. catch(CFileException* e)
  310. {
  311. e->ReportError();
  312. e->Delete();
  313. }
  314. }
  315. DWORD CMyFrame::ReadKAmount()
  316. {
  317. DWORD size=0;
  318. int i=0;
  319. float Amount=0;
  320. KAmount aKAmount;
  321. try
  322. CFile file(_T("kamount.txt"), CFile::modeReadWrite);
  323. CArchive ar(&file,CArchive::load);
  324. size=file.GetLength();
  325. if (size==0)
  326. {
  327. return 0;
  328. }
  329. int n=size/4;
  330. for ( i=0; i<n; i++ )
  331. {
  332. ar>>Amount;
  333. aKAmount.Amount=Amount;
  334. KAmountArray.SetAtGrow(i,aKAmount);
  335. }
  336. return size;
  337. }
  338. catch(CFileException* e)
  339. {
  340. e->ReportError();
  341. e->Delete();
  342. }
  343. return size;
  344. }
  345. //////////////////////////////////////////////////////////////////////////
  346. //转换函数
  347. //
  348. void CMyFrame::Exchange()
  349. {
  350. int x=0,i=0;
  351. for ( i=0; i<m; i++ )
  352. {
  353. x = (int)(150 * ( Price[i] - m_Stock.fClose ) / M );
  354. Point[i][0]=80+i*2;
  355. Point[i][1]=40+150-x;
  356. }
  357. }
  358. void CMyFrame::ExchangeA(int m)
  359. {
  360. int x=0,i=0;
  361. float total1;
  362. float total2;
  363. float aver=0;
  364.     total1=0;
  365. total2=0;
  366. for (i=0;i<m;i++)
  367. {    
  368. total1=total1+Price[i]*Vol[i];
  369. total2=total2+Vol[i];
  370. }
  371. aver=total1/total2; 
  372. x = (int)(150 * ( aver - m_Stock.fClose ) / M );
  373. PointAver[m-1][0]=80+i*2;
  374. PointAver[m-1][1]=40+150-x;
  375. }
  376. void CMyFrame::ExchangeV()
  377. {
  378. int x=0,i=0;
  379. for ( i=0; i<m; i++ )
  380. {
  381. x = (int)(150 * ( Vol[i] ) / VolMax );
  382. VPoint[i][0]=80+i*2;
  383. VPoint[i][1]=40+150*3-x;
  384. }
  385. }
  386. void CMyFrame::ExchangeK()
  387. {
  388. int x=0,i=0;
  389. float a=0,b=0,lw=0;
  390. CRect rect;
  391. POINT client;
  392. POINT high,low,open,close;
  393. KPoint aKPoint;
  394. GetClientRect(&rect);
  395. client.x = rect.Width();
  396. client.y = rect.Height();
  397. int n = KLineArray.GetSize();
  398. for ( i=0; i<n; i++ )
  399. {
  400. if (KLineArray[i].fHigh > KHighMax)
  401. {
  402. KHighMax = KLineArray[i].fHigh;
  403. }
  404. if (KLineArray[i].fLow < KLowMin)
  405. {
  406. KLowMin = KLineArray[i].fLow;
  407. }
  408. }
  409. KM = KHighMax - KLowMin;
  410. a = (client.y-120)/2 -20;//垂直高度
  411. b = client.x - 220 - 80;//水平高度
  412. lw = b/(KDay*5);//每个K线中每个小格的水平宽度
  413. for ( i=0; i<n; i++ )
  414. {
  415. high.x = 80 + (i*5+3)*lw ;
  416. high.y = 70+a-(KLineArray[i].fHigh - KLowMin)*a/KM;
  417. low.x = 80 + (i*5+3)*lw ;
  418. low.y = 70+a-(KLineArray[i].fLow - KLowMin)*a/KM;
  419. open.x = 80 + (i*5+1)*lw ;
  420. open.y = 70+a-(KLineArray[i].fOpen - KLowMin)*a/KM;
  421. close.x = 80 + (i*5+5)*lw ;
  422. close.y = 70+a-(KLineArray[i].fClose - KLowMin)*a/KM;
  423. aKPoint.high = high;
  424. aKPoint.low = low;
  425. aKPoint.open = open;
  426. aKPoint.close = close;
  427. KPointArray.SetAtGrow(i,aKPoint);
  428. }
  429. }
  430. void CMyFrame::ExchangeKAmount()
  431. {
  432. int i=0;
  433. float c=0,b=0,lw=0;
  434. CRect rect;
  435. POINT client;
  436. float high;
  437. POINT top,bottom;
  438. KAmountPoint aKAmountPoint;
  439. GetClientRect(&rect);
  440. client.x = rect.Width();
  441. client.y = rect.Height();
  442. c = (client.y-120)/4  -20; //垂直高度
  443. b = client.x - 220 - 80; //水平宽度
  444. lw = b/(KDay*5);//每个K线中每个小格的水平宽度
  445. int n = KAmountArray.GetSize();
  446. for ( i=0; i<n; i++ )
  447. {
  448. float temp = KAmountArray[i].Amount;
  449. if (KAmountArray[i].Amount > KAmountMax)
  450. {
  451. KAmountMax = KAmountArray[i].Amount;
  452. }
  453. }
  454. for ( i=0; i<n; i++ )
  455. {
  456. float temp1 = KAmountArray[i].Amount;
  457. top.x = 80 + (i*5+1)*lw ;
  458. top.y = 50+(c+20)*3-KAmountArray[i].Amount*c/KAmountMax;
  459. bottom.x = 80 + (i*5+5)*lw ;
  460. bottom.y = 50+(c+20)*3;
  461. aKAmountPoint.top = top;
  462. aKAmountPoint.bottom = bottom;
  463. KAmountPointArray.SetAtGrow(i,aKAmountPoint);
  464. }
  465. }
  466. void CMyFrame::OnKeyDown( UINT nChar, UINT nRepCnt, UINT nFlags )
  467. {
  468. switch(nChar)
  469. {
  470. case VK_F11:
  471. M=M*0.5;
  472. Exchange();
  473. Invalidate();
  474. break;
  475. case VK_F12:
  476. M=M*1.5;
  477. Exchange();
  478. Invalidate();
  479. break;
  480. case VK_F5:
  481. bKLine = (bKLine == FALSE) ? TRUE:FALSE;
  482. Invalidate();
  483. break;
  484. case VK_RIGHT:
  485. if (bCtrl)
  486. {
  487. KBegine+=5;
  488. }
  489. else
  490. {
  491. KBegine++;
  492. }
  493. if (bKLine==TRUE)
  494. {
  495. Invalidate();
  496. }
  497. break;
  498. case VK_LEFT:
  499. if (bCtrl)
  500. {
  501. KBegine-=5;
  502. }
  503. else
  504. {
  505. KBegine--;
  506. }
  507. if (bKLine==TRUE)
  508. {
  509. Invalidate();
  510. }
  511. break;
  512. case VK_UP:
  513. KDay+=10;
  514. if (bKLine==TRUE)
  515. {
  516. Invalidate();
  517. }
  518. break;
  519. case VK_DOWN:
  520. if (KDay>1)
  521. {
  522. KDay-=10;
  523. }
  524. if (bKLine==TRUE)
  525. {
  526. Invalidate();
  527. }
  528. break;
  529. case VK_CONTROL:
  530. bCtrl=TRUE;
  531. break;
  532. default:
  533. break;
  534. }
  535. }
  536. void CMyFrame::OnKeyUp( UINT nChar, UINT nRepCnt, UINT nFlags )
  537. {
  538. switch(nChar)
  539. {
  540. case VK_CONTROL:
  541. bCtrl=FALSE;
  542. break;
  543. default:
  544. break;
  545. }
  546. }
  547. void CMyFrame::OnDayLine()
  548. {
  549. bKLine = FALSE;
  550. Invalidate();
  551. }
  552. void CMyFrame::OnKLine()
  553. {
  554. bKLine = TRUE;
  555. ExchangeK();
  556. Invalidate();
  557. }
  558. void CMyFrame::OnLButtonDown(UINT nFlags, CPoint point)
  559. {
  560. static int    lx=0,ly=0;
  561. int           x=0,y=0,i;
  562. char          chName[100];
  563. CClientDC     dc(this);
  564. CPen          dashpen(PS_DOT,1,RGB(200,200,0));
  565. CPen          blackpen(PS_DOT,1,RGB(0,0,0));
  566.     
  567. dc.SetBkMode(TRANSPARENT);
  568. dc.SelectObject(&dashpen);
  569. x = point.x;
  570. y = point.y;
  571. if ( x>80 && x < 80+480 )
  572. {
  573. dc.SelectObject(&dashpen);
  574. dc.MoveTo(x,40+2);
  575. dc.LineTo(x,40+300-2);
  576. dc.SelectObject(&blackpen);
  577. dc.MoveTo(lx,40+2);
  578. dc.LineTo(lx,40+300-2);
  579. }
  580.     /*for(i=0;i<=m;i++)//有问题
  581. {
  582. if(Point[i][0]==x||Point[i][1]==y)
  583. {
  584. sprintf(chName, "%8s%6.2f", "价格",Price[i]);
  585. dc.TextOut(800, 530, chName, lstrlen(chName)-1);
  586. }
  587. }*/
  588. lx = point.x;
  589. ly = point.y;
  590. }
  591. void CMyFrame::OnCreate()
  592. {
  593. m_hLibrary = ::LoadLibrary("..\Fstrcv\Debug\fstrcv.dll");//装库
  594. INITCARD* lpfunction = (INITCARD*)::GetProcAddress(m_hLibrary, "InitCard");
  595. unsigned int uiCardNumber = (*lpfunction)((this->m_hWnd), WM_IRQSTOCK);
  596. m_EnableMessage = (ENABLEMESSAGE*)::GetProcAddress(m_hLibrary, "EnableMessage");
  597. //m_MyCount = (READMYCOUNT*)::GetProcAddress(m_hLibrary, "ReadMyCount");
  598. m_ReceiveInfo = (RECEIVEINFO*)::GetProcAddress(m_hLibrary, "ReceiveInfo");
  599. m_DataAcquisition = (DATAACQUISITION*)::GetProcAddress(m_hLibrary, "DataAcquisition");
  600. }
  601. ///////////////////////////////////////////////////
  602. /// 画图消息
  603. ///
  604. void CMyFrame::OnDrawCommon(WPARAM wParam,LPARAM lParam)//画公共动态数据
  605. {
  606. CClientDC  dc(this);
  607. CRect     rect;
  608. char      chName[300];
  609. CPoint    client;
  610. GetClientRect (&rect);
  611. client.x=rect.right;
  612. client.y=rect.bottom;
  613. dc.SetBkMode(OPAQUE);
  614. dc.SetBkColor(RGB(0,0,0));
  615. dc.SetTextColor(RGB(255,255,255));
  616. //卖
  617. rect.left = client.x-199;
  618. rect.top = 60;
  619. rect.right = client.x-11;
  620. rect.bottom = 60+60;
  621. dc.SelectStockObject(BLACK_BRUSH);
  622. dc.Rectangle(&rect);
  623. sprintf(chName, "%8s%10.2f%10.2fn", "卖一",(float)m_Stock.Psell1,(float)m_Stock.Vsell1);
  624. dc.TextOut(client.x-198, 60, chName, lstrlen(chName)-1);
  625. sprintf(chName, "%8s%10.2f%10.2fn", "卖二",(float)m_Stock.Psell2,(float)m_Stock.Vsell2);
  626. dc.TextOut(client.x-198, 60+20, chName, lstrlen(chName)-1);
  627. sprintf(chName, "%8s%10.2f%10.2fn", "卖三",(float)m_Stock.Psell3,(float)m_Stock.Vsell3);
  628. dc.TextOut(client.x-198, 60+40, chName, lstrlen(chName)-1);
  629. //买
  630. rect.left = client.x-199;
  631. rect.top = 140;
  632. rect.right = client.x-11;
  633. rect.bottom = 140+60;
  634. dc.SelectStockObject(BLACK_BRUSH);
  635. dc.Rectangle(&rect);
  636. sprintf(chName, "%8s%10.2f%10.2fn", "买一",(float)m_Stock.Pbuy1,(float)m_Stock.Vbuy1);
  637. dc.TextOut(client.x-198, 140, chName, lstrlen(chName)-1);
  638. sprintf(chName, "%8s%10.2f%10.2fn", "买二",(float)m_Stock.Pbuy2,(float)m_Stock.Vbuy2);
  639. dc.TextOut(client.x-198, 140+20, chName, lstrlen(chName)-1);
  640. sprintf(chName, "%8s%10.2f%10.2fn", "买三",(float)m_Stock.Pbuy3,(float)m_Stock.Vbuy3);
  641. dc.TextOut(client.x-198, 140+40, chName, lstrlen(chName)-1);
  642. //动态信息
  643. rect.left = client.x-199;
  644. rect.top = 220;
  645. rect.right = client.x-11;
  646. rect.bottom = 220+120;
  647. dc.SelectStockObject(BLACK_BRUSH);
  648. dc.Rectangle(&rect);
  649. dc.SetBkMode(TRANSPARENT);
  650. sprintf(chName, "%8s%6.2f%8s%6.2fn", "开盘价",m_Stock.fOpen,"最新价",m_Stock.fNew);
  651. dc.TextOut(client.x-205, 220, chName, lstrlen(chName)-1);
  652. sprintf(chName, "%8s%6.2f%8s%6.2fn", "最高价",m_Stock.fHigh,"最低价",m_Stock.fLow);
  653. dc.TextOut(client.x-205, 220+20, chName, lstrlen(chName)-1);
  654. sprintf(chName, "%8s%6d%10s%6.2fn", "笔  数",m,"价格增量",M);
  655. dc.TextOut(client.x-205, 220+40, chName, lstrlen(chName)-1);
  656. sprintf(chName, "%12s%6.0fn","最大成交量",VolMax);
  657. dc.TextOut(client.x-205, 220+60, chName, lstrlen(chName)-1);
  658. if (bKLine)
  659. {
  660. sprintf(chName, "%18s%8.0fn","最大天成交(万元)",KAmountMax/10000);
  661. dc.TextOut(client.x-205, 220+80, chName, lstrlen(chName)-1);
  662. }
  663. /*int temp = (*m_MyCount)();
  664. sprintf(chName, "%10s%5dn","发送数量",temp);
  665. dc.TextOut(client.x-205, 220+100, chName, lstrlen(chName)-1);*/
  666. }
  667. void CMyFrame::OnDrawDayLine(WPARAM wParam,LPARAM lParam)
  668. {
  669. int i=0;
  670. float M6=0,price=0;
  671. float percent=0;
  672. int V6=0;
  673. int voly=0;
  674. CClientDC  dc(this);
  675. CRect     rect;
  676. char      chName[300];
  677. CPoint    client;
  678. CPen      whitepen(PS_SOLID,1,RGB(255,255,255));
  679. CPen      yellowpen(PS_SOLID,1,RGB(255,255,0));
  680. CPen      blackpen(PS_SOLID,1,RGB(0,0,0));
  681. dc.SetBkMode(OPAQUE);
  682. dc.SetBkColor(RGB(0,0,0));
  683. dc.SetTextColor(RGB(255,255,255));
  684. //画坐标值
  685. M6=M/6;
  686. if ( m>0 )
  687. {
  688. for ( i=0; i<13; i++ )
  689. //左边
  690. price=M6*(6-i)+m_Stock.fClose;
  691. sprintf(chName, "%10.2f", price);
  692. dc.TextOut(15, 33+i*25, chName, lstrlen(chName));
  693. //右边
  694. percent=(M6*(6-i)/m_Stock.fClose)*100;
  695. sprintf(chName, "%10.2f%%", percent);
  696. dc.TextOut(560, 33+i*25, chName, lstrlen(chName));
  697. }
  698. }
  699. //画分时线
  700. dc.SetBkMode(TRANSPARENT);
  701. dc.SelectObject(&whitepen);
  702. dc.MoveTo(Point[0][0],Point[0][1]);
  703. for( i=1; i<m; i++ )
  704. {
  705. dc.LineTo(Point[i][0],Point[i][1]);
  706. }
  707. //加权平均线
  708. dc.SelectObject(&yellowpen);
  709. dc.MoveTo(PointAver[0][0],PointAver[0][1]);
  710. for( i=1; i<m; i++ )
  711. dc.LineTo(PointAver[i][0],PointAver[i][1]);
  712. //画成交量线
  713. dc.SelectObject(&yellowpen);
  714. for( i=0; i<m; i++ )
  715. {
  716. dc.MoveTo(80+i*2,487);
  717. dc.LineTo(VPoint[i][0],VPoint[i][1]);
  718. }
  719. //画成交量坐标值
  720. V6 = VolMax/6;
  721. if ( m>0 )
  722. {
  723. dc.SelectObject(&blackpen);
  724. rect.top = 57+300;
  725. rect.bottom = 57+300+5*25;
  726. rect.left = 15;
  727. rect.right = 75;
  728. dc.SelectStockObject(BLACK_BRUSH);
  729. dc.Rectangle(&rect);
  730. for ( i=0; i<5; i++ )
  731. voly=VolMax-V6*(i+1);
  732. sprintf(chName, "%10.2d", voly);
  733. dc.TextOut(10, 57+300+i*25, chName, lstrlen(chName));
  734. }
  735. }
  736. }
  737. void CMyFrame::OnDrawKLine(WPARAM wParam,LPARAM lParam)
  738. {
  739. int i=0;
  740. int a=0,b=0;
  741. CClientDC dc(this);
  742. CRect rect;
  743. RECT kRect,kaRect;
  744. CPoint client;
  745. CPen whitepen(PS_SOLID,1,RGB(255,255,255));
  746. CPen blackpen(PS_SOLID,1,RGB(0,0,0));
  747. CPen cyanPen(PS_SOLID,1,RGB(116,245,240));
  748. CBrush cyanBrush(RGB(116,245,240));
  749. CPen redPen(PS_SOLID,1,RGB(220,112,116));
  750. CBrush blackBrush(RGB(0,0,0));
  751. char chName[200];
  752. GetClientRect(&rect);
  753. client.x = rect.Width();
  754. client.y = rect.Height();
  755. a = (client.y-120)/2 -20;//垂直高度
  756. b = client.x - 220 - 80;//水平宽度
  757. //画K线
  758. ExchangeK();
  759. ExchangeKAmount();
  760. dc.SetBkMode(OPAQUE);
  761. int n = KPointArray.GetSize();
  762. //for( i=KBegine; (i<KBegine+KDay) && (i<n) ; i++ )
  763. for( i=0; i<n ; i++ )
  764. {
  765. if (KPointArray[i].close.y<KPointArray[i].open.y) //升了,用红色线
  766. {
  767. dc.SelectObject(&redPen);
  768. dc.SelectObject(&blackBrush);
  769. }
  770. else //降了,用青色线
  771. {
  772. dc.SelectObject(&cyanPen);
  773. dc.SelectObject(&cyanBrush);
  774. }
  775. if ( KPointArray[i].high.x + KBegine*(b/KDay) > 80 && KPointArray[i].high.x + KBegine*(b/KDay) < 80+b )
  776. {
  777. dc.MoveTo(KPointArray[i].high.x + KBegine*(b/KDay), KPointArray[i].high.y );   //画最高价与最底价
  778. dc.LineTo(KPointArray[i].low.x + KBegine*(b/KDay), KPointArray[i].low.y );
  779. kRect.left =  KPointArray[i].open.x + KBegine*(b/KDay);
  780. kRect.top = KPointArray[i].open.y ;
  781. kRect.right = KPointArray[i].close.x + KBegine*(b/KDay);
  782. kRect.bottom = KPointArray[i].close.y ;
  783. dc.Rectangle(&kRect);     //画矩形
  784. kaRect.left =  KAmountPointArray[i].top.x + KBegine*(b/KDay);
  785. kaRect.top = KAmountPointArray[i].top.y ;
  786. kaRect.right = KAmountPointArray[i].bottom.x + KBegine*(b/KDay);
  787. kaRect.bottom = KAmountPointArray[i].bottom.y ;
  788. dc.Rectangle(&kaRect);     //画矩形
  789. }
  790. }
  791. dc.SetBkMode(TRANSPARENT);
  792.     dc.SetTextColor(RGB(255,255,255));
  793. //画K线坐标值
  794. for ( i=0; i<6; i++ )
  795. sprintf(chName, "%10.2f", KHighMax-(KM/5)*i);
  796. dc.TextOut(18, 65+i*(a/5-2), chName, lstrlen(chName));
  797. }
  798. //画K线成交金额坐标值
  799. dc.SetBkMode(OPAQUE);
  800. dc.SetBkColor(RGB(0,0,0));
  801. dc.SetTextColor(RGB(255,255,255));
  802. for ( i=0; i<3; i++ )
  803. sprintf(chName, "%8.0f", (KAmountMax-(KAmountMax/2)*i)/10000);
  804. dc.TextOut(18, 290+i*43, chName, lstrlen(chName));
  805. }
  806. }
  807. void CMyFrame::OnPaint()//画静态信息
  808. {
  809. int i=0;
  810. CPaintDC  dc(this);
  811. CRect     rect;
  812. char      chName[300];
  813. CPoint    client;
  814. CPen      redpen(PS_SOLID,2,RGB(153,0,0));
  815. CPen      dashpen(PS_DOT,1,RGB(255,255,255));
  816. if ( bKLine == FALSE ) //分时线状态,画分时线的静态数据
  817. {
  818. dc.SetBkMode(TRANSPARENT);
  819. dc.SetTextColor(RGB(255,255,255));
  820. GetClientRect (&rect);
  821. client.x=rect.right;
  822. client.y=rect.bottom;
  823. rect.bottom = 40;
  824. rect.top = 20;
  825. rect.left = client.x-200;
  826. rect.right = client.x-10;
  827. dc.DrawText(_T("G浦发      600000"),-1,&rect,DT_SINGLELINE|DT_CENTER|DT_VCENTER);
  828. rect.bottom = 40;
  829. rect.top = 20;
  830. rect.left = client.x-220;
  831. rect.right = 20;
  832. dc.DrawText(_T("G浦发      600000.sh"),-1,&rect,DT_SINGLELINE|DT_CENTER|DT_VCENTER);
  833. //右外边框
  834. dc.SelectObject(&redpen);
  835. dc.MoveTo (client.x-200, 50);
  836. dc.LineTo (client.x-10, 50);
  837. dc.LineTo (client.x-10, client.y-50);
  838. dc.LineTo (client.x-200, client.y-50);
  839. dc.LineTo (client.x-200, 50);
  840. //左外边框
  841. dc.MoveTo (10, 10);
  842. dc.LineTo (client.x-220, 10);
  843. dc.LineTo (client.x-220, client.y-50);
  844. dc.LineTo (10, client.y-50);
  845. dc.LineTo (10, 10);
  846. //右外边框中的横线
  847. /*for(i=0;i<4;i++)
  848. {   
  849. dc.MoveTo (client.x-200, (i+1)*(client.y-100)/4+50);
  850. dc.LineTo (client.x-10, (i+1)*(client.y-100)/4+50);
  851. }*/
  852. dc.MoveTo (client.x-200, 130);
  853. dc.LineTo (client.x-10, 130);
  854. dc.MoveTo (client.x-200, 210);
  855. dc.LineTo (client.x-10, 210);
  856. dc.MoveTo (client.x-200, 350);
  857. dc.LineTo (client.x-10, 350);
  858. //背景虚线
  859. dc.SelectObject(&dashpen);
  860. for ( i=0; i<17; i++ )
  861. {
  862. dc.MoveTo( 80, 40+(i+1)*25 );
  863. dc.LineTo( 80+120*4, 40+(i+1)*25 );
  864. }
  865. //画左边框日线边框
  866. dc.SelectObject(&redpen);
  867. rect.left = 80;
  868. rect.top = 40;
  869. rect.right = 560;
  870. rect.bottom = 490;
  871. dc.SelectStockObject(NULL_BRUSH);
  872. dc.Rectangle(&rect);
  873. //画下边框
  874. rect.left = 10;
  875. rect.top = 525;
  876. rect.right = client.x-10;
  877. rect.bottom = client.y-5;
  878. dc.Rectangle(&rect);
  879. //画下边框内文字
  880. sprintf(chName, "%8s", "◆金花股份收购西商行面临两大法律障碍");
  881. dc.TextOut(15, 535, chName, lstrlen(chName));
  882. //画横中间实线
  883. for ( i =0; i<2; i++ )
  884. {
  885. dc.MoveTo( 80, 40+(i+1)*150 );
  886. dc.LineTo( 80+120*4, 40+(i+1)*150 );
  887. }
  888. //画中间竖实线
  889. for ( i =0; i<3; i++ )
  890. {
  891. dc.MoveTo( 80+(i+1)*120, 40 );
  892. dc.LineTo( 80+(i+1)*120, 40+150*3 );
  893. }
  894. //画时间信息
  895. sprintf(chName, "%s%26s%26s%26s%26s", "09:30","10:30","13:00","14:00","15:00");
  896. dc.TextOut(62, 490, chName, lstrlen(chName));
  897. //画动态分时线
  898. SendMessage(WM_DrawCommon,NULL,NULL);
  899. SendMessage(WM_DrawDayLine,NULL,NULL); //画动态信息
  900. }
  901. else //画K线
  902. {
  903. dc.SetBkMode(TRANSPARENT);
  904. dc.SetTextColor(RGB(255,255,255));
  905. GetClientRect (&rect);
  906. client.x=rect.right;
  907. client.y=rect.bottom;
  908. rect.bottom = 40;
  909. rect.top = 20;
  910. rect.left = client.x-200;
  911. rect.right = client.x-10;
  912. dc.DrawText(_T("G浦发      600000"),-1,&rect,DT_SINGLELINE|DT_CENTER|DT_VCENTER);
  913. /////////////////右外边框
  914. dc.SelectObject(&redpen);
  915. dc.MoveTo (client.x-200, 50);
  916. dc.LineTo (client.x-10, 50);
  917. dc.LineTo (client.x-10, client.y-50);
  918. dc.LineTo (client.x-200, client.y-50);
  919. dc.LineTo (client.x-200, 50);
  920. //右外边框中的横线
  921. dc.MoveTo (client.x-200, 130);
  922. dc.LineTo (client.x-10, 130);
  923. dc.MoveTo (client.x-200, 210);
  924. dc.LineTo (client.x-10, 210);
  925. dc.MoveTo (client.x-200, 350);
  926. dc.LineTo (client.x-10, 350);
  927. //////////////////////////////左边
  928. //左外边框
  929. dc.MoveTo (10, 10);
  930. dc.LineTo (client.x-220, 10);
  931. dc.LineTo (client.x-220, client.y-50);
  932. dc.LineTo (10, client.y-50);
  933. dc.LineTo (10, 10);
  934. //画所有横线
  935. //上第一横线
  936. dc.MoveTo (10,50);
  937. dc.LineTo (client.x-220, 50);
  938. //上短线
  939. dc.MoveTo (80,70);
  940. dc.LineTo (client.x-220, 70);
  941. //中间第一横线
  942. dc.MoveTo (10,client.y-70);
  943. dc.LineTo (client.x-220,client.y-70);
  944. //下边横线
  945. dc.MoveTo (10, 50+(client.y-120)/2);
  946. dc.LineTo (client.x-220, 50+(client.y-120)/2);
  947. //下短线1
  948. dc.MoveTo (80,50+(client.y-120)/2+20);
  949. dc.LineTo (client.x-220,50+(client.y-120)/2+20);
  950. //下短线2
  951. dc.MoveTo (80, 50+(client.y-120)*3/4);
  952. dc.LineTo (client.x-220, 50+(client.y-120)*3/4);
  953. //下短线3
  954. dc.MoveTo (80,50+(client.y-120)*3/4+20);
  955. dc.LineTo (client.x-220, 50+(client.y-120)*3/4+20);
  956. //竖红线
  957. dc.MoveTo( 80, 50 );
  958. dc.LineTo( 80, client.y-70 );
  959. //背景虚线
  960. dc.SelectObject(&dashpen);
  961. for ( i=0; i<4; i++ )
  962. {
  963. dc.MoveTo( 80, 70+(i+1)*( ( (client.y-120)/2-20 )/5 ) );
  964. dc.LineTo( client.x-220, 70+(i+1)*( ( (client.y-120)/2-20 )/5 ) );
  965. }
  966. //下方虚线
  967. dc.MoveTo (80, 50+(client.y-120)/2+20+( (client.y-120)/4-20 )/2 + (client.y-120)/4 );
  968. dc.LineTo (client.x-220, 50+(client.y-120)/2+20+( (client.y-120)/4-20 )/2 + (client.y-120)/4 );
  969. dc.MoveTo (80, 50+(client.y-120)/2+20+( (client.y-120)/4-20 )/2 );
  970. dc.LineTo (client.x-220, 50+(client.y-120)/2+20+( (client.y-120)/4-20)/2 );
  971. //画下边框
  972. dc.SelectStockObject(NULL_BRUSH);
  973. dc.SelectObject(&redpen);
  974. rect.left = 10;
  975. rect.top = 525;
  976. rect.right = client.x-10;
  977. rect.bottom = client.y-5;
  978. dc.Rectangle(&rect);
  979. //画下边框内文字
  980. sprintf(chName, "%8s", "◆金花股份收购西商行面临两大法律障碍");
  981. dc.TextOut(15, 535, chName, lstrlen(chName));
  982. //画动态分时线
  983. SendMessage(WM_DrawCommon,NULL,NULL);
  984. SendMessage(WM_DrawKLine,NULL,NULL); 
  985. }
  986. }