全局变量
CDC * pDC;
CRect rect;
CDC MemDC;
CBitmap MemBitmap;
BITMAP bm;
int m_Wheel= 100 ;
int px, py, pxf, pxy = 0 ;
int ScreenHeight, ScreenWidth;
int WNumber = 50 ;
int WNS = 0 ;
OnMouseWheel()
BOOL CKlineMiddleView: : OnMouseWheel ( UINT nFlags, short zDelta, CPoint pt)
{
m_Wheel -= zDelta* 0.01 ;
if ( m_Wheel >= 150 ) m_Wheel= 150 ;
else if ( m_Wheel <= 65 ) m_Wheel= 65 ;
else
{
WNumber = m_Wheel - 50 ;
this - > KlineDraw ( ) ;
}
return CView: : OnMouseWheel ( nFlags, zDelta, pt) ;
}
KlineDraw()
void CKlineMiddleView: : KlineDraw ( )
{
pDC = GetWindowDC ( ) ;
pDC- > GetClipBox ( & rect) ;
GetClientRect ( & rect) ;
pDC- > FillSolidRect ( rect, RGB ( 0 , 0 , 0 ) ) ;
ScreenHeight = rect. Height ( ) - 20 ;
ScreenWidth = rect. Width ( ) ;
CClientDoc* pDoc = ( CClientDoc* ) GetDocument ( ) ;
MemBitmap. DeleteObject ( ) ;
MemDC. DeleteDC ( ) ;
MemDC. CreateCompatibleDC ( NULL ) ;
MemBitmap. CreateCompatibleBitmap ( pDC, ScreenWidth, ScreenHeight) ;
CBitmap * pOldBit= MemDC. SelectObject ( & MemBitmap) ;
MemDC. FillSolidRect ( 0 , 0 , ScreenWidth, ScreenHeight, RGB ( 0 , 0 , 0 ) ) ;
WNS = 150 - m_Wheel ;
if ( WNS < 0 )
WNS = 0 ;
float KWidth = ( float) ( ScreenWidth - 30 ) / WNumber;
int maxh = 0 ;
int minh = 100000 ;
int newh = 0 ;
for ( int i = WNS ; i < 100 ; i++ )
{
if ( maxh < pDoc- > m_DataKLine[ i] . KHighestPrice)
maxh = pDoc- > m_DataKLine[ i] . KHighestPrice;
if ( minh > pDoc- > m_DataKLine[ i] . KLowestPrice)
minh = pDoc- > m_DataKLine[ i] . KLowestPrice;
newh = maxh - minh;
}
for ( int i = WNS ; i < 100 ; i++ )
{
int khigh = pDoc- > m_DataKLine[ i] . KHighestPrice;
int klow = pDoc- > m_DataKLine[ i] . KLowestPrice;
int kopen = pDoc- > m_DataKLine[ i] . KOpenPrice;
int kclose = pDoc- > m_DataKLine[ i] . KClosePrice;
int maxOC = max ( kopen, kclose) ;
int minOC = min ( kopen, kclose) ;
int mainHigh = maxOC - minOC;
float multiple = ( float) ScreenHeight/ newh;
int xleftTop = KWidth* ( i- WNS ) ;
float yleftTop = rect. bottom- 10 - ( maxOC- minh) * multiple;
int xWidth = KWidth* 0.9 ;
double yHeight = ( double) mainHigh* multiple;
if ( pDoc- > m_DataKLine[ i] . KOpenPrice > pDoc- > m_DataKLine[ i] . KClosePrice)
{
MemDC. FillSolidRect ( xleftTop, yleftTop, xWidth, yHeight, RGB ( 39 , 176 , 216 ) ) ;
CPen PenBlue ( PS_SOLID , 1 , RGB ( 39 , 176 , 216 ) ) ;
CPen * oldPenx = MemDC. SelectObject ( & PenBlue) ;
MemDC. MoveTo ( xleftTop + xWidth/ 2 , rect. bottom- 10 - ( khigh- minh) * multiple) ;
MemDC. LineTo ( xleftTop + xWidth/ 2 , rect. bottom- 10 - ( klow- minh) * multiple) ;
}
else if ( pDoc- > m_DataKLine[ i] . KOpenPrice < pDoc- > m_DataKLine[ i] . KClosePrice)
{
CBrush br;
CPen pen;
pen. CreatePen ( PS_SOLID , 1 , RGB ( 255 , 74 , 102 ) ) ;
br. CreateStockObject ( NULL_BRUSH ) ;
MemDC. SelectObject ( & pen) ;
MemDC. SelectObject ( & br) ;
MemDC. Rectangle ( xleftTop, yleftTop, xleftTop+ xWidth, yleftTop+ yHeight) ;
CPen PenRed ( PS_SOLID , 1 , RGB ( 255 , 74 , 102 ) ) ;
CPen * oldPenx = MemDC. SelectObject ( & PenRed) ;
MemDC. MoveTo ( xleftTop + xWidth/ 2 , rect. bottom- 10 - ( khigh- minh) * multiple) ;
MemDC. LineTo ( xleftTop + xWidth/ 2 , yleftTop) ;
MemDC. MoveTo ( xleftTop + xWidth/ 2 , yleftTop+ yHeight) ;
MemDC. LineTo ( xleftTop + xWidth/ 2 , rect. bottom- 10 - ( klow- minh) * multiple) ;
}
else
{
int yleftTop = rect. bottom- 10 - ( maxOC- minh) * multiple;
int yHeight = 1 ;
MemDC. FillSolidRect ( xleftTop, yleftTop, xWidth, yHeight, RGB ( 255 , 255 , 255 ) ) ;
CPen PenWhite ( PS_SOLID , 1 , RGB ( 255 , 255 , 255 ) ) ;
CPen * oldPenx = MemDC. SelectObject ( & PenWhite) ;
MemDC. MoveTo ( xleftTop + xWidth/ 2 , rect. bottom- 10 - ( khigh- minh) * multiple) ;
MemDC. LineTo ( xleftTop + xWidth/ 2 , rect. bottom- 10 - ( klow- minh) * multiple) ;
}
}
pDC- > BitBlt ( 0 , 0 , ScreenWidth, ScreenHeight, & MemDC, 0 , 0 , SRCCOPY ) ;
pDC- > BitBlt ( 0 , 0 , ScreenWidth, ScreenHeight, & MemDC, 0 , 0 , SRCCOPY ) ;
pDC- > BitBlt ( 0 , 0 , ScreenWidth, ScreenHeight, & MemDC, 0 , 0 , SRCCOPY ) ;
pDC- > BitBlt ( 0 , 0 , ScreenWidth, ScreenHeight, & MemDC, 0 , 0 , SRCCOPY ) ;
pDC- > BitBlt ( 0 , 0 , ScreenWidth, ScreenHeight, & MemDC, 0 , 0 , SRCCOPY ) ;
}