⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 realtime.cpp

📁 股票软件
💻 CPP
📖 第 1 页 / 共 5 页
字号:
//			nTotalSize	= m_CurStock.GetMinute().GetSize();
		else if( CRealTime::reportMinute == m_nReportWhat )
			nTotalSize	= m_CurStock.GetMinute().GetSize();
		else if( CRealTime::reportBuySellEx == m_nReportWhat )
			nTotalSize	= m_CurStock.GetReport().GetSize();
		else if( CRealTime::reportBigTrade == m_nReportWhat )
			nTotalSize	= m_aReportBigTrade.GetSize();
		else
			return;

		if( 0 == m_nCurrentStartPos )
			return;
		if( -1 == m_nCurrentStartPos )
		{
			m_nCurrentStartPos	= 0;
			while( nTotalSize - m_nCurrentStartPos > m_nCurrentPageCount )	m_nCurrentStartPos	+= m_nCurrentPageCount;
			m_nCurrentStartPos	-= m_nCurrentPageCount;
		}
		else
			m_nCurrentStartPos	-= m_nCurrentPageCount;
		
		if( m_nCurrentStartPos < 0 || m_nCurrentStartPos >= nTotalSize )
			m_nCurrentStartPos	= -1;

		DrawReportRegion( NULL );
	}
}

void CRealTime::MoveDown( BOOL bShiftPressed )
{
	if( CRealTime::modePriceLine == m_nDrawMode )
	{
		int	nTotalSize = 0;
		if( CRealTime::reportQuote == m_nReportWhat )
			nTotalSize	= m_CurStock.GetReport().GetSize();
//		else if( CRealTime::reportPrice == m_nReportWhat )
//			nTotalSize	= m_CurStock.GetMinute().GetSize();
		else if( CRealTime::reportMinute == m_nReportWhat )
			nTotalSize	= m_CurStock.GetMinute().GetSize();
		else if( CRealTime::reportBuySellEx == m_nReportWhat )
			nTotalSize	= m_CurStock.GetReport().GetSize();
		else if( CRealTime::reportBigTrade == m_nReportWhat )
			nTotalSize	= m_aReportBigTrade.GetSize();
		else
			return;

		if( -1 != m_nCurrentStartPos )
		{
			m_nCurrentStartPos	+= m_nCurrentPageCount;
		}
		
		if( m_nCurrentStartPos < 0 || m_nCurrentStartPos >= nTotalSize )
			m_nCurrentStartPos	= -1;

		DrawReportRegion( NULL );
	}
}

void CRealTime::MoveHome( BOOL bShiftPressed )
{
	if( CRealTime::modePriceLine != m_nDrawMode )
		return;
	int	nPos	= ( m_CurStock.GetMinute().GetSize() > 0 ? 0 : -1 );
	MoveTo( nPos, bShiftPressed, FALSE );
}

void CRealTime::MoveEnd( BOOL bShiftPressed )
{
	if( CRealTime::modePriceLine != m_nDrawMode )
		return;
	int	nPos	= ( m_CurStock.GetMinute().GetSize() > 0 ? m_CurStock.GetMinute().GetSize()-1 : -1 );
	MoveTo( nPos, bShiftPressed, FALSE );
}

void CRealTime::MoveTo( int nIndex, BOOL bShiftPressed, BOOL bCtrlPressed )
{
	if( CRealTime::modePriceLine != m_nDrawMode )
		return;

	DrawSelectionLine( NULL, FALSE );

	// To Change m_anIndexCurrent
	if( bShiftPressed && nIndex >= 0 )
	{
		if( m_nIndexCurrent < 0 )
		{
			AddIndexCurrent( nIndex );
		}
		else if( m_nIndexCurrent <= nIndex )
		{
			for( int nSel=m_nIndexCurrent; nSel<=nIndex; nSel++ )
			{
				AddIndexCurrent( nSel );
			}
		}
		else
		{
			for( int nSel=nIndex; nSel<=m_nIndexCurrent; nSel++ )
			{
				AddIndexCurrent( nSel );
			}
		}
	}
	else if( bCtrlPressed && nIndex >= 0 )
	{
		AddIndexCurrent( nIndex );
	}
	else
	{
		m_anIndexCurrent.RemoveAll();
	}

	if( m_nIndexCurrent != nIndex )
	{
		m_nIndexCurrent	= nIndex;
		OnIndexCurrentChanged( );
	}

	DrawSelectionLine( NULL, TRUE );
}

