Пример #1
0
void CSListView::StockInfoChanged( LONG infoid, CStockInfo & info )
{
	CStockContainer & container = AfxGetSListStockContainer();

	container.Lock();

	// update grid value
	for( int nRow=m_Grid.GetRowCount()-1; nRow >= 0; nRow-- )
	{
		LPARAM	id	=	m_Grid.GetItemData(nRow,0);
		if( id == infoid )
		{
			for( int nCol=0; nCol<m_Grid.GetColumnCount(); nCol++ )
			{
				LPARAM lParam = m_Grid.GetItemData(0,nCol);
				m_Grid.SetItemText( nRow, nCol, AfxGetVariantDispString( lParam, info, &container ) );
				m_Grid.SetItemFgColour( nRow, nCol, AfxGetVariantColor( lParam, info ) );
			}
			m_Grid.RedrawRow( nRow );
			break;
		}
	}

	container.UnLock();
}
Пример #2
0
int CStock::PrepareBaseInfo( BOOL bReload )
{
	// Load From File
	PrepareData( CStock::dataBasetext, 0, bReload );
	
	// Save To pText
	int nTextLen = m_nBaseTextLen;
	char * pText	=	NULL;
	if( m_pBaseText && nTextLen > 0 )
	{
		pText = new CHAR[nTextLen+1];
		if( pText )	memcpy( pText, m_pBaseText, nTextLen );
		if( pText )	pText[nTextLen] = 0;
	}
	
	int nIntroLen = SLH_MAX * 80;
	if( !AllocBaseTextMem( nIntroLen + m_nBaseTextLen + 10 ) )
		return 0;

	int nCount = 0;
	
	for( int nVariantID = SLH_MIN; nVariantID <= SLH_MAX; nVariantID ++ )
	{
		CSPString	strTemp	=	AfxGetVariantName( nVariantID, TRUE );
		strTemp	+=	": \t";
		strTemp	+=	(LPCTSTR)AfxGetVariantDispString( nVariantID, m_stockinfo, NULL );
		strTemp	+=	STRING_CRLF;

		SP_ASSERT( nCount + strTemp.GetLength() < nIntroLen );
		if( nCount + strTemp.GetLength() < nIntroLen )
		{
			nCount += strTemp.GetLength();
			strcat( m_pBaseText, (LPCTSTR)strTemp );
		}
	}
	
	nCount += strlen(STRING_CRLF);
	strcat( m_pBaseText, STRING_CRLF );
	nCount += strlen(STRING_CRLF);
	strcat( m_pBaseText, STRING_CRLF );
	
	if( pText && nCount + nTextLen < m_nBaseTextLen )
	{
		nCount += nTextLen;
		strcat( m_pBaseText, pText );
	}
	
	if( pText )
		delete [] pText;

	return nCount;
}
Пример #3
0
BOOL CSListView::SetAverageItem( CGridCtrl &grid, CStockContainer & container, BOOL bRedraw )
{
	if( grid.GetColumnCount() <= 0 )
		return FALSE;

	container.Lock();

	// Get LPARAM
	CUIntArray	anParams;
	anParams.SetSize( 0, grid.GetColumnCount() );
	for( int nCol=0; nCol < grid.GetColumnCount(); nCol ++ )
	{
		LPARAM	lParam	=	grid.GetItemData( 0, nCol );
		anParams.Add( lParam );
	}

	// Set Average
	CStockInfo & infoAve = container.GetAverage( );
	CStockInfo & infoWAve = container.GetWeightAverage( );
	int	iRowAve=0, iRowWAve=0;

	if( grid.GetRowCount() >= 3
		&& grid.GetItemData(grid.GetRowCount()-2,0) == (LPARAM)ID_STOCKCNTN_AVERAGE
		&& grid.GetItemData(grid.GetRowCount()-1,0) == (LPARAM)ID_STOCKCNTN_WEIGHTAVERAGE )
	{
		// get item id
		iRowAve		=	grid.GetRowCount()-2;
		iRowWAve	=	grid.GetRowCount()-1;
	}
	else
	{
		// Insert item
		iRowAve = grid.InsertRow( infoAve.GetStockName() );
		grid.SetItemData( iRowAve, 0, (LPARAM)ID_STOCKCNTN_AVERAGE );
		iRowWAve = grid.InsertRow( infoWAve.GetStockName() );
		grid.SetItemData( iRowWAve, 0, (LPARAM)ID_STOCKCNTN_WEIGHTAVERAGE );
	}

	// Set Average
	for( nCol=0; nCol<anParams.GetSize(); nCol++ )
	{
		grid.SetItemText( iRowAve, nCol, AfxGetVariantDispString(anParams[nCol], infoAve, NULL) );
		grid.SetItemBkColour( iRowAve, nCol, AfxGetProfile().GetColor(CColorClass::clrSListBK) );
		grid.SetItemFgColour( iRowAve, nCol, AfxGetVariantColor( anParams[nCol], infoAve ) );
	}

	// Set Weight Average
	for( nCol=0; nCol<anParams.GetSize(); nCol++ )
	{
		grid.SetItemText( iRowWAve, nCol, AfxGetVariantDispString(anParams[nCol], infoWAve, NULL) );
		grid.SetItemBkColour( iRowWAve, nCol, AfxGetProfile().GetColor(CColorClass::clrSListBK) );
		grid.SetItemFgColour( iRowWAve, nCol, AfxGetVariantColor( anParams[nCol], infoWAve ) );
	}

	//	Set Param which is
	//	SLH_MARKETVALUE, SLH_MARKETVALUEA, SLH_MARKETVALUEB and etc,  and more than SLH_USERDEFINE_BEGIN
	for( nCol=0; nCol < anParams.GetSize(); nCol ++ )
	{
		UINT	lParam	=	anParams[nCol];
		if( SLH_DIFF == lParam || SLH_DIFFPERCENT == lParam || SLH_SCOPE == lParam
			|| SLH_DIFFPERCENT_MIN5 == lParam || SLH_PE == lParam
			|| SLH_PMAININCOME == lParam || SLH_RATIO_PCASH == lParam
			|| SLH_RATIO_CURRENCY == lParam || SLH_RATIO_CHANGEHAND == lParam
			|| SLH_RATIO_VOLUME == lParam || SLH_RS == lParam
			|| SLH_MARKETVALUE == lParam || SLH_MARKETVALUEA == lParam
			|| SLH_MARKETVALUEB == lParam || lParam >= SLH_USERDEFINE_BEGIN )
		{
			double	dc = 0., average = 0.;
			double	wsum = 0.0001, waverage = 0., w = 0.;
			for( int iRow=1; iRow<grid.GetRowCount(); iRow++ )
			{
				if( iRow == iRowAve || iRow == iRowWAve )
					continue;

				int	id	=	grid.GetItemData(iRow,0);
				if( id < 0 || id > container.GetSize() )
					continue;

				CStockInfo	& info = container.ElementAt(id);
				w	=	info.m_fShare_count_total;
				double	dValue	=	0.;
				if( !AfxGetVariantValue( lParam, info, &dValue, &container ) )
					continue;

				average		=	(average * dc + dValue)/(dc+1);
				waverage	=	(waverage * wsum + dValue * w)/(wsum+w);

				dc		+=	1;
				wsum	+=	w;
			}

			CString	strText;
			if( SLH_MARKETVALUE == lParam || SLH_MARKETVALUEA == lParam || SLH_MARKETVALUEB == lParam )
			{
				strText.Format( "%u", (DWORD)average );
				grid.SetItemText( iRowAve, nCol, strText );
				grid.SetItemText( iRowWAve, nCol, "-" );
			}
			else
			{
				strText.Format( "%.2f", average );
				grid.SetItemText( iRowAve, nCol, strText );
				strText.Format( "%.2f", waverage );
				grid.SetItemText( iRowWAve, nCol, strText );
			}
		}
	}

	container.UnLock();

	if( bRedraw )
	{
		grid.RedrawRow( iRowAve );
		grid.RedrawRow( iRowWAve );
	}
	return TRUE;
}
Пример #4
0
void CMultiSort::DrawMultiSort( CDC * pDC, MULTISORT &ms, CRect rect, UINT nSLH, int nSelectPos )
{
	DECLARE_COLOR_DEFINATION

	int	x	=	rect.left+8;
	int	x2	=	(int)( rect.left+0.56*rect.Width() );
	int	x3	=	rect.right-8;
	int	y	=	rect.top+20;
	int	yStep	=	(rect.Height()-23) / 6 ;
	if( yStep <= 0 )
		return;
	
	CFont	* pOldFont	=	AfxSelectDCFont( pDC, 14 );
	pDC->SetBkColor( clrBK );

	int size = sizeof(m_msRise.m_stocks)/sizeof(m_msRise.m_stocks[0]);
	for( int i=0; i<size; i++ )
	{
		CStockInfo	info;
		char	buf_code[sizeof(ms.m_stocks[i].m_code)+1];
		memset( buf_code, 0, sizeof(buf_code) );
		memcpy( buf_code, ms.m_stocks[i].m_code, sizeof(ms.m_stocks[i].m_code) );
		if( !AfxGetStockContainer().GetStockInfo(buf_code, &info) )
			continue;
		info.m_fClose	=	float(0.001*ms.m_stocks[i].m_data1);

		pDC->SetTextColor( clrText );
//#ifdef	CLKLAN_ENGLISH_US
//		pDC->TextOut( x, y, info.GetStockCode() );
//#else
		pDC->TextOut( x, y, info.GetStockName() );
//#endif

		UINT nOldAlign = pDC->SetTextAlign( TA_RIGHT | TA_TOP );
		pDC->SetTextColor( AfxGetVariantColor(SLH_CLOSE,info) );
		pDC->TextOut( x2, y, (LPCTSTR)AfxGetVariantDispString(SLH_CLOSE,info,NULL) );

		CString strTemp;
		if( CStock::classVolRatio == ms.m_class )
			strTemp.Format( "%.2f", 0.01*ms.m_stocks[i].m_data2 );
		else if( CStock::classAmount == ms.m_class )
			strTemp.Format( "%.0f", 0.001*ms.m_stocks[i].m_data2 );
		else
			strTemp.Format( "%.2f%%", 0.01*ms.m_stocks[i].m_data2 );
		pDC->TextOut( x3, y, strTemp );

		y	+=	yStep;
		pDC->SetTextAlign( nOldAlign );

		// 选中股票
		if( nSelectPos == i )
		{
			int	ySel = y-yStep+16;
			if( ySel > rect.top && ySel < rect.bottom )
				DrawLine( pDC, 2, clrBorder, rect.left+5, ySel, rect.right-5, ySel );
		}
	}

	// 补足股票排名
	for( i=size; i<6; i++ )
	{
		pDC->SetTextColor( clrText );
		pDC->TextOut( x, y, "-" );

		UINT nOldAlign = pDC->SetTextAlign( TA_RIGHT | TA_TOP );
		pDC->TextOut( x2, y, "-" );

		pDC->TextOut( x3, y, "-" );

		y	+=	yStep;
		pDC->SetTextAlign( nOldAlign );
	}

	pDC->SelectObject( pOldFont );
}
Пример #5
0
void CMultiSort::DrawMultiSort( CDC * pDC, CSPDWordArray &adwSortID, CRect rect, UINT nSLH, int nSelectPos )
{
	DECLARE_COLOR_DEFINATION

	int	x	=	rect.left+8;
	int	x2	=	(int)( rect.left+0.56*rect.Width() );
	int	x3	=	rect.right-8;
	int	y	=	rect.top+20;
	int	yStep	=	(rect.Height()-23) / 6 ;
	if( yStep <= 0 )
		return;
	
	CFont	* pOldFont	=	AfxSelectDCFont( pDC, 14 );
	pDC->SetBkColor( clrBK );

	for( int i=0; i<adwSortID.GetSize(); i++ )
	{
		if( (int)adwSortID[i] < 0 || (int)adwSortID[i] >= AfxGetStockContainer().GetSize() )
			continue;

		CStockInfo	& info	=	AfxGetStockContainer().ElementAt(adwSortID[i]);

		pDC->SetTextColor( clrText );
//#ifdef	CLKLAN_ENGLISH_US
//		pDC->TextOut( x, y, info.GetStockCode() );
//#else
		pDC->TextOut( x, y, info.GetStockName() );
//#endif

		UINT nOldAlign = pDC->SetTextAlign( TA_RIGHT | TA_TOP );
		pDC->SetTextColor( AfxGetVariantColor(SLH_CLOSE,info) );
		pDC->TextOut( x2, y, (LPCTSTR)AfxGetVariantDispString(SLH_CLOSE,info,NULL) );

		pDC->SetTextColor( AfxGetVariantColor(nSLH,info) );
		if( SLH_RATIO_VOLUME == nSLH )
		{
			double	dVolRatio	=	1;
			CSPTime	tTrade;
			if( AfxGetVariantValue(nSLH,info,&dVolRatio,NULL)
				&& tTrade.FromStockTimeDay( info.m_datetech ) )
				dVolRatio = dVolRatio / CSPTime::GetTimeTradeRatioOfOneDay( tTrade, CSPTime::GetCurrentTime() );

			CString	strTemp;
			strTemp.Format( "%.2f", dVolRatio );
			pDC->TextOut( x3, y, strTemp );
		}
		else
		{
			pDC->TextOut( x3, y, (LPCTSTR)AfxGetVariantDispString(nSLH,info,NULL) );
		}

		y	+=	yStep;
		pDC->SetTextAlign( nOldAlign );

		// 选中股票
		if( nSelectPos == i )
		{
			int	ySel = y-yStep+16;
			if( ySel > rect.top && ySel < rect.bottom )
				DrawLine( pDC, 2, clrBorder, rect.left+5, ySel, rect.right-5, ySel );
		}
	}

	// 补足股票排名
	for( i=adwSortID.GetSize(); i<6; i++ )
	{
		pDC->SetTextColor( clrText );
		pDC->TextOut( x, y, "-" );

		UINT nOldAlign = pDC->SetTextAlign( TA_RIGHT | TA_TOP );
		pDC->TextOut( x2, y, "-" );

		pDC->TextOut( x3, y, "-" );

		y	+=	yStep;
		pDC->SetTextAlign( nOldAlign );
	}

	pDC->SelectObject( pOldFont );
}
Пример #6
0
void CQuoteTipDlg::OnPaint() 
{
	// Do not call CTipDialog::OnPaint() for painting messages
	// CTipDialog::OnPaint();

	CPaintDC dc(this); // device context for painting
	
	dc.SetBkMode( TRANSPARENT );
	CFont * pOldFont = AfxSelectDCFont(&dc,14);

	CRect rectAll;
	GetClientRect( &rectAll );
	int nWidthTotal = rectAll.Width();
	double o = (nWidthTotal-10) / 26;

	CRect rect;
	int x = 5, y = 5;
	int nCount = 0;
	CStockContainer & container = AfxGetSListStockContainer();

	// Draw Header Title
	{
		CString strCode = AfxGetVariantName(SLH_CODE,FALSE);
		CString strClose = AfxGetVariantName(SLH_CLOSE,FALSE);
		CString strDiffPercent = AfxGetVariantName(SLH_DIFFPERCENT,FALSE);
		CString strVolume = AfxGetVariantName(SLH_VOLUME,FALSE);

		dc.SetTextColor( AfxGetProfile().GetColor(CColorClass::clrTitle) );
		rect = CRect(x,y,x+6*o,y+m_nItemHeight-1);
		dc.DrawText( strCode, rect, DT_VCENTER | DT_CENTER | DT_SINGLELINE | DT_WORD_ELLIPSIS );
		rect = CRect(x+6*o,y,x+13*o,y+m_nItemHeight-1);
		dc.DrawText( strClose, rect, DT_VCENTER | DT_CENTER | DT_SINGLELINE | DT_WORD_ELLIPSIS );
		rect = CRect(x+13*o,y,x+19*o,y+m_nItemHeight-1);
		dc.DrawText( strDiffPercent, rect, DT_VCENTER | DT_CENTER | DT_SINGLELINE | DT_WORD_ELLIPSIS );
		rect = CRect(x+19*o,y,rectAll.right-5,y+m_nItemHeight-1);
		dc.DrawText( strVolume, rect, DT_VCENTER | DT_CENTER | DT_SINGLELINE | DT_WORD_ELLIPSIS );

		y += m_nItemHeight;
	}

	y += 2;

	for( int nIndex=m_nIndexStart; nIndex<container.GetSize(); nIndex++ )
	{
		nCount ++;
		if( nCount > m_nPageCount )
			break;

		CStockInfo & info = container.ElementAt(nIndex);
		CString strCode = AfxGetVariantDispString(SLH_CODE,info,NULL);
		CString strClose = AfxGetVariantDispString(SLH_CLOSE,info,NULL);
		CString strDiffPercent = AfxGetVariantDispString(SLH_DIFFPERCENT,info,NULL);
		CString strVolume = AfxGetVariantDispString(SLH_VOLUME,info,NULL);

		rect = CRect(x,y,x+6*o,y+m_nItemHeight-1);
		dc.SetTextColor( AfxGetVariantColor(SLH_CODE,info) );
		dc.DrawText( strCode, rect, DT_VCENTER | DT_RIGHT | DT_SINGLELINE | DT_WORD_ELLIPSIS );
		rect = CRect(x+6*o,y,x+13*o,y+m_nItemHeight-1);
		dc.SetTextColor( AfxGetVariantColor(SLH_CLOSE,info) );
		dc.DrawText( strClose, rect, DT_VCENTER | DT_RIGHT | DT_SINGLELINE | DT_WORD_ELLIPSIS );
		rect = CRect(x+13*o,y,x+18*o,y+m_nItemHeight-1);
		dc.SetTextColor( AfxGetVariantColor(SLH_DIFFPERCENT,info) );
		dc.DrawText( strDiffPercent, rect, DT_VCENTER | DT_RIGHT | DT_SINGLELINE | DT_WORD_ELLIPSIS );
		rect = CRect(x+18*o,y,rectAll.right-10,y+m_nItemHeight-1);
		dc.SetTextColor( AfxGetVariantColor(SLH_VOLUME,info) );
		dc.DrawText( strVolume, rect, DT_VCENTER | DT_RIGHT | DT_SINGLELINE | DT_WORD_ELLIPSIS );

		y += m_nItemHeight;
	}

	dc.SelectObject(pOldFont);
}
Пример #7
0
void CSListView::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint) 
{
	// TODO: Add your specialized code here and/or call the base class
	if( UPDATE_HINT_SLISTVIEW != lHint )
		return;
	if( IsWindowVisible() )
		SetFocus( );
	int	nColumnCount	=	m_Grid.GetColumnCount();
	if( nColumnCount <= 0 )
		return;

	if( GetParentFrame()->GetSafeHwnd() != AfxGetMainFrame()->GetActiveFrame()->GetSafeHwnd() )
	{
		m_bShouldUpdate	=	TRUE;
		return;
	}
	m_bShouldUpdate	=	FALSE;

	CStockContainer & container = AfxGetSListStockContainer();
	container.Lock();

	m_Grid.DeleteNonFixedRows();

	// Progress
	CMainFrame	* pMainFrame = AfxGetMainFrame();
	if( pMainFrame )
	{
		pMainFrame->ShowProgressBar( );
		pMainFrame->SetProgress( 0 );
		pMainFrame->SetMessageText( IDS_MAINFRAME_WAITING );
	}

	CUIntArray	anParams;
	anParams.SetSize( 0, nColumnCount );
	for( int nCol=0; nCol < nColumnCount; nCol ++ )
	{
		LPARAM	lParam	=	m_Grid.GetItemData( 0, nCol );
		anParams.Add( lParam );
	}

	CRect rectClient;
	GetClientRect( &rectClient );
	int nPageCount = 1 + rectClient.Height() / abs(m_Grid.GetFixedRowHeight()) + 1;

	for( int i=0; i<container.GetSize(); i++ )
	{
		CStockInfo & info = container.GetStockInfoByID(i);

		int nRow = m_Grid.InsertRow( info.GetStockName() );
		m_Grid.SetItemData( nRow, 0, i );

		for( int nCol=0; nCol<anParams.GetSize(); nCol++ )
		{
			m_Grid.SetItemFormat( nRow, nCol, DT_CENTER|DT_VCENTER|DT_SINGLELINE );
			m_Grid.SetItemText( nRow, nCol, AfxGetVariantDispString( anParams[nCol], info, &container ) );
			m_Grid.SetItemBkColour( nRow, nCol, AfxGetProfile().GetColor(CColorClass::clrSListBK) );
			m_Grid.SetItemFgColour( nRow, nCol, AfxGetVariantColor( anParams[nCol], info ) );
			if( anParams[nCol] == SLH_DATE )
				m_Grid.SetColumnWidth( nCol, 80 );
			if( anParams[nCol] == SLH_CODE )
				m_Grid.SetColumnWidth( nCol, 60 );
		}

		if( i == nPageCount+5 )
		{
			m_Grid.Invalidate( );
			MSG		msg;
			while (::PeekMessage(&msg, NULL, NULL, NULL, PM_NOREMOVE) )
				AfxGetApp()->PumpMessage();
		}
		if( pMainFrame )
			pMainFrame->SetProgress( 100*i/container.GetSize() );
	}

	// Set Average and Weight Average
//	SetAverageItem( m_Grid, container, FALSE );

	// Sort If Needed
	if( -1 != m_nColSort )
	{
		LPARAM	lParam	=	m_Grid.GetItemData( 0, m_nColSort );
		if( lParam >= 0 )
		{
			CStockContainer::m_pSortContainer	=	&container;
			container.m_nSortVariantID	=	lParam;
			container.m_bSortAscend		=	m_bSortAscend;
			m_Grid.SortItems( ItemCompareFunc, 0, TRUE );
		}
	}

	if( pMainFrame )
	{
		pMainFrame->SetProgress( 100 );
		pMainFrame->HideProgressBar( );
		pMainFrame->SetMessageText( IDS_MAINFRAME_FINISHED );
		pMainFrame->SetMessageText( IDS_HELPTIP_SLIST );
	}

	if( m_bFirstUpdate )
		m_Grid.AutoSizeColumns( );
	else
		m_Grid.SetColumnWidth( 0, 80 );
	m_bFirstUpdate	=	FALSE;
	m_Grid.Invalidate( );

	SendRequestQuote(TRUE);

	container.UnLock();
}