📄 slistview.cpp.svn-base
字号:
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;
}
void CSListView::OnDblclkItem( int nStockIndex )
{
CStockContainer & container = AfxGetSListStockContainer();
int nType;
CSPString strDomain;
DWORD dwDate = -1;
if( nStockIndex >= 0 )
{
container.GetCurrentType( &nType, &strDomain, &dwDate );
if( ( nType == CStockContainer::typeDomain && strDomain.IsEmpty() )
|| ( nType == CStockContainer::typeGroup && strDomain.IsEmpty() ) )
{
CStockInfo & info = container.GetStockInfoByID( nStockIndex );
AfxShowSlist( nType, CString(info.GetStockName()), dwDate );
}
else
AfxShowStockRealTime( nStockIndex, TRUE );
}
}
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();
}
void CSListView::SendRequestQuote( BOOL bForced )
{
static int nLastStart = -1;
static int nLastCount = -1;
BOOL bQuoteTipSended = FALSE;
BOOL bInTrade = CSPTime::InTradeTime(CSPTime::GetCurrentTime().GetTime(),900);
CView * pView = AfxGetStaticDoc()->GetActiveView();
if( bForced )
{
CStockContainer stocks;
CStockInfo info;
if( AfxGetStockContainer().GetStockInfo( STKLIB_CODE_MAIN, &info ) )
stocks.Add(info);
if( AfxGetStockContainer().GetStockInfo( STKLIB_CODE_MAINSZN, &info ) )
stocks.Add(info);
if( stocks.GetSize() > 0 )
AfxGetStkReceiver().RequestStockData( CStock::dataReport, stocks.GetData(), stocks.GetSize(), 0, 0 );
}
if( bForced || pView == this )
{
CCellRange cr = m_Grid.GetVisibleNonFixedCellRange();
int nStart = cr.GetMinRow() - 1;
int nCount = cr.GetMaxRow() - cr.GetMinRow() + 1;
CStockContainer & container = AfxGetSListStockContainer();
container.Lock();
if( nStart >= 0 && nCount > 0 && container.GetSize() > 0 && (bInTrade || bForced || nLastStart != nStart || nLastCount != nCount) )
{
nLastStart = nStart;
nLastCount = nCount;
AfxGetStkReceiver().RequestStockData( CStock::dataReport, container.GetData()+nStart, min(nCount,container.GetSize()-nStart), 0, 0 );
bQuoteTipSended = (0 == nStart && nCount >= 9);
}
container.UnLock();
}
if( bInTrade )
{
// 预警系统所需股票行情刷新
CAlarmCondContainer & conds = AfxGetProfile().GetAlarmCondContainer();
CStockContainer stocks;
stocks.SetSize( 0, conds.GetSize() + 5 );
for( int i=0; i<conds.GetSize(); i++ )
{
ALARMCOND cond = conds.GetAt(i);
CStockInfo info;
if( AfxGetStockContainer().GetStockInfo( cond.m_szCode, &info ) )
stocks.Add( info );
}
CStockInfo infoMain, infoMainSzn;
if( AfxGetStockContainer().GetStockInfo( STKLIB_CODE_MAIN, &infoMain )
&& AfxGetStockContainer().GetStockInfo( STKLIB_CODE_MAINSZN, &infoMainSzn ) )
{
stocks.Add( infoMain );
stocks.Add( infoMainSzn );
}
// 行情QuoteTip 需要行情数据
if( !bQuoteTipSended )
{
CStockContainer & container = AfxGetSListStockContainer();
container.Lock();
for( int i=0; i<9 && i<container.GetSize(); i++ )
stocks.Add( container.ElementAt(i) );
container.UnLock();
}
if( stocks.GetSize() > 0 )
AfxGetStkReceiver().RequestStockData( CStock::dataReport, stocks.GetData(), stocks.GetSize(), 0, 0 );
}
}
/////////////////////////////////////////////////////////////////////////////
// CSListView overrides
BOOL CSListView::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext)
{
// TODO: Add your specialized code here and/or call the base class
return CFormView::Create(lpszClassName, lpszWindowName, dwStyle, rect, pParentWnd, nID, pContext);
}
BOOL CSListView::OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo)
{
// TODO: Add your specialized code here and/or call the base class
if( ::IsWindow(m_Grid.GetSafeHwnd()) )
if( m_Grid.OnCmdMsg(nID, nCode, pExtra, pHandlerInfo))
return TRUE;
return CFormView::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo);
}
int CALLBACK ItemCompareFunc(LPARAM lParam1, LPARAM lParam2,
LPARAM lParamSort)
{
if( lParam1 < 0 && lParam2 < 0 )
return 0;
if( lParam1 < 0 )
return 1;
if( lParam2 < 0 )
return -1;
CStockContainer & container = AfxGetSListStockContainer();
if( lParam1 >= container.GetSize() || lParam2 >= container.GetSize() )
{
ASSERT( FALSE );
return 0;
}
CStockInfo &s1 = container.ElementAt(lParam1);
CStockInfo &s2 = container.ElementAt(lParam2);
return CStockContainer::SortFunction( &s1, &s2 );
}
BOOL CSListView::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
if( m_Grid.GetSafeHwnd() == pMsg->hwnd )
{
if( WM_LBUTTONDBLCLK == pMsg->message
|| ( WM_KEYDOWN == pMsg->message && VK_RETURN == pMsg->wParam ) )
{
int nColumnCount = m_Grid.GetColumnCount();
int nRowCount = m_Grid.GetRowCount();
if( nColumnCount <=0 || nRowCount <= 0 )
return CFormView::PreTranslateMessage(pMsg);
CRect rectCell;
m_Grid.GetCellRect(0,0,&rectCell);
CPoint pt = pMsg->pt;
::ScreenToClient( m_Grid.GetSafeHwnd(), &pt );
if( pt.y >= rectCell.top && pt.y < rectCell.bottom )
return CFormView::PreTranslateMessage(pMsg);
int nSelRow = m_Grid.GetFocusCell().row;
if( nSelRow >= 1 && nSelRow < m_Grid.GetRowCount() )
{
int id = m_Grid.GetItemData(nSelRow,0);
OnDblclkItem( id );
}
}
else if( WM_LBUTTONUP == pMsg->message )
{
int nColumnCount = m_Grid.GetColumnCount();
int nRowCount = m_Grid.GetRowCount();
if( nColumnCount <=0 || nRowCount <= 0 )
return CFormView::PreTranslateMessage(pMsg);
CRect rectCell;
m_Grid.GetCellRect(0,0,&rectCell);
CPoint pt = pMsg->pt;
::ScreenToClient( m_Grid.GetSafeHwnd(), &pt );
if( pt.y < rectCell.top || pt.y >= rectCell.bottom )
return CFormView::PreTranslateMessage(pMsg);
CCellID cell = m_Grid.GetFocusCell();
if( cell.col >=0 && cell.col < nColumnCount )
{
BOOL bSortAscendNew = ( m_nColSort == cell.col ? !m_bSortAscend : FALSE );
RemoveSortSign( );
m_nColSort = cell.col;
m_bSortAscend = bSortAscendNew;
SetSortSign( );
LPARAM lParam = m_Grid.GetItemData( 0, cell.col );
if( lParam >= 0 )
{
CStockContainer & container = AfxGetSListStockContainer();
container.Lock();
//if( container.Sort( lParam, m_bSortAscend ) )
// OnUpdate( NULL, UPDATE_HINT_SLISTVIEW, NULL );
CStockContainer::m_pSortContainer = &container;
container.m_nSortVariantID = lParam;
container.m_bSortAscend = m_bSortAscend;
m_Grid.SortItems( ItemCompareFunc, 0, TRUE );
container.UnLock();
}
m_Grid.Invalidate( );
}
}
}
return CFormView::PreTranslateMessage(pMsg);
}
void CSListView::DoDataExchange(CDataExchange* pDX)
{
CFormView::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CSListView)
//}}AFX_DATA_MAP
}
void CSListView::OnInitialUpdate()
{
CFormView::OnInitialUpdate();
// SetColumn
ResetColumns( );
// Create Tab
if( !::IsWindow( m_wndWorkTab.GetSafeHwnd() )
&& m_wndWorkTab.Create(WS_CHILD|WS_VISIBLE, CRect(0,0,0,0), this, IDC_SLISTVIEW_WORKTAB) )
{
CString strName;
strName.LoadString( IDS_SLISTVIEW_CLASS );
m_wndWorkTab.Addtab( &m_Grid, strName, SL_WORKTAB_CLASS);
strName.LoadString( IDS_SLISTVIEW_A );
m_wndWorkTab.Addtab( &m_Grid, strName, SL_WORKTAB_A);
//strName.LoadString( IDS_SLISTVIEW_MSMALL );
strName = _T("中小板");
m_wndWorkTab.Addtab( &m_Grid, strName, SL_WORKTAB_MSMALL);
strName.LoadString( IDS_SLISTVIEW_SHB );
m_wndWorkTab.Addtab( &m_Grid, strName, SL_WORKTAB_SHB);
strName.LoadString( IDS_SLISTVIEW_SZNB );
m_wndWorkTab.Addtab( &m_Grid, strName, SL_WORKTAB_SZNB);
strName.LoadString( IDS_SLISTVIEW_BOND );
m_wndWorkTab.Addtab( &m_Grid, strName, SL_WORKTAB_BOND);
strName.LoadString( IDS_SLISTVIEW_FUND );
m_wndWorkTab.Addtab( &m_Grid, strName, SL_WORKTAB_FUND);
//strName.LoadString( IDS_SLISTVIEW_RIGHT );
strName = _T("权证");
m_wndWorkTab.Addtab( &m_Grid, strName, SL_WORKTAB_RIGHT);
strName.LoadString( IDS_SLISTVIEW_SELF );
m_wndWorkTab.Addtab( &m_Grid, strName, SL_WORKTAB_SELF);
strName.LoadString( IDS_SLISTVIEW_GROUP );
m_wndWorkTab.Addtab( &m_Grid, strName, SL_WORKTAB_GROUP);
strName.LoadString( IDS_SLISTVIEW_DOMAIN );
m_wndWorkTab.Addtab( &m_Grid, strName, SL_WORKTAB_DOMAIN);
m_wndWorkTab.SetSelectTabColor( AfxGetProfile().GetColor(CColorClass::clrSListBK),
AfxGetProfile().GetColor(CColorClass::clrTitle) );
m_wndWorkTab.SetActualTitle(FALSE);
m_wndWorkTab.SetCurtab( SL_WORKTAB_SELF );
CFont font;
font.CreateStockObject (DEFAULT_GUI_FONT);
m_wndWorkTab.SetFont( &font );
// m_Grid No HScrollBar
m_Grid.SetOuterHScrollBar( TRUE, m_wndWorkTab.GetSafeHwnd() );
}
}
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( 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 );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -