用VC开发股票分析软件(三)
2013年10月15日
⁄ 综合
⁄ 共 1434字 ⁄ 字号
小 中 大
- void CStockView::OnDraw(CDC* pDC)
- {
- CStockDoc* pDoc = GetDocument();
- ASSERT_VALID(pDoc);
-
-
-
- CClientDC mjClientDC(this) ;
- OnPrepareDC(&mjClientDC);
-
- CRect rc;
- GetClientRect(&rc);
- CBrush br(RGB(0,0,0));
- pDC->FillRect(&rc,&br);
- CBrush *pBrush;
- CBrush mjSunBrush;
-
- CPen *pPen;
- CPen mjSunPen ;
- mjSunBrush.CreateSolidBrush(RGB(255,0,0));
- pBrush = mjClientDC.SelectObject(&mjSunBrush);
-
- mjSunPen.CreatePen(PS_SOLID,1,RGB(255,0,0));
- pPen = mjClientDC.SelectObject(&mjSunPen);
- int ClosePrice = 97 ;
- int BeginPrice = 90 ;
- int MinPrice = 85;
- int MaxPrice = 99;
-
-
- int x = 300;int y = 400 ;
-
- int KlineWidth = 10 ;
- int MidLine = KlineWidth / 2 ;
-
-
- int x1 = x ;
- int y1 = y - (BeginPrice-MinPrice) ;
-
-
- int x2 = x + KlineWidth;
- int y2 = y - ((BeginPrice-MinPrice) + (ClosePrice - BeginPrice));
- mjClientDC.Rectangle(CRect(x1,y1,x2,y2));
-
- int x3 = x1 + MidLine ;
- int y3 = y - (MaxPrice-MinPrice) ;
- int x4 = x3 ;
- int y4 = y ;
- mjClientDC.MoveTo(x3,y3);
- mjClientDC.LineTo(x3,y4);
- ReleaseDC(pDC);
-
- }
- 画K线,实际就是矩形+线条的组合。这个例子只说了画阳线的方法,可以类推