void CRealTime::Move( int nMove, BOOL bShiftPressed, BOOL bCtrlPressed )
{
	if( CRealTime::modePriceLine != m_nDrawMode )
		return;

	int	nIndexCurrent	= m_nIndexCurrent;
	
	if( nIndexCurrent < 0 )
	{
		if( nMove < 0 )
			nIndexCurrent	= m_CurStock.GetMinute().GetSize()-1;
		else if( nMove > 0 )
			nIndexCurrent	= 0;
	}
	else
	{
		nIndexCurrent	+= nMove;
	}

	if( nIndexCurrent < 0 )
		nIndexCurrent	= 0;
	if( nIndexCurrent >= m_CurStock.GetMinute().GetSize() )
		nIndexCurrent	= m_CurStock.GetMinute().GetSize()-1;

	MoveTo( nIndexCurrent, bShiftPressed, bCtrlPressed );
}

void CRealTime::OnLButtonDown( UINT nFlags, CPoint point, BOOL bShiftPressed, BOOL bCtrlPressed )
{
	if( CRealTime::modePriceLine == m_nDrawMode )
	{
		// Selection
		int	nIndexClick	= -1;
		CRect	rect(m_rectPrice.left,m_rectPrice.top,m_rectPrice.right,m_rectAll.bottom-m_nMarginBottom);
		if( rect.PtInRect(point) )
		{
			DWORD	dwSeconds	= CSPTime::GetTradeSecondsOfOneDay();
			for( int nIndex=0; nIndex<m_CurStock.GetMinute().GetSize(); nIndex ++ )
			{
				CRect	rectLine	= rect;
				DWORD sec = CSPTime(m_CurStock.GetMinute()[nIndex].m_time).ToStockTimeSecOrder();
				DWORD secL = sec-100, secR = sec+100;
				if( nIndex > 0 )
					secL = CSPTime(m_CurStock.GetMinute()[nIndex-1].m_time).ToStockTimeSecOrder();
				if( nIndex < m_CurStock.GetMinute().GetSize()-1 )
					secR = CSPTime(m_CurStock.GetMinute()[nIndex+1].m_time).ToStockTimeSecOrder();
				rectLine.left	= (int)( rect.left+rect.Width()*(secL+sec)*0.5/dwSeconds );
				rectLine.right	= (int)( rect.left+rect.Width()*(sec+secR)*0.5/dwSeconds );
				if( rectLine.PtInRect(point) )
				{
					nIndexClick	= nIndex;
					break;
				}
			}
		}
		MoveTo( nIndexClick, bShiftPressed, bCtrlPressed );

		if( CRealTime::modePriceLine == m_nDrawMode
			&& CRealTime::reportBigTrade == m_nReportWhat )
		{
			// reportBigTrade 大单成交,选中股票
			if( m_rectReport.PtInRect(point) )
			{
				int nShowCount = (m_rectReport.Height()-RT_RDTITLE_HEIGHT) / RT_RDELEMENT_HEIGHT;
				if( nShowCount <= 0 )	nShowCount	= 1;

				nIndexClick	= -1;
				for( int nIndex=0; nIndex<nShowCount; nIndex ++ )
				{
					CRect	rectElement	= m_rectReport;
					rectElement.top		= m_rectReport.top+RT_RDTITLE_HEIGHT+RT_RDELEMENT_HEIGHT*nIndex;
					rectElement.bottom	= m_rectReport.top+RT_RDTITLE_HEIGHT+RT_RDELEMENT_HEIGHT*(nIndex+1);
					if( rectElement.PtInRect(point) )
					{
						nIndexClick	= nIndex;
						break;
					}
				}
				// 画选中标记
				int	nSelectPosNew	= nIndexClick+m_nCurrentStartPos;
				if( -1 != nIndexClick && nSelectPosNew >= 0 && nSelectPosNew < m_aReportBigTrade.GetSize() )
				{
					DECLARE_COLOR_DEFINATION

					CClientDC	dc(m_pParent);
					int	y	= m_rectReport.top+RT_RDTITLE_HEIGHT+RT_RDELEMENT_HEIGHT*(nIndexClick+1) - 1;
					if( y > m_rectReport.top && y < m_rectReport.bottom )
						DrawLine( &dc, 2, clrBorder, m_rectReport.left+5, y, m_rectReport.right-5, y );
					if( -1 != m_nCurrentSelectPos 
						&& nSelectPosNew != m_nCurrentSelectPos
						&& m_nCurrentSelectPos-m_nCurrentStartPos >= 0 )
					{
						y	= m_rectReport.top+RT_RDTITLE_HEIGHT+RT_RDELEMENT_HEIGHT*(m_nCurrentSelectPos-m_nCurrentStartPos+1) - 1;
						if( y > m_rectReport.top && y < m_rectReport.bottom )
							DrawLine( &dc, 2, clrBK, m_rectReport.left+5, y, m_rectReport.right-5, y );
					}
					m_nCurrentSelectPos	= nSelectPosNew;
				}
			}
		}
	}
	else if( CRealTime::modeBigTradeDetail == m_nDrawMode )	// 大单成交明细
	{
		int	nColumnPerPage	= GetColumnPerPage( m_rectAll );
		int	nCountPerColumn	= GetCountPerColumn( m_rectAll );
		int	nCountPerPage	= nCountPerColumn * nColumnPerPage;
		if( nCountPerPage <= 0 )
			return;
		
		int	nOldSelectPos	= m_nCurrentSelectPos;
		int	nStartPos		= m_nCurrentStartPos;

		for( int nColumn=0; nColumn<nColumnPerPage; nColumn ++ )
		{
			if( nStartPos >= m_aReportBigTrade.GetSize() )
				break;

			CRect	rectColumn;
			rectColumn.top		= m_rectAll.top + RT_RDTITLE_HEIGHT;
			rectColumn.bottom	= m_rectAll.bottom;
			rectColumn.left		= m_rectAll.left + nColumn*RT_RDCOLUMN_WIDTH;
			rectColumn.right	= rectColumn.left + RT_RDCOLUMN_WIDTH;
			
			// 清除上次选中标记
			if( -1 != nOldSelectPos 
				&& nOldSelectPos >= nStartPos
				&& nOldSelectPos < nStartPos+nCountPerColumn )
			{
				DECLARE_COLOR_DEFINATION

				CClientDC	dc(m_pParent);
				int y	= rectColumn.top+RT_RDTITLE_HEIGHT+RT_RDELEMENT_HEIGHT*(nOldSelectPos-nStartPos+1) - 1;
				if( y > rectColumn.top && y < rectColumn.bottom )
					DrawLine( &dc, 2, clrBK, rectColumn.left+5, y, rectColumn.right-5, y );
			}
			
			if( rectColumn.PtInRect(point) )
			{
				int nIndexClick	= -1;
				for( int nIndex=0; nIndex<nCountPerColumn; nIndex ++ )
				{
					CRect	rectElement	= rectColumn;
					rectElement.top		= rectColumn.top+RT_RDTITLE_HEIGHT+RT_RDELEMENT_HEIGHT*nIndex;
					rectElement.bottom	= rectColumn.top+RT_RDTITLE_HEIGHT+RT_RDELEMENT_HEIGHT*(nIndex+1);
					if( rectElement.PtInRect(point) )
					{
						nIndexClick	= nIndex;
						break;
					}
				}

				// 画选中标记
				int	nSelectPosNew	= nIndexClick+nStartPos;
				if( -1 != nIndexClick && nSelectPosNew >= 0 && nSelectPosNew < m_aReportBigTrade.GetSize() )
				{
					DECLARE_COLOR_DEFINATION

					CClientDC	dc(m_pParent);
					int	y	= rectColumn.top+RT_RDTITLE_HEIGHT+RT_RDELEMENT_HEIGHT*(nIndexClick+1) - 1;
					if( y > rectColumn.top && y < rectColumn.bottom )
						DrawLine( &dc, 2, clrBorder, rectColumn.left+5, y, rectColumn.right-5, y );
					m_nCurrentSelectPos	= nSelectPosNew;
				}
			}
			
			nStartPos	+= nCountPerColumn;
		}
	}
}


