策略为王源代码分析-分组统计

Published

 

 

1.分组统计菜单定义

G:\stock\TskingVS2019\src\Client\StkUI\StkUI.rc

 MENUITEM "分组统计信息(&S)",                  ID_SLIST_GROUP
        MENUITEM "板块统计信息(&A)",                  ID_SLIST_DOMAIN
        MENUITEM SEPARATOR
        POPUP "分组列表(&G)"
        BEGIN
            MENUITEM "分组统计信息(&S)",                  ID_SLIST_GROUP
            MENUITEM "分组设定(&E)...",                 ID_OPTION_SETGROUP
            MENUITEM "分组1",                         ID_SLIST_GROUP1
        END
        POPUP "板块列表(&D)"
        BEGIN
            MENUITEM "板块统计信息(&A)",                  ID_SLIST_DOMAIN
            MENUITEM SEPARATOR
            MENUITEM "板块1",                         ID_SLIST_DOMAIN1

分组统计菜单消息定义

 

ON_COMMAND(ID_SLIST_GROUP, OnSlistGroup)
	ON_COMMAND(ID_SLIST_GROUPSELF, OnSlistGroupself)
	ON_COMMAND(ID_SLIST_DOMAIN, OnSlistDomain)

3.分组统计响应函数

void CMainFrame::OnSlistGroup() { AfxShowSlist(CStockContainer::typeGroup); } 

 

/股票类列表 股票数据选择 by freeman
_AFXCORE_INLINE void AfxShowSlist( int nType, LPCTSTR lpszDomain, DWORD dwDate )
{
	CSListView	* pSListView = AfxGetSListView( );
	if( pSListView )
	{
		pSListView->SetCurrentStatus( nType, lpszDomain, dwDate );
		AfxSwitchToStaticView( RUNTIME_CLASS(CSListView) );
	}
	else
	{
		AfxSwitchToStaticView( RUNTIME_CLASS(CSListView) );
		pSListView = AfxGetSListView( );
		if( pSListView )
			pSListView->SetCurrentStatus( nType, lpszDomain, dwDate );
	}
}

 

 

step 1:读取财务数据时,填入板块数据

G:\stock\TskingVS2019\src\Client\StkUI\View\SListView.cpp

void CSListView::SetCurrentStatus(int nType, LPCTSTR lpszDomain, DWORD dwDate)
{
	AfxGetSListStockContainer().RetrieveFromStatic(nType, lpszDomain, AfxGetActiveStrategy(), dwDate);
	OnUpdate(NULL, UPDATE_HINT_SLISTVIEW, NULL);

	/*CMainFrame	* pFrame = AfxGetMainFrame();
	if (pFrame)
		pFrame->m_DateBox.SetCurrentWindowText();*/
}

 

 

G:\stock\TskingVS2019\src\Client\StkLib\Src\Container.cpp

//股票列表底部菜单分类、策略选股 by freeman
BOOL CStockContainer::RetrieveFromStatic( int nType, LPCTSTR lpszDomain, CStrategy * pStrategy, DWORD dwDate )
{
	CSPMutex::Scoped	l(m_mutex);

	Clear( );

	if( nType == typeNone )
	{
		m_nType	=	typeNone;
		return TRUE;
	}

	if( nType < typeMin || nType > typeMax )
		return FALSE;
	m_nType		=	nType;

	m_dwDate	=	dwDate;
	
	CSPStringArray	astrSpecify;

	switch( nType )
	{
....
case typeGroup:
		{
			if( lpszDomain && strlen(lpszDomain) > 0 )
			{
				AfxGetGroupContainer().GetDomainStocks( lpszDomain, astrSpecify );
				RetrieveSpecify( astrSpecify );
				m_strDomain	=	lpszDomain;
			}
			else
				return AfxGetGroupContainer().GetAllDomainInfo( this, m_dwDate );
		}
		break;
	case typeDomain:
		{
			if( lpszDomain && strlen(lpszDomain) > 0 )
			{
				AfxGetDomainContainer().GetDomainStocks( lpszDomain, astrSpecify );
				RetrieveSpecify( astrSpecify );
				m_strDomain	=	lpszDomain;
			}
			else
				return AfxGetDomainContainer().GetAllDomainInfo( this, m_dwDate );
		}
		break;
.....
}
//财务数据
BOOL CStockInfo::StatBaseIndex(DWORD dwDate)
{
	SP_ASSERT(0 != dwDate);

	if (m_basedata.GetSize() == 0)
		return FALSE;

	int	nIndex = m_basedata.GetSize() - 1;
	for (int i = m_basedata.GetSize() - 1; i >= 0; i--)
	{
		if (m_basedata.ElementAt(i).m_date <= dwDate)
		{
			nIndex = i;
			break;
		}
	}

	BASEDATA& block = m_basedata.ElementAt(nIndex);

	//策略为王的板块和省份数据是从财务数据中获取并填入的 by freeman
	strncpy(m_szDomain, block.m_szDomain, min(sizeof(m_szDomain), sizeof(block.m_szDomain)));
	strncpy(m_szProvince, block.m_szProvince, min(sizeof(m_szProvince), sizeof(block.m_szProvince)));
	strncpy(m_szProvince, "block.m_szProvince", min(sizeof(m_szProvince), sizeof(block.m_szProvince)));