LRESULT CDownloadDlg::OnStkReceiverData(WPARAM wParam, LPARAM lParam) { PCOMMPACKET pCommPacket = (PCOMMPACKET)lParam; switch( wParam ) { case CStock::dataReport: if( pCommPacket && CStock::dataReport == pCommPacket->m_dwDataType && pCommPacket->m_dwCount > 0 ) { m_nReportCount += pCommPacket->m_dwCount; for( DWORD i=0; i<pCommPacket->m_dwCount; i++ ) { CKData kdata; kdata.SetKType( CKData::ktypeDay ); KDATA kd; if( UpdateKDATAByREPORT( kd, &(pCommPacket->m_pReport[i]) ) ) { kdata.Add( kd ); AfxGetDB().InstallKData( kdata, FALSE ); } } CStockContainer & container = AfxGetStockContainer(); if( m_nReportRequestSent - m_nReportCount < 64 && m_nReportRequestSent < (UINT)container.GetSize() ) { container.Lock(); m_nReportRequestSent += AfxGetStkReceiver().RequestStockData( CStock::dataReport, container.GetData()+m_nReportRequestSent, min(160,container.GetSize()-m_nReportRequestSent), 0, 0 ); container.UnLock(); } if( !m_bReportFinished && m_nReportCount > 0.95 * m_nReportTotal ) { m_bReportFinished = TRUE; ::SendMessage( GetSafeHwnd(), WM_USER_DOWNLOAD_PROGRESS, STKLIB_MAX_PROGRESS, NULL ); AfxBeginThread( DownloadMain, (LPVOID)m_pDownloadInfo,THREAD_PRIORITY_NORMAL); } else if( !m_bReportFinished && m_nReportTotal > 0 ) { DWORD dwProgress = STKLIB_MAX_PROGRESS * m_nReportCount / m_nReportTotal; ::SendMessage( GetSafeHwnd(), WM_USER_DOWNLOAD_PROGRESS, dwProgress, NULL ); } } break; } return 0L; }
// update CStockInfo by Report data BOOL UpdateStockInfoByREPORT( CStockInfo & info, REPORT * pReport ) { SP_ASSERT( pReport ); if( !pReport ) return FALSE; // 股票市场 if( strlen(pReport->m_szCode) > 0 ) info.SetStockCode( pReport->m_dwMarket, pReport->m_szCode ); if( strlen(pReport->m_szName) > 0 ) info.SetStockName( pReport->m_szName ); if( info.GetType() == 0 ) { if( CStock::marketSHSE == pReport->m_dwMarket ) info.SetType( CStock::typeshA ); else if( CStock::marketSZSE == pReport->m_dwMarket ) info.SetType( CStock::typeszA ); else info.SetType( CStock::typeshA ); } // 成交买卖价量信息 if( pReport->m_fLast > 1e-4 ) info.m_fLast = pReport->m_fLast; info.m_fOpen = pReport->m_fOpen; info.m_fHigh = pReport->m_fHigh; info.m_fLow = pReport->m_fLow; info.m_fClose = pReport->m_fNew; info.m_fVolume = pReport->m_fVolume; info.m_fAmount = pReport->m_fAmount; info.m_fBuyPrice[0] = pReport->m_fBuyPrice[0]; info.m_fBuyPrice[1] = pReport->m_fBuyPrice[1]; info.m_fBuyPrice[2] = pReport->m_fBuyPrice[2]; info.m_fBuyPrice[3] = pReport->m_fBuyPrice[3]; info.m_fBuyPrice[4] = pReport->m_fBuyPrice[4]; info.m_fBuyVolume[0] = pReport->m_fBuyVolume[0]; info.m_fBuyVolume[1] = pReport->m_fBuyVolume[1]; info.m_fBuyVolume[2] = pReport->m_fBuyVolume[2]; info.m_fBuyVolume[3] = pReport->m_fBuyVolume[3]; info.m_fBuyVolume[4] = pReport->m_fBuyVolume[4]; info.m_fSellPrice[0] = pReport->m_fSellPrice[0]; info.m_fSellPrice[1] = pReport->m_fSellPrice[1]; info.m_fSellPrice[2] = pReport->m_fSellPrice[2]; info.m_fSellPrice[3] = pReport->m_fSellPrice[3]; info.m_fSellPrice[4] = pReport->m_fSellPrice[4]; info.m_fSellVolume[0] = pReport->m_fSellVolume[0]; info.m_fSellVolume[1] = pReport->m_fSellVolume[1]; info.m_fSellVolume[2] = pReport->m_fSellVolume[2]; info.m_fSellVolume[3] = pReport->m_fSellVolume[3]; info.m_fSellVolume[4] = pReport->m_fSellVolume[4]; // K线数据、日期 KDATA kd; UpdateKDATAByREPORT( kd, pReport ); int nLen = info.m_kdata.GetSize(); if( nLen > 0 && info.m_kdata.ElementAt(nLen-1).m_date == kd.m_date ) info.m_kdata.SetAt( nLen-1, kd ); else info.m_kdata.Add( kd ); info.m_datetech = kd.m_date; // 保存 memcpy( &(info.m_reportLatest), pReport, sizeof(info.m_reportLatest) ); return TRUE; }