void CRealTime::OnLButtonDblClk( UINT nFlags, CPoint point )
{
	OnLButtonDown( nFlags, point, FALSE, FALSE );

	if( CRealTime::modePriceLine == m_nDrawMode
		&& CRealTime::reportBigTrade == m_nReportWhat )
	{
		// reportBigTrade 大单成交,选中股票
		if( m_rectReport.PtInRect(point) )
		{
			if( m_nCurrentSelectPos >= 0 && m_nCurrentSelectPos < m_aReportBigTrade.GetSize() )
			{
				REPORT & report = m_aReportBigTrade.ElementAt(m_nCurrentSelectPos);
				AfxGetProfile().SetCurrentStock( report.m_szCode);
			}
		}
	}
	else if( CRealTime::modeBigTradeDetail == m_nDrawMode )
	{
		// 大单成交,选中股票
		if( m_nCurrentSelectPos >= 0 && m_nCurrentSelectPos < m_aReportBigTrade.GetSize() )
		{
			REPORT & report = m_aReportBigTrade.ElementAt(m_nCurrentSelectPos);
			AfxGetProfile().SetCurrentStock( report.m_szCode );
			SetDrawMode( CRealTime::modePriceLine, GetDrawTechLine(), GetReportWhat() ); 
		}
	}
}

