策略为王源代码分析-基本资料和行情选股

Published

1.基本资料和行情选股的菜单点击事件

1.1 基本资料和行情选股的菜单ID

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

 BEGIN
        MENUITEM "交易(&T)...\tF12",              ID_TOOL_TRADER
        MENUITEM SEPARATOR
        MENUITEM "计算器(&C)...",                  ID_TOOL_CALCULATOR
        MENUITEM "记事本(&N)...",                  ID_TOOL_NOTE
        MENUITEM SEPARATOR
        MENUITEM "基本资料和行情选股(&F)...",            ID_TOOL_FILTERINFO
        MENUITEM "预警系统(&A)...",                 ID_TOOL_ALARM
    END

ID_TOOL_FILTERINFO在

G:\stock\TskingVS2019\src\Client\StkUI\resource.h中定义。

#define ID_TOOL_FILTERINFO              34513

1.2.基本资料和行情选股id 对应的函数

G:\stock\TskingVS2019\src\Client\StkUI\MainFrm.cpp

ON_COMMAND(ID_TOOL_FILTERINFO, OnToolFilterinfo)

1.3.基本资料和行情选股id被点击后打开对话框

void CMainFrame::OnToolFilterinfo()
{
	CFilterInfoDlg	dlg;
	dlg.DoModal();
}

 

2.基本资料和行情选股对话框分析

G:\stock\TskingVS2019\src\Client\StkUI\Dialog\FilterInfoDlg.cpp

2.1 基本资料和行情选股对话框点击“开始”按钮

//基本资料和行情选股对话框点击“开始”按钮
void CFilterInfoDlg::OnStart() 
{
	UpdateData( ); ////step 1.基本资料和行情选股对话框,首先更新数据

	if( m_listCond.GetCount() <= 0 )
	{
		AfxMessageBox( IDS_FILTERINFO_NOCOND, MB_OK|MB_ICONINFORMATION );
		return;
	}

	BOOL	bAnd	=	TRUE;
	CButton * pbtn	=	(CButton *)GetDlgItem(IDC_RADIOAND);
	if( pbtn )	bAnd	=	pbtn->GetCheck();

	m_listResult.ResetContent();

	CStockContainer & container	=	AfxGetStockContainer();
	m_ctrlProgress.SetWindowPos( NULL, 0, 0, 0, 0, SWP_SHOWWINDOW|SWP_NOSIZE|SWP_NOMOVE );
	m_ctrlProgress.SetRange( 0, container.GetSize() );//基本资料和行情选股对话框,进度条最大数设置为股票个数
	for( int i=0; i<container.GetSize(); i++ )
	{
		m_ctrlProgress.SetPos( i ); //进度条设置为当前股票序号

		CStockInfo	&	info	=	container.ElementAt(i); 
		LONG	stocktype	=	info.GetType(); //判断选股范围
		if( CStock::typeshA == stocktype )
		{	if( !m_btnAll.GetCheck() && !m_btnShaa.GetCheck() )	continue;	}
		else if( CStock::typeshB == stocktype )
		{	if( !m_btnAll.GetCheck() && !m_btnShab.GetCheck() )	continue;	}
		else if( CStock::typeszA == stocktype )
		{	if( !m_btnAll.GetCheck() && !m_btnSzna.GetCheck() )	continue;	}
		else if( CStock::typeszB == stocktype )
		{	if( !m_btnAll.GetCheck() && !m_btnSznb.GetCheck() )	continue;	}
		else
		{	continue;	}

		BOOL	bSelected	=	bAnd;
		for( int k=0; k<m_listCond.GetCount(); k++ )  //选股条件
		{
			FILTERINFO_CONDITION * pCond = (FILTERINFO_CONDITION *)m_listCond.GetItemData(k);
			double	dValue	=	0;
			BOOL	bOK		=	FALSE;
			if( pCond && AfxGetVariantValue( pCond->nVariantID, info, &dValue, &container ) ) //对第i只股票进行计算
			{
				bOK	=	TRUE;
				if( pCond->bHasMoreThan && dValue < pCond->dMoreThan )
					bOK	=	FALSE;
				if( pCond->bHasLessThan && dValue > pCond->dLessThan )
					bOK	=	FALSE;
			}

			if( bAnd && !bOK )
			{
				bSelected	=	FALSE;
				break;
			}
			if( !bAnd && bOK )
			{
				bSelected	=	TRUE; //符合选股条件
				break;
			}
		}

		//符合条件
		if( bSelected )
		{
			//加入结果列表,CListBox	m_listResult,因为是对话框,改变m_listResult的值即更新界面
			int nItem = m_listResult.AddString( CString(info.GetStockCode()) + "(" + info.GetStockName() + ")" );
			m_listResult.SetItemData( nItem, i ); 
		}
	}
	m_ctrlProgress.SetPos( container.GetSize() );
	
	m_btnAddToGroup.EnableWindow( TRUE );
}