void CRealTime::ResetIndexCurrent( int nIndexCurrent )
{
	m_nIndexCurrent	= nIndexCurrent;
}

BOOL CRealTime::AddIndexCurrent( int nIndex )
{
	if( CRealTime::modePriceLine != m_nDrawMode )
		return FALSE;

	for( int k=0; k<m_anIndexCurrent.GetSize(); k++ )
	{
		if( (UINT)nIndex == m_anIndexCurrent[k] )
			return FALSE;
	}
	m_anIndexCurrent.Add( nIndex );
	return TRUE;
}

void CRealTime::OnIndexCurrentChanged( )
{
	if( CRealTime::modePriceLine != m_nDrawMode )
		return;

	DECLARE_COLOR_DEFINATION

	if( !m_pParent || !::IsWindow(m_pParent->GetSafeHwnd()) )
		return;
	
	CClientDC	dc(m_pParent);
	CDC	*pDC	= &dc;

	CRect	rectTop(m_rectPrice.left+135,m_rectAll.top,m_rectPrice.right,m_rectPrice.top-1 );
	pDC->FillSolidRect( &rectTop, clrBK );
	
	if( m_nIndexCurrent < 0 || m_nIndexCurrent >= m_CurStock.GetMinute().GetSize() )
		return;
	
	MINUTE	minute	= m_CurStock.GetMinute().ElementAt(m_nIndexCurrent);

	// Fill Background
	pDC->SetBkColor( clrBK );

	CString	strTemp;
	CFont	* pOldFont	= AfxSelectDCFont( pDC, 12 );

	int	x	= rectTop.left;
	int	y	= rectTop.top + 4;
	int	right	= rectTop.right-100;
	pDC->SetTextColor( clrText );
	strTemp = "时间";
	if( x < right )		pDC->TextOut( x, y,   strTemp );
	strTemp = "价格";
	if( x+80 < right )	pDC->TextOut( x+80, y,  strTemp );
	strTemp = "量(手)";
	if( x+160 < right )	pDC->TextOut( x+160, y,  strTemp );
	strTemp = "额(千元)";
	if( x+290 < right )	pDC->TextOut( x+290, y,  strTemp );

	// Time
	CSPTime	time(minute.m_time);
	strTemp	= time.Format( "%H:%M" );
	pDC->SetTextColor( clrPlane );
	if( x+30 < right )	pDC->TextOut( x+30, y, strTemp );

	// Price
	CString strPriceFmt;
	strPriceFmt.Format( "%%.%df", m_CurStock.GetStockInfo().DigitBit() );
	strTemp.Format( strPriceFmt, minute.m_fNew );
	pDC->SetTextColor( RT_DETERMINE_COLOR( minute.m_fNew, m_CurStock.GetStockInfo().m_fLast ) );
	if( x+110 < right )	pDC->TextOut( x+110, y, strTemp );
	
	// Volume
	double	dVolume	= minute.m_fVolume;
	if( m_nIndexCurrent > 0 )
		dVolume	-= m_CurStock.GetMinute()[m_nIndexCurrent-1].m_fVolume;
	strTemp.Format( "%.0f", dVolume*0.01 );
	pDC->SetTextColor( clrTitle );
	if( x+220 < right )	pDC->TextOut( x+220, y, strTemp );
	
	// Amount
	double	dAmount	= minute.m_fAmount;
	if( m_nIndexCurrent > 0 )
		dAmount	-= m_CurStock.GetMinute()[m_nIndexCurrent-1].m_fAmount;
	strTemp.Format( "%.2f", dAmount*0.001 );
	pDC->SetTextColor( clrTitle );
	if( x+350 < right )	pDC->TextOut( x+350, y, strTemp );

	pDC->SelectObject( pOldFont );
}

void CRealTime::DrawSelectionLine( CDC * pDC, BOOL bAddOrRemove )
{
	if( CRealTime::modePriceLine != m_nDrawMode )
		return;

	ASSERT( m_pParent && ::IsWindow( m_pParent->GetSafeHwnd() ) );
	if( !m_pParent || !::IsWindow(m_pParent->GetSafeHwnd()) )
		return;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -